Fragment output to specific color attachment? (SOLVED)

Started by
4 comments, last by HarriPellikka 11 years, 8 months ago
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.
Advertisement
gl_FragData unless it has changed in GL 3.0/4.0

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


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.

Learn to make games with my SDL 2 Tutorials

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

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.

Learn to make games with my SDL 2 Tutorials

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!

This topic is closed to new replies.

Advertisement