Very weird shader issue with world position (simple to reproduce)

I need to get worldPosition inside my shader, to compare with other custom inputs. The world position seems good, but in fact it’s weird !! I explain :
1216959--49829--$wordPos.png

This is a quad, size 1x1, I apply a simple shader on it :
o.Albedo = IN.worldPos.x;

My problem : I expected to have a more linear gradient. Like that (done in photoshop)
1216959--49832--$wordPos_correct.png

I precise that I have no light, just an ambiant to (1.0, 1.0, 1.0)
Am I crazy?

Try this:
o.Albedo = 0;
o.Emission = IN.worldPos.x;

Thank you for your answer,
but it leads to the same weird result.

This is my very simple debug shader:

 Shader "Iso/Debug" {
    Properties {
    }
       
    SubShader {
      Tags { "RenderType" = "Opaque" }

      Cull Off
      CGPROGRAM
      #pragma surface surf Lambert

      struct Input {
          float3 worldPos;
      };

      void surf (Input IN, inout SurfaceOutput o) {
		  o.Albedo = 0;
		  o.Emission = IN.worldPos.x;
      }
      ENDCG
    } 
    Fallback "Diffuse"
  }

Are you rendering in linear or gamma space?

Did you try creating a new lighting function that simply returns albedo, then disable vertex lights, ambient, forward add, etc… ?

Awesome ! I needed to set a gamma lighting (not linear lighting) to see what i expected to see. Thank’s a lot !

Sorry for the potential thread hijack, but does this mean that the value of worldPos.x is truly handled differently in linear space in comparison to gamma? does anyone happen to have encountered this issue before?

Just wanted to try and understand the cause of this, it could perhaps have it’s practical uses, but the behaviour just seems odd to me :slight_smile:

From the shader’s perspective, no it isn’t. It will looks like it’s affected, but that’s because you’re viewing the results which are altered after computation by the gamma correction or lack thereof.

For example, if you used worldposition x and y for UV coordinates, you wouldn’t get texture stretching and relaxing when switching between linear and gamma, despite the perceived differences in value when viewing the raw worldposition values in Unity.