-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Extending ShadowMaterial #49
Comments
That is correct. Since For now you can use the The goal with CSM is to support all ThreeJS in-built materials out of the box so I will mark this as a feature request and work on it in the next update. |
Thanks for the reply! I wasn't able to access your codesandbox for some reason but the solution I ended up going with for my use case was to extend MeshLambertMaterial and inject the shadowmask_pars_fragment shaderchunk so I could access the getShadowMask() function. |
Sorry the box was set to private. Should be fixed now. But yes thats essentially the solution:
|
Can I assume this issue is the case with extending MeshDepthMaterial too? Guessing id need to patch the following last line if viable..
I'm trying to patch a shader (juniorsounds depthkit.js) which uses a large geometry and a video texture to set all non relevant pixels as discarded but the depth image, seems to still be the original geometry & in my particular case, this causes a big rectangle to overlay on top of what should be outlines in an outline pass... |
... working in vanilla three , not r3f if thats relevant at all |
Shouts out for the exceptional work thus far though , really glad to find this repo. |
If it works in Vanilla but not in R3F then it must have to do with your setup in react (Memoization and such). If you can post a minimal reproduction I can take a look also remember that some pathways in ThreeJS materials require certain properties to be set on the material instance. So for example in MeshDepthMaterial, the depthPacking property value determines which pathway gets executed |
Beg your pardon, I meant I'm working in vanilla three, not r3f - as in i cant get the depth material to work in vanilla three, Im not using react at all. I'll see if i can create a sandbox in due course but might be tricky as involves video files.. My rough attempt so far is essentially a second CustomShaderMaterial with the same vertex/frag shader as the actual mesh material and a patchmap doing:
Confused about the usage of " // The keyword you will assign to in your custom shader" - im just using * all of the time as Im unclear as to where / how to use the keyword activation |
For further clarity - the material is setup as follows =>
|
I see. As for the comment -
CSM will only inject your patch map if the keyword you specify in place of Most if not all third party patch maps would use I am not too sure what the intended result is here. Perhaps an running example would help. If you are trying to set the depth based on a video texture here is what the patchMap would look like: const crossDkFrag = `
uniform sampler2D tDepthVideoTex;
varying vec2 vUv;
void main() {
vec4 depth = texture2D(tDepthVideoTex, vUv);
vec4 csm_CustomDepth = depth;
}
`;
const depthPatchMap = {
csm_CustomDepth: {
"gl_FragColor = packDepthToRGBA( fragCoordZ );": `
gl_FragColor = csm_CustomDepth;
`,
},
}; And then you would simply set the Note my useage of PS: Thanks for the kindness, I really appreciate it! |
Also, this usecase with MeshDepthMaterial seems to not require CSM. You can simply write a very small ShaderMaterial and assign that to |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
using three r.161 currently |
OK - so like an absolute tool, i had castShadow & receiveShadow set to false before so that my incomplete works didnt interfere with other shadows - seems these have to be true in order for custom depth material to be invoked at all. Starting from scratch now ive confirmed i can actually make it work !! fool .. |
Hi Farazz - firstly apologies for stuffing this thread with my previous insanity. Would you clarifying the usage of the patchmap keys? My current working code looks like this: In my vertex shader, im doing the calculations for the depth values - since this is where its done on the actual shader too. varying float visibility;
Aim therefore is to set patch map to patch 2 entries in the original base depth shader...
Ive also tried visibility in "" like the * is but it doesnt seem to be patched in Is the following valid?
Seems to be , though im still not seeing any appropriate culling |
Just wanted to report back on progress.. I managed to get the depth material to work as a regular material for the model... And the keyword replace works as advertised...
But, when I use it as a custom depth material, it still renders as the original plane geometry.. |
Hello @CosyStudios, I’d love to assist you further, however GitHub issues is to track bugs and not support tickets. Please DM me on Discord @CantBeFaraz and we can pick up there I’m not familiar with your use case so please try to create a working minimal reproduction of the issue on CodeSandbox or feel free to send me some code to work with Lastly, I might not be available all the time so if you’d like to buy my time for more dedicated support feel free to also reach out through Discord or email |
Fair comment Farraz.. I'll continue to crack at it but will follow on discord and attempt a sandbox should i need to reach out, happy to fund some time appropriately should I require a close eye. Best.. |
Hello, I have decided that
|
I'd like to extend the three.js ShadowMaterial so I can apply shadows to my custom shader. When I try to do this my shader code gets ignored and the default ShadowMaterial is rendered (ie. the fragments in shadow render as black, the rest of the mesh is transparent).
Looking at the source code for ShadowMaterial, I can see it explicitly sets the gl_FragColor, whereas the other materials use outgoingLight as their output:
gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
Am I approaching this wrong or is this not possible with the library currently?
The text was updated successfully, but these errors were encountered: