Applying glstate built-in variables

Hi,

I want to write a vertex lighting shader by my own, but I have the problem, that the glstate built-ins doesn’t work for me. Do I make the mistake or is it another issue? There is one directional light in the scene which is forced as vertex light.

My test vertex shader that doesn’t react to modifications to light color:

Shader “Test” {
Properties {
_Color (“Main Color”, Color) = (1,1,1,1)
}

Category {
Blend AppSrcAdd AppDstAdd

// ------------------------------------------------------------------
// ARB fragment program

SubShader {
// Pixel lights
Pass {
Name “PPL”
Tags { “LightMode” = “Vertex” }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_builtin
#include “UnityCG.cginc”
#include “AutoLight.cginc”

struct v2f {
V2F_POS_FOG;
LIGHTING_COORDS
};

v2f vert (appdata_base v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );

TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}

uniform sampler2D _MainTex;

float4 frag (v2f i) : COLOR
{
return glstate.light[0].diffuse;
}
ENDCG
}
}
}
}

The lighting states can only be used in the vertex shader (I think…). You are using it in a pixel shader.

Perhaps a bit late, but that is exactly what is done in the Unite 2008 presentation on Shaders.

Download the .mov, and skip to about 1:50, where he starts calculating lighting per pixel. He uses the glstate variables in the fragment function, and it works fine…

How on earth is that possible? :stuck_out_tongue:

I just posted the exact same issue. Are you using Unity on the PC or MAC? The presentation is on a MAC.
Only thing making sense to me at this point.

Neither of your shaders work on my iMac’s ATI HD 2600. Objects with either shader do not render at all.

above shader is kind of bogus, isn’t it?

“Per Pixel Light” and then right away enforcing vertex light mode.
Shouldn’t that be pixel?

The name tag doesn’t change how the shader renders. It’s just for referencing passes with UsePass, etc.

Ok, I messed up: I was viewing them with mipmap view turned on. They both appear to work when used with the right kind of lights.