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 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 36

Thread: Multisample textures

  1. #21
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    I assume your vertex shader has the texture coordinate in defined as a vec3?

  2. #22
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    206
    Quote Originally Posted by tonyo_au View Post
    I assume your vertex shader has the texture coordinate in defined as a vec3?

    yes.
    Vertex shader:
    Code :
    in vec3 inputtexcoord;
    in vec3 tk_position;
    out vec3 ps_texCoord;
     
    uniform mat4 tk_mvpMatrix;
    void main(void)
    {
            ps_texCoord = inputtexcoord;
    gl_Position = tk_mvpMatrix * vec4(tk_position, 1.0); 
    }

    fragement

    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 = color + texelFetch(tk_diffuseMap, ivec2(ps_texCoord), i);
    	}
     
    fragColor=vec4(color/4);
    }

  3. #23
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Sorry I should have seen this earlier

    texelFetch texture coordinates are in pixels not 0-1; so you need to multiply uv by texture width and height

  4. #24
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    206
    Quote Originally Posted by tonyo_au View Post
    Sorry I should have seen this earlier

    texelFetch texture coordinates are in pixels not 0-1; so you need to multiply uv by texture width and height
    There was a mistake in above frag shader: for
    texelFetch(tk_diffuseMap, ivec2(ps_texCoord), i);


    Now,
    vec2 iTmp = textureSize(tk_diffuseMap);
    vec2 tmp =floor(iTmp * ps_texCoord.xy);
    color = color + texelFetch(tk_diffuseMap, ivec2(tmp), i);

    this also not working.
    Last edited by debonair; 01-04-2013 at 03:32 AM.

  5. #25
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    When I have errors like this that I can't understand I modify the frag shader to display the uv values, eg
    Code :
     
    fragColor=vec4(ps_texCoord.xy,0,1);
    fragColor=vec4(ps_texCoord.x,0,0,1); // to just see the u  values
    Now you can see how the texture is being mapped onto the cube. It may give a clue as to what is wrong

  6. #26
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    206
    Quote Originally Posted by tonyo_au View Post
    When I have errors like this that I can't understand I modify the frag shader to display the uv values, eg
    Code :
     
    fragColor=vec4(ps_texCoord.xy,0,1);
    fragColor=vec4(ps_texCoord.x,0,0,1); // to just see the u  values
    Now you can see how the texture is being mapped onto the cube. It may give a clue as to what is wrong
    Many thanks for your help..
    Got it working..

  7. #27
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Great to here

  8. #28
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    206
    When using multisampled textures, do i need to set samplers ( to number which i am using in glTexImage2DMultisample ) ? because i am assuming it needs to be set in MSAA. Please correct me if wrong. I have no idea how internally multisampling works..

  9. #29
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,193
    When just reading from multisample textures in a shader (what it sounds like you want to do), you can forget anything you might know (or not know) about multisample rasterization -- it doesn't matter. Conceptually you just have a texture where instead of having 1 vector value per pixel you have N vector values per pixel, where N is the number of samples per pixel you allocated for that multisample texture.

    To fetch the Nth sample from a particular pixel, just bind the multisample texture handle (what you get from glGenTextures) to a texture unit, and then in the shader, call texelFetch with the integer texcoord ("P") addressing the specific pixel and the "sample" argument being the sample index within that pixel.

  10. #30
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    206
    Quote Originally Posted by Dark Photon View Post
    When just reading from multisample textures in a shader (what it sounds like you want to do), you can forget anything you might know (or not know) about multisample rasterization -- it doesn't matter. Conceptually you just have a texture where instead of having 1 vector value per pixel you have N vector values per pixel, where N is the number of samples per pixel you allocated for that multisample texture.

    To fetch the Nth sample from a particular pixel, just bind the multisample texture handle (what you get from glGenTextures) to a texture unit, and then in the shader, call texelFetch with the integer texcoord ("P") addressing the specific pixel and the "sample" argument being the sample index within that pixel.
    Thanks, I mean to say do i need to set number of samples to 4 or 8 (instead of 1) while creating context in my config attributes?

Posting Permissions

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