• Advertisement
Sign in to follow this  

Fragment output to specific color attachment? (SOLVED)

This topic is 1982 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Heya,

I've been crawling through GLSL and MRT tutorials for a few days, and everything's going nicely. Now, I have a FBO with two textures bound to it, to ColorAttachment0 and ColorAttachment1. I want to draw the diffuse (color) to the first one, and the surface normals to the second one. How is this achieved? The result I want is to have the diffuse data on the first texture (bound to ColorAttachment0) and the normal data on the second texture (bound to ColorAttachment1).

I've done this in HLSL, where I was able to specify an output variable with COLOR0, COLOR1 etc., but I haven't found anything similar in GLSL.

Share this post


Link to post
Share on other sites
Advertisement

gl_FragData unless it has changed in GL 3.0/4.0


It has, you need to bind your fragment location before you link your program.

Share this post


Link to post
Share on other sites
Thanks, it works! What about the new input system for vertex shaders? I know how to set the uniform variables, but how do I supply the vertex position and normal data? I use VBOs for my meshes, and they include the position, normal and UV coord. data, and I call the buffer data pointers before drawing the elements, but I don't know how to reach the data from the vertex shader... sad.png

Share this post


Link to post
Share on other sites

Thanks, it works! What about the new input system for vertex shaders? I know how to set the uniform variables, but how do I supply the vertex position and normal data? I use VBOs for my meshes, and they include the position, normal and UV coord. data, and I call the buffer data pointers before drawing the elements, but I don't know how to reach the data from the vertex shader... sad.png


Using custom GLSL attributes. Where uniforms are variables used on all the vertex data, attributes are from each instance of the vertex data, All you have to do is 1) Define the variable in your vertex shader and fragment shader as you need them, 2) get the variable location in your OpenGL program using glGetAttribLocation() 3) Enable the attribute and set the data pointer.

Share this post


Link to post
Share on other sites
Thanks, I actually found your web site after my last post and crawled through the examples, and got the thing finally working!

It's quite sad there's so little amount of info and tutorials about modern OpenGL / GLSL. Majority of stuff is for the obsolete / deprecated techniques. Also, the ones that actually are somewhat "modern", are done in painstakingly complex ways. Thankfully, your tutorials are simple enough, but some other tutorials use abstractive layers extensively to the point that a newbie like myself must spend hours trying to find the actual thing from the code - not even mentioning the fact I don't do C++, which makes it even more frustrating to read the sources.

Anyways, thanks, Lazy Foo!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement