Search Unity

Strange CG Behaviour

Discussion in 'Shaders' started by Major McDoom, Oct 12, 2010.

  1. Major McDoom

    Major McDoom

    Joined:
    Oct 12, 2010
    Posts:
    8
    Hi guys,

    I encountered some really strange errors today from my CG program in my Surface Shader.
    Here's what I mean:

    Works.
    Code (csharp):
    1.  
    2. o.Albedo = tex2D(_WaterBase, i.uv_WaterBase).rgb;
    3. o.Alpha = 1;
    4.  
    Works.
    Code (csharp):
    1.  
    2. o.Albedo = 1;
    3. o.Alpha = i.uv_WaterBase.r;
    4.  
    Does not work.
    Code (csharp):
    1.  
    2. o.Albedo = tex2D(_WaterBase, i.uv_WaterBase).rgb;
    3. o.Alpha = i.uv_WaterBase.r;
    4.  
    The first one uses the texture coords to determine color, and has a constant alpha.
    The second one uses the texture coords to determine alpha, and has a constant color.
    The third one tries to use the texture coords to determine both color AND alpha,
    but it ends up being completely transparent.

    Also, I can't use the isnan function. Even when I call isnan(1.0), it says there is no
    matching overloaded function found!

    This is all very frustrating. Could someone please lend a hand?
     
    Last edited: Oct 14, 2010
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Can you post full shader that has those problems?

    About the isnan - what is the exact error you're getting? And does it go away if you add "#pragma exclude_renderers gles" to the shader? It might be that we did not add support for this function to the GLSL cross-compiler. FYI, not all GPUs support full IEEE floats, so relying on NaNs, denormals other funky things might not work depending on the GPU.
     
  3. Major McDoom

    Major McDoom

    Joined:
    Oct 12, 2010
    Posts:
    8
    Thank you, Aras. It's solved now. Turns out the sample tiling factor was the problem. :)