Skip to content
Snippets Groups Projects
Commit 71362e6f authored by Oliphan's avatar Oliphan
Browse files

Fixed distortions to work in screen space

parent d2178fbf
Branches master
Tags V2
No related merge requests found
......@@ -123,9 +123,11 @@
worldNormal.x = dot(i.tspace0, waveNormsCombined);
worldNormal.y = dot(i.tspace1, waveNormsCombined);
worldNormal.z = dot(i.tspace2, waveNormsCombined);
//Calculate screen space normals for distortions
fixed3 screenNormal = mul((float3x3)UNITY_MATRIX_V, waveNormsCombined);
//Sample caustics textures with normal distortion
fixed3 caustic1 = tex2D(_CausticsTex, caustUV1 - normalize(waveNormsCombined + i.distortionNormal)*_RefractionDeform).rgb;
fixed3 caustic2 = tex2D(_CausticsTex, caustUV2 - normalize(waveNormsCombined + i.distortionNormal)*_RefractionDeform).rgb;
fixed3 caustic1 = tex2D(_CausticsTex, caustUV1 - normalize(screenNormal + i.distortionNormal)*_RefractionDeform).rgb;
fixed3 caustic2 = tex2D(_CausticsTex, caustUV2 - normalize(screenNormal + i.distortionNormal)*_RefractionDeform).rgb;
//Combine samples
fixed3 causticrgb = caustic1 * caustic2;
......@@ -136,8 +138,8 @@
half lightingcol = nl * _LightColor0;
//Calculate refraction and reflection UV offsets
float3 refractionOffset = normalize(waveNormsCombined + i.distortionNormal) * _RefractionDeform * abs(_WaveHeight);
float3 reflectionOffset = normalize(waveNormsCombined + i.distortionNormal) * _ReflectionDeform * abs(_WaveHeight);
float3 refractionOffset = normalize(screenNormal + i.distortionNormal) * _RefractionDeform * abs(_WaveHeight);
float3 reflectionOffset = normalize(screenNormal + i.distortionNormal) * _ReflectionDeform * abs(_WaveHeight);
//Calculate screen space UV position
float2 screenUV = i.screenPos.xy / i.screenPos.w;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment