There’s something I’m not understanding about shader depth writing.
I have separate ShaderMaterial and corresponding depthShaderMaterial, the latter I then apply using depthRenderer.getDepthMap().setMaterialForRendering(myMesh, myCustomDepthShaderMaterial) which works as I intend, but looking at other built-in materials like for instance the GridMaterial code, I don’t understand how they are writing to the depth map. It seems to happen automagically? It makes me wonder if the approach I’ve taken with separate depth material applied using setMaterialForRendering() is unnecessary and overly complicated.
Can anyone provide some insights into this?
More context - I’m trying to get @roland’s greased line to write depth values, but I’m assuming because the vertex shader changes the vertex positions I definitely will need to use something like the approach outlined above?
Sorry for the delayed follow-up @Evgeni_Popov but I’m having a bit of trouble getting ShadowDepthWrapper to work with a slightly modified version of @roland’s GreasedLine. Here’s my PG and what I’m trying to do is get the greased line to write to the depth map:
Ah OK @Evgeni_Popov , sorry I interpreted your first reply from Dec 22 as being able to use ShadowDepthWrapper to write to the DepthRenderer.DepthMap - I didn’t know there was a difference between depth map for shadows and other purposes?.
I’ve started trying to migrate the custom shader material code to a material plugin, which I will later extend to write depth, but for now I can’t even get the plugin to work. No console errors - the shader compiles fine (no errors), but nothing displays.
The material plugin is instantiated around line 50 and defined at line 100.
The UniformBuffer.updateFloat2 takes two floats as parameters, not a Vector2.
Also, worldViewProjection is automatically bound for you by the ShaderMaterial class as long as you add it to the uniform array that you pass to the constructor, but there is no such facility in a material plugin, so you have to construct the matrix and bind it yourself:
Thanks @Evgeni_Popov, that got me a step closer. I managed to get it going:
However one of my goals in migrating from ShaderMaterial to MaterialPluginBase was that I’d made the assumption that I could then use greased line emissiveColor with GlowLayer but it seems GlowLayer is not yet compatible with material plugins
Got a solution I’m reasonably happy with. Greased line that writes to depth map, works with fog and no code replication between color and depth shaders. Now if only I could get it going with glow layer