I am learning how to build shaders. I have nice reflections from the cube map and wanted to add color and texture maps to blend with the reflections. The slots are there and I have hammered away trying various code insertions from various wikis, blogs and examples from this forum but am having a time getting my head around the calls you can make and the syntax. What i have tried so far gave me hot pink…ouch…or did nothing at all. Here is what I have so far that did not throw errors or hot pink. Texture slot accepts textures unlike other shaders I tried and can change the diffuse to enhance the texture…which is a goal of this shader. Also…is this as optimized as it could be for mobile. I really want to get this under my thumb and understand it if anybody could be of help. How do i combine the outputs?
Shader "GLSLMobileDiffuseReflections" {
Properties {
_Cube("Reflection Map", Cube) = "" {}
_Color ("Diffuse Material Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" { }
}
SubShader {
Pass {
GLSLPROGRAM
// User-specified uniforms
uniform vec4 _Color; // shader property specified by users
uniform samplerCube _Cube;
// The following built-in uniforms
// are also defined in "UnityCG.glslinc",
// i.e. one could #include "UnityCG.glslinc"
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;
#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));
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#endif
#ifdef FRAGMENT
void main()
{
vec3 reflectedDirection =
reflect(viewDirection, normalize(normalDirection));
gl_FragColor = textureCube(_Cube, reflectedDirection);
}
#endif
ENDGLSL
}
}
}