I'm trying to write a custom shader for THREE.js shadows, but am new to GLSL and having some trouble getting started. I think the best approach is to start with the "identity" functions that produce the same shading as a default ShaderMaterial function and the slowly hack on those. But I can't seem to get it to work. Here's what I've tried:
// vertex function
void main() {
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1 );
}
// fragment function
uniform vec3 shadowColor;
void main() {
gl_FragColor = vec4(shadowColor, 1);
}
The uniforms just provides black as the shadow color:
uniforms: {
shadowColor: {
type: 'c',
value: new THREE.Color(0x000000)
}
},
vertexShader: vshader,
fragmentShader: fshader,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending,
transparent: true
});
This produces nothing in the way of a shadow, though it's firing correctly, I see, because I can change the output of gl_FragColor to an arbitrary HSL value and see the whole view shaded with that color. Clearly I don't understand the correct vertexShader that produces the same output as the default.
Any help with an identity vertexShader and fragmentShader would really aid me in getting my feet wet with GLSL.
Thanks!