Hello, I’m creating a custom material to render to an MRT in which there is two textures and I’m creating a material that renders to the first (the main one, the other is for effects on post process).
the thing is I wanna put some lights and shadows on my custom shader as explained here:
And it breaks:
Of course my assumption is that I used 300es and obviously the imports are 100es style or something but the 300es is the only way I’ve found of targetting the first texture in the MRT, I’m not even sure it would be supported in 100es.
Is there a way to fix that?
Note: I passed the colors as uniforms through setVertex3 but it crashes so I hardcoded them in the shader.
It works well on my app but not on the PG, weird.
The ShaderMaterial is not really meant to be used with lights, see
It is in the context of trying to use the code generated by “Generate code” in the NME, but the explanations regarding the ShaderMaterial not supporting lights is what matters.
You should try to use a node material instead, if you want to support the standard lights from Babylon.
Another possibility is to use a CustomMaterial, which is a wrapper around StandardMaterial and lets you inject some custom code at some specific parts of the shader (you also have PBRCustomMaterial as a wrapper for PBRMaterial).
Ok, I’ll investigate that path hover looking on some examples in the PG it uses old glsl style and I’m not sure I can bring my
layout(location=0) out vec4 mainColor;
layout(location=1) out vec4 zoneColor;
in it. (as far as I understand it, maybe I’m wrong)
In other hand the only use of standard features for lighting would be just having the vector of the light direction to compare with the normal of the face (or its interpolation in case of smooth shading) and knowing if I’m in the shadow or not.
I’m not into multiple sources of lights or colored shadows.
I don’t know it simplifies the problem enough or if it remains a hassle.
https://playground.babylonjs.com/#04JDPF#98
taking a look at this one, I have to provide at least the position of the light as it changes when it does, I’ll try to implement that.
Meanwhile I have to find the equivalent for shadows and that part might be tough.
If you have good advices on those path or think I’m in for a good dead end you’re welcome and of course thanks for the help!
Still, trying it on my project I have:
404 http://localhost:9000/src/Shaders/ShadersInclude/lightVxUboDeclaration.fx
Which I usually have when my shader is not declared in the Effects so I checked in the node_modules to know what to import and there is lightUbo… but nothing about lightVxUboDeclaration and since I treeshake my project I’m not sure what to import to make it work
At low resolution poisson helps but i’d rather raise the resolution or better narrow the frustum of the shadow map (still have to test that)
PCF doesn’t work, I suspect it to be v5.
You seem to sell me v5 a lot, since it’s a personal project not in critical prod so I might use it if you tell me it’s stable enough to be used.
I have also to take the angle from the light to the normal of the face to vary a bit the color.