-
-
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
MRT Support #16390
MRT Support #16390
Conversation
Nice! I did not review the renderer code, though. The hard part. :-) |
Looking great! It could be nice to add also a WebGL1 MRT example to see the differences and test between both implementations |
Thanks for the review. I updated. One concern with WebGL 1. No proper way to inject |
@takahirox thanks, sounds good, we could get webgl2 support landed and iterate on the webgl1 example in another PR. |
Hi, any plans to release this in r106? |
There is already |
For MRT we need a way to bind multiple color attachments to the framebuffer and I don't think this is possible with the current API. |
This is great. Hope this can land soon. Two notes, Firstly, built in materials currently write Secondly, in the example, the texture options is set like this renderTarget = new THREE.WebGLMultiRenderTarget( window.innerWidth * window.devicePixelRatio, window.innerHeight * window.devicePixelRatio, 2 );
renderTarget.texture.format = THREE.RGBAFormat;
renderTarget.texture.minFilter = THREE.NearestFilter;
renderTarget.texture.magFilter = THREE.NearestFilter;
renderTarget.texture.type = THREE.FloatType;
renderTarget.texture.generateMipmaps = false; but to my understanding, this wont actually do anything. There is already a way to set it that does seem to work though, so changing this might be good before releasing. renderTarget = new THREE.WebGLMultiRenderTarget(
window.innerWidth * window.devicePixelRatio,
window.innerHeight * window.devicePixelRatio,
2,
{
format: THREE.RGBAFormat,
minFilter: THREE.NearestFilter,
magFilter: THREE.NearestFilter,
type: THREE.FloatType,
generateMipmaps: false
}
); Do verify this before changing it, but it seems highly odd the way it is. |
src/renderers/webgl/WebGLTextures.js
Outdated
@@ -753,14 +775,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, | |||
// Render targets | |||
|
|||
// Setup storage for target texture and bind it to correct framebuffer | |||
function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) { | |||
function setupFrameBufferTexture( framebuffer, renderTarget, texture, attachment, textureTarget ) { | |||
|
|||
var glFormat = utils.convert( renderTarget.texture.format ); | |||
var glType = utils.convert( renderTarget.texture.type ); | |||
var glInternalFormat = getInternalFormat( glFormat, glType ); | |||
state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null ); |
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 can probably wait but is it possible for the different color attachments to have different sizes?
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 am not sure if different image sizes have any real-world usage (if supported at all). Although the fragment stage outputs several colors, the rasterization stage has been executed only once, so separate target resolutions are not possible. To write to the smaller/bigger images the driver would need to down/up sample which might be possible but the gain of having some of them smaller is probably none. The gain of MRT is to exactly execute everything prior the fragment shader once only.
According to this post it might work but will be rendered with the size of the smallest image https://community.khronos.org/t/fbo-with-different-size-attachments/62925/2
P.S. Different formats and types for the images are possible and have practical usage. I read that some combination could possibly fail depending on the implementation. Not sure if this applies to WebGL or OpenGL only.
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'd like to go as is so far, and consider different size if users actually demand it.
Thanks for the comments.
Built-in material as is seems working fine with
|
Thanks for the comments. Updated. And using module in example now. I think ready to go. |
I think this is almost there! We should be able to land this at the beginning of the next dev cycle 🤞 A few more changes... I don't think we should add As per the class name, I think I'm not sure it's a good idea to extend from |
That sounds good to me.
I have removed And
Sounds good to me. I renamed it.
Personally I prefer extending |
So, r128 has been released. It's time to go now? |
Happy 2nd birthday to this PR!! 🥳🥳🥳🥳 |
What better way to celebrate than... |
Thanks! |
Finally the time has come, thanks! The PR was originally made two years ago. There are a lot of updates which may affect the PR in the core during that time. I think I carefully kept updating the PR but let me know if you folks find anything which doesn't match the newest core API/design/behavior/etc. @Mugen87 As I wrote in the PR comment, I took over @mattdesl and @edankwan works. Would you please add their names in the change log next to me? |
And I think there is a big room for API improvement. For example currently When I made this PR, there were a lot of difficulties and limitations to improve the API. But during the two years we have had tons of new features and simplifications in Three.js (mainly done by @Mugen87 thanks). Such difficulties and limitations might have been removed and we might be able to improve the API now. Let's cooperate and work on it all together. |
Fixes #5179.
Kudos to @mattdesl and @edankwan
MRT PR was opened #9358 #8439. It needed to be cleaned up to get merged but that PR hasn't been updated for years. I still want to see MRT in Three.js, so I cleaned up and created a new PR.
API
In the current implementation, users need to use
RawShaderMaterial
(oronBeforeCompile()
for built-in material) to render toWebGLMultiRenderTarget
.