Search Unity

Object Position returns 000 when object is not partially lit.

Discussion in 'Shaders' started by digitalsalmonfx, Sep 14, 2014.

  1. digitalsalmonfx

    digitalsalmonfx

    Joined:
    Oct 9, 2013
    Posts:
    7
    This has been an issue for me for ages now, figured I'd ask someone -

    I create a shader (In shaderforge) which connects appends object position x and y to r and g of the emissive of an unlit shader. The shader compiles to what is shown below.

    When the object is not being partially lit it appears black; When it is fully lit or not lit at all, it is black.

    The only way to get it to react properly is to have it slightly lit. Why on earth is it reacting this way?




    struct VertexInput {
    float4 vertex : POSITION;
    };
    struct VertexOutput {
    float4 pos : SV_POSITION;
    };
    VertexOutput vert (VertexInput v) {
    VertexOutput o;
    float4 objPos = mul ( _Object2World, float4(0,0,0,1) );
    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    return o;
    }
    fixed4 frag(VertexOutput i) : COLOR {
    float4 objPos = mul ( _Object2World, float4(0,0,0,1) );
    ////// Lighting:
    ////// Emissive:
    float4 node_121 = objPos;
    float3 emissive = float3(float2(node_121.r,node_121.g),0.0);
    float3 finalColor = emissive;
    /// Final Color:
    return fixed4(finalColor,1);
    }
     
  2. digitalsalmonfx

    digitalsalmonfx

    Joined:
    Oct 9, 2013
    Posts:
    7
    FYI - The issue was dynamic batching. Turn it off in Player Settings if you're having this issue.