Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is ShaderChunks.lights_pars? #7833

Closed
unphased opened this issue Dec 21, 2015 · 2 comments
Closed

What is ShaderChunks.lights_pars? #7833

unphased opened this issue Dec 21, 2015 · 2 comments

Comments

@unphased
Copy link
Contributor

I am on development branch from about a week ago (I need an r74 build for the #3532 fix) and I am not able to figure out how to quickly insert simple lambertian matte shading into the custom shader I am writing.

Basically I need to write a shader to render (in one pass) a single directional sun light with a shadowmap and a fixed number of non-shadowed pointlights that are affixed to the mesh.

What I've got so far which fails to compile now that I've attempted to add ShaderChunks for lights is:

var vert =                                                                
    THREE.ShaderChunk.shadowmap_pars_vertex +                             
    THREE.ShaderChunk.lights_pars +                                       
    "\n" +                                                                
    "varying vec3 meshColor\n" +                                          
    "void main() {\n" +                                                   
        "vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n" +   
        "gl_Position = projectionMatrix * viewMatrix * worldPosition;\n" +
        // make directional lambertian lighting without specular          
        // "vec3 lightDir = normalize(lightPos);\n" +                     
        // "float lambert = max(dot(lightDir, normal), 0.0);\n" +         
        THREE.ShaderChunk.lights_lambert_vertex +                         
        THREE.ShaderChunk.shadowmap_vertex +                              
    "\n}\n";                                                              
var frag =                                                                
    THREE.ShaderChunk.shadowmap_pars_fragment +                           
    "\n" +                                                                
    "varying vec3 meshColor\n" +                                          
    "void main() {\n" +                                                   
        THREE.ShaderChunk.shadowmap_fragment +                            
        "\ngl_FragColor = vec4(min(meshColor, shadowMask), 1.0);\n" +     
    "\n}\n";                                                              

material = new THREE.ShaderMaterial({                                     
    uniforms: THREE.UniformsUtils.merge([                                 
        THREE.UniformsLib.common,                                         
        THREE.UniformsLib.lights,                                         
        THREE.UniformsLib.fog,                                            
        THREE.UniformsLib.shadowmap                                       
    ]),                                                                   
    vertexShader: vert,                                                   
    fragmentShader: frag                                                  
});                                                                       

I get some ungooglable problems including a syntax error at IncidentLight -- this doesnt even appear anywhere in the code when I search..

I guess what i'm going to do now is just hand-roll the per-vertex lambert that I need and get on with my custom pointlights. But it would be so fantastic if someone could shed a little (directional?) light on what happened to ShaderChunk.lights_lambert_pars_vertex.

@unphased
Copy link
Contributor Author

OK looks like i need common for IncidentLight and maybe I will be able to figure this out. I was trying to find how the default shaders were made, got nowhere from grepping, and then i stumbled upon ShaderLib.js and it holds ALL the secrets.

@unphased
Copy link
Contributor Author

Why is lights_pars not used in the lambert frag shader?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants