Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 36

Thread: Multisample textures

  1. #11
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,218
    Quote Originally Posted by debonair View Post
    as gl_samplerID is supported on after 4.0 versions, what would replace it?
    You don't need it to access multisample textures. You only need it if you plan to do per-sample rasterization.

    And while that is core in GL/GLSL 4.0, you can also get it through the ARB_sample_shading extension.

  2. #12
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by Dark Photon View Post
    You don't need it to access multisample textures. You only need it if you plan to do per-sample rasterization.

    And while that is core in GL/GLSL 4.0, you can also get it through the ARB_sample_shading extension.
    so, i should pass 3rd parameter as 0 ?
    and if i want "per-sample rasterization" then ?

  3. #13
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    The 3rd parameter is to select the sample. If for example you wanted to save each sample in a separate texture buffer, you could loop in your cpu code calling a whole screen render and set a uniform to say which sample to fetch. If you just want to merge the samples into a single texture you can use glBlitFramebuffer or do it manually in a shader by fetching all the samples and averaging them.

  4. #14
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by tonyo_au View Post
    The 3rd parameter is to select the sample. If for example you wanted to save each sample in a separate texture buffer, you could loop in your cpu code calling a whole screen render and set a uniform to say which sample to fetch. If you just want to merge the samples into a single texture you can use glBlitFramebuffer or do it manually in a shader by fetching all the samples and averaging them.
    Now, if i choose to do it manually in shader with 4 samples, my shader will be:

    Code :
    uniform sampler2DMS tk_diffuseMap;
    in vec3 ps_texCoord;
    out vec4 fragColor;
     
    void main(void)
    {
     
    	vec2 iTmp = textureSize(tk_diffuseMap);
    	vec2 tmp = floor(iTmp * ps_texCoord.xy);
     
    	vec4 color;
    	for(int i = 0; i < 4; ++i)
    	{
    		color+ = texelFetch(depthTex, ivec2(tmp), i);
     
     
    	}
     
    fragColor=color;
    }
    What do you mean by "averaging them" ?
    and if i am using texture unit 0 i.e. only 1 texture, uniform will be set to 0.

    Correct me if wrong.
    Last edited by debonair; 01-02-2013 at 12:17 AM.

  5. #15
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    You logic outputs the sum of the samples not the average. To average you need to divide the colour by the number of samples. This is of course the simplest thing you can do. You could convert the rgb to a better colour space to do the averaging.

  6. #16
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by tonyo_au View Post
    You logic outputs the sum of the samples not the average. To average you need to divide the colour by the number of samples. This is of course the simplest thing you can do. You could convert the rgb to a better colour space to do the averaging.
    ohh. Thanks for pointing out.

    Now, i am rendering white cube with green background in non default FBO and attaching the created multisampled texture to this FBO.
    When i render a cube in default FBO using above texture, it gives corruption in texture.

    Here is my code:
    Code :
    viewport_width=32;
    viewport_height=32;
    		glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureId);
    		nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glBindTexture(*target, textureId);"));		
     
    		glUniform1i(glGetUniformLocation(shader_data.psId,"tk_diffuseMap"), 0);
    		nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glUniform1i(glGetUniformLocation(shader_data.psId,\"basetexture\"), 0);"));
     
    		glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4 ,GL_RGBA, viewport_width, viewport_height ,true);	
    		nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4 ,GL_RGBA, 32, 32,true);"));		
     
    		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, Fboid);
    		nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glBindFramebuffer(GL_FRAMEBUFFER, Fboid);"));
     
    		glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D_MULTISAMPLE,textureId,0);	
    		nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D_MULTISAMPLE,textureId,0);"));
     
    		glEnable(GL_MULTISAMPLE);
    		nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glEnable(GL_MULTISAMPLE);"));
     
    		draw_cube(viewport_width, viewport_height);
     
                    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    		nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glBindFramebuffer(GL_FRAMEBUFFER, Fboid);"));
     
    		glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureId);
    		nResult |= GL_ERROR_CHECK((GL_NO_ERROR, "glBindTexture(*target, textureId);"));		
     
                    glDrawElements ( GL_TRIANGLES, 36,GL_UNSIGNED_INT, indices );

    fragment shader

    Code :
    uniform sampler2DMS tk_diffuseMap;
    in vec3 ps_texCoord;
    out vec4 fragColor;
     
    void main(void)
    {
     
    	vec2 iTmp = textureSize(tk_diffuseMap);
    	vec2 tmp = iTmp * ps_texCoord.xy;
     
    	vec4 color;
    	for(int i = 0; i < 4; ++i)
    	{
    		color = color + texelFetch(tk_diffuseMap, ivec2(tmp), i);
    	}
     
    fragColor=vec4(color/4);
    }

  7. #17
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Your code looks all back to front.What are you exactly trying to do?

  8. #18
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by tonyo_au View Post
    Your code looks all back to front.What are you exactly trying to do?
    I am rendering a cube on non default FBO and creating a multisampled texture attached to this FBO. Now, i am applying this multisampled texture on a cube rendered on default FBO. I am using "render to texture" concept here.

    I am getting diagonally half of one of 6 faces green. and rest of the faces black...

  9. #19
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    I would look at the uv values you are using to render the cube. Also have you dumped the texture out as an image to be sure your texture is ok since I assume you have created it programmatically. Also why are using a mutlisample for a texture on the cube rather than a mipmap.

  10. #20
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by tonyo_au View Post
    I would look at the uv values you are using to render the cube. Also have you dumped the texture out as an image to be sure your texture is ok since I assume you have created it programmatically. Also why are using a mutlisample for a texture on the cube rather than a mipmap.
    Code :
    		GLfloat tex_coords[]={
    		0.0, 0.0,0.0,
            1.0, 0.0,1.0,
            1.0, 1.0,1.0,
    		0.0, 1.0,0.0,
     
    		0.0, 0.0,0.0,
            1.0, 0.0,1.0,
            1.0, 1.0,1.0,
    		0.0, 1.0,0.0,
     
    		0.0, 0.0,0.0,
            1.0, 0.0,1.0,
            1.0, 1.0,1.0,
    		0.0, 1.0,0.0,
     
    		0.0, 0.0,0.0,
            1.0, 0.0,1.0,
            1.0, 1.0,1.0,
    		0.0, 1.0,0.0,
     
    		0.0, 0.0,0.0,
            1.0, 0.0,1.0,
            1.0, 1.0,1.0,
    		0.0, 1.0,0.0,
     
    		0.0, 0.0,0.0,
            1.0, 0.0,1.0,
            1.0, 1.0,1.0,
    		0.0, 1.0,0.0
    };

    I am neglecting a third component of tex cords in a shader.
    Yeah, i confirmed my texture is correct when i rendered that to default FBO.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •