mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 21:49:55 +00:00
fixed refraction and underwater distortion artifacts
This commit is contained in:
parent
113bbfa253
commit
8caa5ff9c4
2 changed files with 16 additions and 4 deletions
|
@ -50,7 +50,7 @@ float4 main_fp (float2 iTexCoord : TEXCOORD0,
|
||||||
{
|
{
|
||||||
float4 normal = tex2D(NormalMap, noiseCoord) * 2 - 1;
|
float4 normal = tex2D(NormalMap, noiseCoord) * 2 - 1;
|
||||||
|
|
||||||
float depth = tex2D(DepthMap, iTexCoord).r * far;
|
float depth = tex2D(DepthMap, iTexCoord + normal.xy * 0.015).r * far;
|
||||||
depth = saturate(depth / 2000.f);
|
depth = saturate(depth / 2000.f);
|
||||||
|
|
||||||
float4 color = tex2D(RT, iTexCoord + normal.xy * 0.015) +
|
float4 color = tex2D(RT, iTexCoord + normal.xy * 0.015) +
|
||||||
|
|
|
@ -62,7 +62,6 @@ void main_fp
|
||||||
float depthTex = tex2D(depthMap, screenCoords).r;
|
float depthTex = tex2D(depthMap, screenCoords).r;
|
||||||
float depth1 = depthTex * far - iDepth;
|
float depth1 = depthTex * far - iDepth;
|
||||||
depth1 = saturate(depth1 / 500.f);
|
depth1 = saturate(depth1 / 500.f);
|
||||||
depth1 = (depthTex == 0 ? 1 : depth1);
|
|
||||||
|
|
||||||
// Simple wave effect. to be replaced by something better
|
// Simple wave effect. to be replaced by something better
|
||||||
float2 uv1 = iUv + time * float2(0.5, 0);
|
float2 uv1 = iUv + time * float2(0.5, 0);
|
||||||
|
@ -74,7 +73,20 @@ void main_fp
|
||||||
normal = 2*normal - 1;
|
normal = 2*normal - 1;
|
||||||
|
|
||||||
float2 screenCoords_reflect = screenCoords + normal.yx * 0.05;
|
float2 screenCoords_reflect = screenCoords + normal.yx * 0.05;
|
||||||
float2 screenCoords_refract = screenCoords + normal.yx * 0.1 * depth1;
|
float2 screenCoords_refract = screenCoords + normal.yx * 0.05 * depth1;
|
||||||
|
|
||||||
|
// Sample depth again with the refracted coordinates
|
||||||
|
depthTex = tex2D(depthMap, screenCoords_refract).r;
|
||||||
|
float depth2 = (depthTex * far - iDepth) / 500.f;
|
||||||
|
depth2 = (depthTex == 0 ? 1 : depth2);
|
||||||
|
// if depth2 is less than 0, this means we would refract something which is above water,
|
||||||
|
// which we don't want to - so in that case, don't refract
|
||||||
|
if (depth2 < 0.25) // delta due to inaccuracies
|
||||||
|
{
|
||||||
|
screenCoords_refract = screenCoords;
|
||||||
|
depth2 = depth1;
|
||||||
|
}
|
||||||
|
depth2 = saturate(depth2);
|
||||||
|
|
||||||
float4 reflection = tex2D(reflectionMap, screenCoords_reflect);
|
float4 reflection = tex2D(reflectionMap, screenCoords_reflect);
|
||||||
float4 refraction = tex2D(refractionMap, screenCoords_refract);
|
float4 refraction = tex2D(refractionMap, screenCoords_refract);
|
||||||
|
@ -93,7 +105,7 @@ void main_fp
|
||||||
float3 halfVector = normalize(iEyeVector + lightDir);
|
float3 halfVector = normalize(iEyeVector + lightDir);
|
||||||
float specular = pow(max(dot(normal.xyz, halfVector.xyz), 0), 64);
|
float specular = pow(max(dot(normal.xyz, halfVector.xyz), 0), 64);
|
||||||
|
|
||||||
float opacity = depth1 * saturate(reflectionFactor + specular);
|
float opacity = depth2 * saturate(reflectionFactor + specular);
|
||||||
opacity *= (1-isUnderwater);
|
opacity *= (1-isUnderwater);
|
||||||
|
|
||||||
reflection.xyz += lightSpecularColour0.xyz * specular;
|
reflection.xyz += lightSpecularColour0.xyz * specular;
|
||||||
|
|
Loading…
Reference in a new issue