instantreality forum
news: Welcome to the instantreality forums!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
January 17, 2018, 02:31:31 am


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: [SOLVED] Passing the frame- and depthbuffer to a GLSL-ShaderProgram  (Read 5576 times)
marsuek
Newbie
*
Posts: 10


View Profile
« on: September 01, 2011, 11:17:42 am »

Hi there,

i want to implement a postprocessing shader that needs information from both the framebuffer and the depthbuffer. So I add two RenderedTextures to the PolygonOverlays Appearance. The first is the framebuffer, the second marked with depthMap='true' is the depthbuffer.
I thought that I can access them with the textureIDs 0 and 1 (compare to field-values in postProcessing.framebuffer.value and postProcessing.depthbuffer.value)

Code:
   <Foreground>
      <PolygonOverlay>
        <Appearance>
          <RenderedTexture minFilter='linear' magFilter='linear' update='always' dimensions='1024 1024 0'>
            <Viewpoint containerField='viewpoint' USE='myViewpoint'/>
          </RenderedTexture>
          <RenderedTexture depthMap='true' minFilter='linear' magFilter='linear' update='always' dimensions='1024 1024 255'>
            <Viewpoint containerField='viewpoint' USE='myViewpoint'/>
          </RenderedTexture>
          <ComposedShader DEF='postProcessing' language='GLSL'>
            <field accessType='inputOutput' name='framebuffer' type='SFInt32' value='0'/>
            <field accessType='inputOutput' name='depthbuffer' type='SFInt32' value='1'/>
            <!--
            <field accessType='inputOutput' name='positions' type='MFVec3f' value='-2 2 0 2 2 0 -2 -2 0 2 -2 0'/>
            <field accessType='inputOutput' name='levels' type='MFInt32' value='0 1 2 3'/>
            -->
            <ShaderPart type='VERTEX'><![CDATA[
                  #version 330 compatibility

                  void main(void)
                  {
                    gl_Position = ftransform();
                    gl_TexCoord[0] = gl_MultiTexCoord0;
                    gl_TexCoord[1] = gl_MultiTexCoord1;
                  }
                  ]]>
            </ShaderPart>
            <ShaderPart type='FRAGMENT'><![CDATA[
                  #version 330 compatibility
              
                  uniform sampler2D framebuffer;
                  uniform sampler2D depthbuffer;
                  /*
                  uniform vec3 positions[];
                  uniform int levels[];
                  */
                                      
                  void main(void)
                  {
                    gl_FragColor = texture2D(framebuffer, gl_TexCoord[0].st);
                  }
                  ]]>
            </ShaderPart>
          </ComposedShader>
        </Appearance>
      </PolygonOverlay>
    </Foreground>

But the textureIDs seem to be wrong because the GLSL-compiler always ignores the first RenderedTexture, because the second one overwrites it:

Code:
WARNING OpenSG Unknown parameter 'depthbuffer'!

My first attempt was the use of only one single RenderedTexture with deptMap='false true' but I didn't know how to access the single textures. Are there any? Sorry I don't understand it by reading the docs...

@Offtopic:
I get an equal OpenSG-error when trying to set other uniforms (see uncommented fields).
« Last Edit: September 07, 2011, 12:44:54 pm by marsuek » Logged
marsuek
Newbie
*
Posts: 10


View Profile
« Reply #1 on: September 01, 2011, 12:47:18 pm »

This (see attachment) is how I would do it with only one RenderedTexture but I don't know how to get access to the different textures.

Their 'isADepthMap'-properties are set by depthMap='false true' etc. That would mean that texture[0] is 'false', texture[1] is 'true', when texture[j] is one single texture2D layer in a texture3D, isn't it?
I assumed that the '2' in dimension '1024 1024 2' refers to the 3D-textures size in z-direction and if I say that zOffset='1' the 3D-texture only can contain 2 layers and I could access them by either (framebuffer)

Code:
gl_FragColor = texture3D(tex, vec3(gl_TexCoord[0].s, gl_TexCoord[0].t, 0));

or (depthbuffer):

Code:
gl_FragColor = texture3D(tex, vec3(gl_TexCoord[0].s, gl_TexCoord[0].t, 1));
Logged
yjung
Administrator
Sr. Member
*****
Posts: 260


View Profile
« Reply #2 on: September 02, 2011, 12:44:11 pm »

Concerning your first post, where you got the warning "Unknown parameter 'depthbuffer'", the reason simply is that your graphics card driver optimizes the code such that unused variables are ignored. In your case, your shader only contained the follwing line:
Code:
gl_FragColor = texture2D(framebuffer, gl_TexCoord[0].st);
Since you never tried to access the second texture, the corresponding uniform variable is optimized away and therefore, you got that warning. So, just use it and then the warning goes away...

Concerning your second post, please the node documentation:
http://doc.instantreality.org/documentation/nodetype/Renderedtexture/
As can be seen, the third value describes the number of components (e.g. 4 in case of RGBA), while the fourth value describes the depth size.
Admittedly, this seems rather odd, but this is to assure compatibility to the node's original specification as proposed by the Xj3D team:
http://www.xj3d.org/extensions/render_texture.html

Hope that helps
Yvonne
Logged
marsuek
Newbie
*
Posts: 10


View Profile
« Reply #3 on: September 07, 2011, 12:44:41 pm »

Thank you, I didn't know that. I'll give it a try...
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.15 | SMF © 2011, Simple Machines