Jump to content
  • Advertisement
Sign in to follow this  
quasty

OpenGL 2pass rendering in OpenGL / GLSL

This topic is 4791 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

Hi, does anyone now a guide to setup a 2pass rendering in GLSL, so that in the 2nd pass you got a texture to use exactly on the object as before? Every fragment of the object should have the same color it had in the first pass and the texture rendered to is placed on that object acordingly. Thus you can start the 2nd pass with the same color on the objects fragments, as the first pass ended. any ideas how to achieve that? The first pass is more or less correct, but I was wondering what texture coordinates could I use to place the texture that it exactly covers the object? thank in advance :)

Share this post


Link to post
Share on other sites
Advertisement
im not to sure what u want, explain better.
do u want to do
in the 2nd pass only draw to screenpiuxels that u drawed to in the first pass?
if so u can achieve this with the stencilbuffer or the use of destination alpha

Share this post


Link to post
Share on other sites
AFAIK what you do in each rendering pass is COMPLETELY independant of each other pass, and you cannot access the results of each pass. (save having to render each pass to a texture, and projecting that back) Your second pass automatically applies over the top of the geometry rendered in the first pass as long as your geometry is position invariant. You dont need to re apply those textures / lighting as they are already done.

Share this post


Link to post
Share on other sites
Thank you. what I want to do is use a 2D-texture from a rendering pass, and project it back on the geometry.

I guess RenderToTexture is the only way I can access other fragments/pixels. I want to render basic diffuse and ambient lighting (first pass) to a texture and then use some image processing technique on that texture and add this processed texture and some other render operations in a second pass back to the geometry.

I've searched for stencilbuffer and destination alpha, but what I found was about shadows. How can I use it to project a texture back to geometry?

thanks alot

Share this post


Link to post
Share on other sites
Sounds to me like you're trying to implement a "camera" system where you render one scene, then use the rendering as a texture on a surface that represents a monitor of some sort.

Is this right?

Share this post


Link to post
Share on other sites
No, but that's a nice thing to do too.
:)

I've ATM a one pass skin shader and wanted to add simulated subsurface scattering of light under the skin. I've read about an approach to render the diffuse lighting of a face to a texture, in a second pass blur and then project this texture back to the geometry; then adding specular lighting (and shadows) to the blurred first pass.

I've implemented everything but the projection of the texture at the geometry is the tricky part.

Share this post


Link to post
Share on other sites
1st pass: Render to texture. Using a pbuffer or whatever is handy out there nowadays.

2nd pass: Bind this texture to one of the multitexture slots

glActiveTextureARB(GL_TEXTURE2_ARB);
..bind texture here

Then in GLSL you would set up your texture variable

uniform sampler2D texture;

Then back in your program you bind this multitexture slot to that particular GLSL uniform variable.

texloc = glGetUniformLocationARB(program, "texture");
glUniform1iARB(texloc, 2);

Then in your shader, you can look into the texture at any location and use it how you need by using

texture2D(texture, vec2(...) )

Hopefully this is what you were asking? I'm not sure as to what you need for the actual texture coordinates :)


Share this post


Link to post
Share on other sites
Thank you very much.
Quote:
Then in your shader, you can look into the texture at any location and use it how you need by using

texture2D(texture, vec2(...) )
But this is the part that troubles me. How do I know where to look in the texture / find the specific texel to be projected at the fragment since I don't have texture coordinates?

Share this post


Link to post
Share on other sites
You dont calculate the texture coordinates yourself, you use the glTexEnv functions which generate texture coordinates for you. Im having problems right now myself getting it to correctly align the coordinates in normalized (0 to 1) screen space on the vertex pipeline, but it can be done using the fragments' position in a ARB_fragment_program. Not to sure if the fragment position works using window coordinates in GLSL though... If it can, then the texture coordinate is the fragment position (x,y) divided by the screen (width,height).

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!