Unity 3.0 glstate.light replacement?

Hey guys,

First off, I was wondering if there was any way to add parameters and assign properties to a built-in shader yet. If not, then why isn’t this being supported?

Second - I was wondering if there was a supported replacement for the removal of glstate.light. I need to get the position of a light without passing it in a parameter (for the reason above).

Any help is greatly appreciated

  • Chris

What do you mean by that?

It’s not removed, but not supported by some platforms (namely, xbox360, ps3, GLSL). In next build there will be a helper macro UNITY_HAS_LIGHT_PARAMETERS to help with that.

As always, you can download the built-in shader source, and make any modifications you want. If you don’t change its name, the modified shader will override the built-in one.

Thanks for the responses -

I’m overriding the terrain shader and wanting to add properties to it that I can control from script.

With most shaders it’s:

material.setfloat(…)

As far as I can tell, there is no script access to the terrain’s material, so I was wondering if there was a hack-around way to edit properties inside of the shader.

if you write an own terrain then yes
but otherwise no as the terrain has no material actually so also no access to any kind of values through the Material class

So will this be beta 8? And what will it’s usage be to get a directional light’s direction? I don’t mean to sound impatient - I’ve just exhausted all other possibilities. Thanks Aras!

beta 7, should be out now.

Same as in Unity 2.6; if you write a simple vertex shader, put “Lighting On” somewhere in the pass; then brightest 4 lights will have their data in glstate.light*. This will not work on 360, PS3 or OpenGL ES 2.0, so you wrap that code inside an #if UNITY_HAS_LIGHT_PARAMETERS.*
In beta 7 there’s also a function in UnityCG.cginc, float3 ShadeVertexLights (float4 vertex, float3 normal) that computes per-vertex diffuse lighting from those 4 brightest lights.