I have a surface shader that adds a bit of positional noise, using the following code:

float2 uv_main = IN.uv_MainTex + 
        tex2D(_PosNoise, IN.uv_MainTex).r - 0.5,
        tex2D(_PosNoise, IN.uv_MainTex).r - 0.5
    ) / float2(_Width, _Height) * _MovementOffset;
o.Albedo = tex2D(_MainTex, uv_main);

_MovementOffset is a float, the _Width and _Height are the size of the map in world coordinates. _PosNoise is a texture that is the same for both versions.

The problem I'm seeing is that the effective noise changes between how the image looks in the Unity Editor vs when it is compiled. The effect is such that I need to multiply the MovementOffset by a factor of 2-3 to have the same effect in the compiled version.


Unity Editor


Compiled Version

I don't understand what could be causing this, and am having some real difficulties figuring it out. Any suggestions on where to look? Thanks!

  • \$\begingroup\$ maybe float2(_Width, _Height) is causing scaling difference when your window size is bigger? \$\endgroup\$ – Jimmy Jul 25 '17 at 20:46
  • \$\begingroup\$ They are world coordinates, and don't change on window size. Also, I have verified that varying the editor game window size doesn't affect the result. \$\endgroup\$ – PearsonArtPhoto Jul 25 '17 at 21:23
  • \$\begingroup\$ What kind of format and compression are you using on your noise texture? \$\endgroup\$ – DMGregory Jul 25 '17 at 21:27
  • \$\begingroup\$ The noise feature is generated at run time. \$\endgroup\$ – PearsonArtPhoto Jul 25 '17 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.