-
-
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
object callbacks #9738
object callbacks #9738
Conversation
I actually tested, it seems twice as fast to just call an empty function than to test for null. Any suggestions on what to do, i'd like to change both the way you have it now, and the way i'm doing it in this pull, should i just disregard this one and do another one? |
@@ -1525,12 +1525,15 @@ function WebGLRenderer( parameters ) { | |||
|
|||
} else { | |||
|
|||
if ( object.onBeforeRender !== null ) object.onBeforeRender(); | |||
if ( object.onBeforeRender !== null ) object.onBeforeRender( _this , _gl camera, fog, geometry, material, object, group ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot a comma after _gl
.
|
||
_this.renderBufferDirect( camera, fog, geometry, material, object, group ); | ||
|
||
} | ||
|
||
if ( object.onAfterRender !== null ) object.onAfterRender( _this , _gl camera, fog, geometry, material, object, group ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comma after _gl
too.
Just do another commit on your |
hmm did this work? |
It did! |
amazeballz! ill do a stencil buffer example from above, i think it's the most interesting since we don't have a high level interface for the stencil buffer and it's not mentioned too much in the literature |
Ok, the arguments that we're passing and its order deserves a bit of discussion though. I guess we're passing The only argument I find redundant is |
Agreed, but I think having object is useful more in lieu of a 'onwillupdate'. About the renderer, _gl is probably enough? |
I don't know what that means...
Nah, passing the renderer is fine. Maybe someone would like to do |
Right i forgot about that ( on the phone ). Still this could be done with _gl too but it's easier with the render api. I'd inject two more one before the matrices are computed 'onWillUpdate' and 'onHasUpdated'. That's where I'd definitely want access to the 'object'? |
There was something else I used with the renderer, possibly clear target as well, again all this could be done with _gl but it's more complicated |
What would be an use case? |
I wouldn't use _gl directly though. I would use |
How about different nomenclature?
|
Something along these lines:
could be done on prerender but would have to force the update of the matrices etc? This would help avoid putting a bunch of logic in the |
Sorry, I don't see what this brings us that can't be done already by simply animating the objects every frame. Lets stay on topic ( We were discussing the arguments we should pass. |
I'm thinking... object.onBeforeRender( _this, camera, geometry, material, group ); |
/ping @fallenoak @arose |
per previous request added after call added arguments to both calls
7958fdf
to
4dd9d0f
Compare
id still pass _gl just in case, maybe as the last argument? I might be a bit out of the loop but do we have a high level method to set the stencil op, enable the stencil buffer etc? Is it expensive to get gl out of _this every time? On a different note, i did use this to try to mimic a multipass rendering. Lets say you want to add a coat layer to a car body material, or something like that, render two geometries "on top" of each other with different materials. Just having one transparent and the other not would push these two different objects in different queues. I'd like to have one not write to depth, followed by an immediate render of the same geometry, writing to depth. For this i had something along the lines:
|
Thanks! |
Ok, this is how it's currently looking like: object.onBeforeRender( _this, scene, camera, geometry, material, group );
object.onAfterRender( _this, scene, camera, geometry, material, group ); |
@mrdoob Perfect! Thanks much, everyone! |
* object callbacks per previous request added after call added arguments to both calls * faster function evaluation, missing comma
Hmm, this The way dynamic uniforms were implemented probably wasn't as intuitive as it could have been, but at least the renderer knew if it encountered an object with dynamic uniforms then then that object must be excluded from any internal optimisations the renderer implements. Setting I'm going to submit a pull request soon that provides enormous performance gains for a lot of scenes. I was just rebasing it on |
How is this handled by game engines? |
Game engines typically don't expose low level systems like uniforms to high level systems like the the scene graph, at least not without one or more abstraction layers. This is extremely important for game engines as they're typically cross-platform and support multiple renderers (rendering details are hidden away). Callbacks also aren't typically called per object/node, they're called per controller (MVC), where the "view" is a "node", or in threejs' case an |
Hmm, not sure if i understand. In unity for example, you can write shaders, not sure if it gets any more low level than that in GL world, but you also use a gui, manage scene graphs and such. I haven't worked with it in a while but if i remember correctly you could do all kinds of stuff on all sorts of different SceneKit, the last thing i worked with also exposes very low level systems despite being so high level and pretty much useless :) I'm not a MVC master, but, shouldn't a node or an object actually be a Model in this case? I may be completely off here, but it feels that a shader is more like a view here. Your node contains data and state - rotation, position, color, scale, mesh, material properties etc. Shader says: "display this with lighting, use this state/data", "display the same set but flat shaded" etc. In any case i think it is cumbersome, but a functionality like this is needed in some way. |
@pailhead you don't change GL state in a shader which is what @Benjamin-Dobell is referring to. |
@pailhead thanks for the suggestion - this is related to my post on discourse: What’s the best simple way to handle the update pattern? However, this is not what I'm looking for. The goals of the update pattern are:
This helps with the latter, but breaks the first. |
I think technically it's not too hard to implement this sort of a pattern yourself by turning Ie.
|
per previous suggestion:
#7048
per previous pull:
#7806
recent discussion:
#9662
example (copied)
I didnt have time to come up with a meaningful example, but i did see some other features that were implemented that could also benefit from this.
My usage case would be something like this:
stencil buffer management
sequencing two meshes and a mask to render in a specific order and make use of the stencil buffer which has very little exposure in Three.
configuring a material before each call
Another example would be #7048 , but without the dynamic property and modifications to the renderer.
If there was a callback like this the same could be achieved with:
transforming objects that rely on other objects being transformed
I wish that i could have one Vector3 be a position that many different objects can reference, but three doesnt work like that.
With a callback