Page 1 of 1

Water Shader Refraction Part

PostPosted: Sun Nov 12, 2017 4:18 pm
by Desoxi
Hello there,
just bought the plugin for unity and im trying a few things around.
At the moment im recreating the water shader from the samples and one part is a bit weird though.
Working refraction: https://imgur.com/a/U5Zx8
Not working refraction: https://imgur.com/a/vyeAh

The first one uses the component mask node but doesnt mask it at all (seen by the xyzw text). This nodesystem works well and i think the refraction looks good.
But as you can see in the second screenshot, which uses the component mask to use only xy, the refraction is not correct anymore. The sample nodesystem uses the same mask (xy) and when you start the sample scene everything is ok.
As soon as you switch the mask node to xyzw and back to xy again the sample scene as well does not work as intended anymore.

The only difference i could find in the generated code is the following:

Mask (xyzw, which is working as intended):
Code: Select all
float4 screenColor17 = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD( ( (ase_screenPos26).xyzw + float4( ( _Distortion * temp_output_15_0 ) , 0.0 ) ) ) );


Mask (xy, looks wrong):
Code: Select all
float4 screenColor17 = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD( float4( ( float3( (ase_screenPos26).xy ,  0.0 ) + ( _Distortion * temp_output_15_0 ) ) , 0.0 ) ) );


Dont know whether or not this is a bug, but if its not, i would appreciate it if you could explain it to me so i can understand how this works.

Re: Water Shader Refraction Part

PostPosted: Sun Nov 12, 2017 4:24 pm
by Desoxi
Alright i guess i just figured out why this doesnt seem to work.
The UNITY_PROJ_COORD function needs a 4 component vector. And i think the W component is important in here because of perspective division. And if we use a "XY" component mask this W component is most likely to become 0 which would screw things up in perspective division.
Am i right?

Re: Water Shader Refraction Part

PostPosted: Mon Nov 13, 2017 10:20 am
by Amplify_Borba
Hello,

Thank you for reporting this issue and for the detailed explanation, we'll be running some tests on our side and get back to you as soon as possible!

Re: Water Shader Refraction Part

PostPosted: Thu Nov 16, 2017 2:50 pm
by Ricardo Teixeira
Desoxi wrote:Alright i guess i just figured out why this doesnt seem to work.
The UNITY_PROJ_COORD function needs a 4 component vector. And i think the W component is important in here because of perspective division. And if we use a "XY" component mask this W component is most likely to become 0 which would screw things up in perspective division.
Am i right?


Greetings,

This is not an issue with the component mask node, so to speak, Grab screen color node UV inputs changes whether the input is a vector2 or a vector4 and does some different calculations. Changing the connected nodes changes the connection from vector3 to vector4 changing the input to a vector4 but then changing it back to vector3 again does not trigger the change because it's not a vector2. (backwards compatibility purposes)

We're going to leave this issue pending because this behavior might not be relevant anymore or maybe we can think of a better solution while maintaining backwards compatibility.

Apologies for the inconvenience.