I’m somewhat inexperienced with shaders, and find myself uncertain as to how to achieve something; I had a shot at searching for the answer, but I’m honestly not sure of what terms to use, and didn’t find anything that looked promising in the search that I did perform.
I have a shader that handles both terrain texturing and some slightly-hacky lighting, and now want to split the process into two separate parts so that I can apply the terrain-texturing to only my terrain geometry, while still applying the lighting to everything, terrain included.
Is this feasible–can two fragment shaders be applied to a single piece of geometry, while using only one of them for other objects? If so, how do I go about this? My best guess is to separate the vertex and fragment shaders into separate files, then create two fragment shaders (one for the terrain-texturing and one for the lighting) and assign them via “setShader”–but how does that affect the shader inputs? Do the inputs get passed through from one fragment shader to the next?
To illustrate, this is the sort of thing that I have in mind:
vtx = loader.loadShader(vertexShader.cg)
lighting = loader.loadShader(lightingShader.cg)
terrainTex = loader.loadShader(terrainTextureShader.cg)
terrain = geometry.find("**/terrain")
geometry.setShader(vtx)
geometry.setShader(lighting, 1)
terrain.setShader(terrainTex, 0)
… I suppose that “terrainTextureShader.cg” would be responsible for generating the base colour of a given fragment, with “lightingShader.cg” then taking that and using light-direction, normals, etc. to shade it appropriately…