Jump to content

  • Log In with Google      Sign In   
  • Create Account


Fragment output to specific color attachment? (SOLVED)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Manabreak   Members   -  Reputation: 141

Like
0Likes
Like

Posted 18 August 2012 - 09:23 AM

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.

Sponsor:

#2 dpadam450   Members   -  Reputation: 889

Like
0Likes
Like

Posted 18 August 2012 - 06:51 PM

gl_FragData[i] unless it has changed in GL 3.0/4.0

#3 Lazy Foo   Members   -  Reputation: 1105

Like
2Likes
Like

Posted 18 August 2012 - 09:29 PM

gl_FragData[i] 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


#4 Manabreak   Members   -  Reputation: 141

Like
0Likes
Like

Posted 19 August 2012 - 12:50 AM

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... Posted Image

#5 Lazy Foo   Members   -  Reputation: 1105

Like
1Likes
Like

Posted 19 August 2012 - 02:36 AM

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... Posted Image


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


#6 Manabreak   Members   -  Reputation: 141

Like
0Likes
Like

Posted 19 August 2012 - 04:09 AM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS