I'm exploring the idea of creating a ShaderMaterial with lighting similar to that of a MeshLambertMaterial. To achieve this, I have developed a vertex and fragment shader (available here) and included the uniforms from THREE.ShaderLib[ 'lambert' ].uniforms in the ShaderMaterial.
As far as I understand, the next step would involve merging the code from the fragment and vertex shaders used in the MeshLambertMaterial (fragment and vertex shaders) with my custom shader code for adding lighting.
While combining the vertex shader seems relatively simple, I am unsure how to integrate a base color (generated by my custom shader) into the meshlambert_frag.glsl code for lighting calculations. A potential scenario could resemble the following:
// Custom shader code preceding the main function
// Code from meshlambert_frag.glsl preceding the main function
void main {
vec4 myBaseColor ... // Generated by custom fragment shader
// meshlambert_frag.glsl code within the main function will utilize myBaseColor for lighting calculations before setting gl_FragColor
}
Furthermore, is duplicating such a significant portion of code (from meshlambert shaders) deemed bad practice in this context? What alternative approach would you recommend?