-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[BETA] ESM Grid Renderer Script #7079
Conversation
Yea so thats the dithering alpha @slimbuck we should prob add a flag for this what do you think? |
Make sure the grid is the last opaque object rendered. Then only semitrans objects will expose the dithering. |
The grid doesn't scale correctly when the screen aspect ratio changes Screen.Recording.2024-11-01.at.15.11.30.mov |
This seems to be related to getFrustumCorners! And I've just seen the corresponding fix https://github.com/playcanvas/engine/pull/7077/files |
@kpal81xd - keen to get this ready for the release? |
Id say no since I have another PR for a grid that uses a mesh instead of being just a renderer WIP so I want to evaluate the use case of both |
scripts/esm/grid-renderer.mjs
Outdated
} | ||
this.app.scene.on('prerender:layer', (camera, layer, transparent) => { | ||
if (!camera.layers.includes(targetLayer.id)) { | ||
camera.layers = camera.layers.concat(targetLayer.id); |
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.
I really don't like changing camera.layers from inside the rendering callback.
That means at least one frame will be rendered incorrectly, and could even cause some crashes, as for example meshes on that layer were not culled for the camera, but in the middle of the frame, camera new needs to render them.
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.
Ahh i see what would you suggest I change it to instead?
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.
So ive currently changed it to store the cameras in the prerender but update the layers in an update loop. Would that solve the issue?
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.
It would not, it's still a mid frame rendering callback.
Things like that need to be set up before the rendering, and not during.
So doing things like that in the scripts initialise / update is the correct way.
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.
I guess theres no other way then and the grid has to be attached to the camera
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.
Or the grid could be assigned a layer, that's what it really needs right? So that the mesh instance is added to that layer.
Inside the preRender callback, a uniform with the camera properties can be changed on the material, I believe there was this need as well.
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.
So the grid does have a layer set so I could add a hook on there but does that pass the camera as parameter?
Not sure what you mean about the material tho
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.
this one does:
Lines 109 to 120 in c26ecf6
* Fired when the camera renders a layer. The handler is passed the {@link CameraComponent}, | |
* the {@link Layer} that will be rendered, and a boolean parameter set to true if the layer is | |
* transparent. This is called during rendering to a render target or a default framebuffer, and | |
* additional rendering can be performed here, for example using {@link QuadRender#render}. | |
* | |
* @event | |
* @example | |
* app.scene.on('postrender:layer', (camera, layer, transparent) => { | |
* console.log(`Camera ${camera.entity.name} rendered the layer ${layer.name} (transparent: ${transparent})`); | |
* }); | |
*/ | |
static EVENT_POSTRENDER_LAYER = 'postrender:layer'; |
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.
I thought you needed to set some camera view matrix or similar uniform, not entirely sure. Ignore if not.
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.
Not set I just need to get the projection and the frustum corners
Ports grid into a script from supersplat editor with changes:
resolution: GridRenderer.RESOLUTION_HIGH | GridRenderer.RESOLUTION_MEDIUM | GridRenderer.RESOLUTION_LOW
halfExtents: Vec2
colorX: Color
,colorZ: Color
Preview