Hi Guys,
I need some help adding vertex lighting to this shader. I know I have to use lightDir somehow but I’m having trouble understanding what it is I have to do, anyone have some pointers?
Shader "Reflective/VertexLit Modified" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
_Shininess ("Shininess", Range (0.03, 1)) = 0.7
_MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
}
SubShader {
Pass {
Tags { "LightMode"="Vertex" }
Lighting On
GLSLPROGRAM
uniform samplerCube _Cube;
varying mediump vec2 uv;
uniform vec3 _WorldSpaceCameraPos; // camera position in world space
uniform mat4 _Object2World; // model matrix
uniform mat4 _World2Object; // inverse model matrix
// Varyings
varying vec3 normalDirection;
varying vec3 viewDirection;
varying vec3 lightDir;
varying vec3 normal;
#ifdef VERTEX
void main()
{
mat4 modelMatrix = _Object2World;
mat4 modelMatrixInverse = _World2Object; // unity_Scale.w is unnecessary because we normalize vectors
normalDirection = normalize(vec3(vec4(gl_Normal, 0.0) * modelMatrixInverse));
viewDirection = vec3(modelMatrix * gl_Vertex - vec4(_WorldSpaceCameraPos, 1.0));
uv = gl_MultiTexCoord0.xy ;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#endif
#ifdef FRAGMENT
uniform lowp sampler2D _MainTex;
uniform lowp vec4 _Color;
uniform lowp vec4 _ReflectColor;
uniform lowp float _Shininess;
void main() {
vec3 reflectedDirection = reflect(viewDirection, normalize(normalDirection));
lowp vec4 mainTex = texture2D(_MainTex, uv);
lowp vec4 fragColor = mainTex + (_Color - 1.);
gl_FragColor = (textureCube(_Cube, reflectedDirection) * _Shininess * _ReflectColor) + fragColor ;
}
#endif
ENDGLSL
}
}
}