-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Object3D: Introduce onBeforeShadow(). #14921
Comments
|
Let say you got 20 meshes sharing the same material but needs differents values of uniforms. Using onBeforeRender function is useful to refresh thoses uniforms in it, like changing color value, noise or what ever that is associated to each mesh just before they are rendered ( avoiding the creation of 20 materials for 20 meshs, as you just need to refresh the uniforms ) That works, but not when shadow are rendered. If you got some uniforms that influences mesh position for example, using a same customdepthmaterial shared across all thoses meshes, uniforms won't get refresh per-mesh because onBeforeRender is never called when rendering shadow, and that would be useful !! |
Yeah, that makes sense. Let's see what the others think about this issue. |
That is what cloning the material is for. They still share a single shader.
Right, but each object can clone the custom depth material, correct? -- The other solution, presumably, would be to add support for |
Main problem with the cloning material thing is, it also clones textures and you end up having as much textures as clone. Textures in material * number of clones. For few reasons It would be nice to have more controls over those things. I mean the current system is working, the only thing missing in to get that onBeforeRender function working when shadows are rendered. |
Perhaps you can provide a simple live example to make it clear what you are doing as a workaround, and what you would prefer to be able to do. Is this about |
I can do an example as soon as I got time for sure. |
@Mugen87 , may I describe the case where some kind of |
Can you update your uniforms prior to calling @Samsy wrote:
It has been awhile... Now would be a good time, if you are still interested. |
@WestLangley Scene: several objects consisted of sprites. Each object has its own Algorithm:
The |
I'm okay with adding |
@NataliaDSmirnova I have no opinion on
Do your sprites cast shadows? @Mugen87 Maybe you can explain since you understand it. |
Yes, my sprites cast shadows and receive shadows. |
@NataliaDSmirnova Sprites do not cast shadows. Have you hacked the library itself? You want us to add this feature to the library to support your hack? |
Maybe she is using meshes with |
@WestLangley , @Mugen87 I am sorry for confusing you. I haven't hacked your library, only used its basiс functionality, to built objects, that I need. I haven't used THREE.Sprite. |
@NataliaDSmirnova I assume you doing something like this three.js example which demonstrates instancing with shadows, and shows how to set a custom depth material. Perhaps it would be a good idea if you provide a simple live example so it is clear what you are doing. Sorry, I cannot approve something I do not understand. It's not for a lack of trying... |
@WestLangley As for my case, I need to turn sprites perpendicular to camera direction to get correct spheres image and turn them perpendicular to the light direction to form correct shadowmap for the spheres. The first task is done using |
@NataliaDSmirnova wrote:
I wish you would show your example with instancing. :/ I expect you should be doing billboarding in your vertex shader. That way each instance will face the camera or shadow camera automatically. |
@WestLangley Such objects cast wrong shadows because the uniforms are not set on per-object/per-camera basis (onBeforeRender is not called during the shadow pass). We see this as an accidental omission in API design and thus are reporting it as a problem. Of course, I could prepare a full working example for your convenience but it would take much more time (which I probably lack) than showing the design flaw through a simpler example. Even with such an example, you could possibly suggest workarounds and kludges for this specific example. That's not our point. At last, we could implement our own shadowing technique or even a 3D engine ourselves 😄 Please let me know if it makes sense. |
I give up. I did my best... |
Hello! It's been a while since we discussed the question. The geometry may have thousands of cylinders and spheres and we decided to render every one of them with an "analytical sprite" in addition to instancing to speedup. Analytical sprite also may be called a "procedural sprite" and is a little bit more complex than common sprite. It's a quad, perpendicular to camera view but it doesn't use a texture. Quad is used as a placeholder, positioned with instancing, and the cylinder/sphere image is produced on the fly in a pixel shader. We create our own Material for procedural sprites and have got a perfect result: image quality + performance. We use onBeforeRender function to update uniforms needed for math inside fragment shader. We suggest to add Object3D.onBeforeShadow and call it inside WebGLShadowMap.renderObject. In more detail, there is an example https://jsfiddle.net/NataliaDSmirnova/pqeyft5o/ (If you need I'll create a PR with live example file in threejs/examples directory and changes in library). There are three modes, you can change the used one in line 3. What I would ask you is to add If you need, I'll create a PR for the feature. |
@NataliaDSmirnova Hmm... your technique looks very similar to that of #11349. :-) |
Your lines are very cool 👍 Yes, our idea is close, but I think we've realized a closer effect for wide lines. See, how it looks: https://miew.app/?l=pdb:1CRN&p=macro&r=0&m=LN 😄 |
@NataliaDSmirnova Would you be willing to show that example with shadows added? |
I've added a link to an online example with shadows into PR #17932. It uses modified three.js, I've put temporarily on our site. By default, the mode with procedural sprites is set. |
Unfortunately #25933 from @RenaudRohlinger was closed but this function is something that's needed to support proper frustum culling support with shadows for BatchedMesh. Right now frustum culling will occur every frame based on the render camera on |
Oops didn't see I made this PR with my dev branch, not sure if I still got it somewhere I will check. |
Object3D.onBeforeRender not triggered when depthmaterial for shadows are rendered.
renderBufferDirect method does not trigger the onBeforeRender function
Three.js version
Browser
OS
Hardware Requirements (graphics card, VR Device, ...)
The text was updated successfully, but these errors were encountered: