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 1 of 4 123 ... LastLast
Results 1 to 10 of 36

Thread: Multisample textures

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207

    Multisample textures

    I read some pages on google but still confused about working of multisample textures.
    Can anyone explain this concept? If possible please explain it with source code.
    Thanks.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Are you planning to use shaders or immediate mode?

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by tonyo_au View Post
    Are you planning to use shaders or immediate mode?
    i am going to use shaders.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Ok, that easier. You need to supply a uv for each texture in the vertex bindings (you can of course shared one uv for multiple textures. Then bind each texture to a sampler in the fragment shader. Fetch the texture pixels in the fragment shader and apply them as you see fit. I will post a little example - I am off to a boxing day do

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    example
    Code :
    vertex shader
     
    layout(location = VERTEX_BINDINGS_POSITION) in  vec3  Position;
    layout(location = VERTEX_BINDINGS_TEXTURE0) in  vec2  Texture0;
    layout(location = VERTEX_BINDINGS_TEXTURE1) in  vec2  Texture1;
     
    out vec2 texture0;
    out vec2 texture1;
     
    void main()
    {
     texture0 = Texture0;
     texture1 = Texture1;
     
     gl_Position = CameraProjection * CameraModelView * vec4(Position,1);
    }
     
    fragment
     
     
    in vec2 texture0;
    in vec2 texture1;
     
    uniform    sampler2D       Image0;
    uniform    sampler2D       Image1;
     
    layout(location = 0, index = 0) out vec4 fFragColour;
     
     
     
    void main()
    {
     
      vec4 c0 = texture2D(Image0,p_Texture0.st);
      vec4 c1 = texture2D(Image1,p_Texture1.st);
     
      vec4 colour = mix(c0,c1,c1.a); // some blend function
     
      fFragColour = colour;
     
    }

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by tonyo_au View Post
    example
    Code :
    vertex shader
     
    layout(location = VERTEX_BINDINGS_POSITION) in  vec3  Position;
    layout(location = VERTEX_BINDINGS_TEXTURE0) in  vec2  Texture0;
    layout(location = VERTEX_BINDINGS_TEXTURE1) in  vec2  Texture1;
     
    out vec2 texture0;
    out vec2 texture1;
     
    void main()
    {
     texture0 = Texture0;
     texture1 = Texture1;
     
     gl_Position = CameraProjection * CameraModelView * vec4(Position,1);
    }
     
    fragment
     
     
    in vec2 texture0;
    in vec2 texture1;
     
    uniform    sampler2D       Image0;
    uniform    sampler2D       Image1;
     
    layout(location = 0, index = 0) out vec4 fFragColour;
     
     
     
    void main()
    {
     
      vec4 c0 = texture2D(Image0,p_Texture0.st);
      vec4 c1 = texture2D(Image1,p_Texture1.st);
     
      vec4 colour = mix(c0,c1,c1.a); // some blend function
     
      fFragColour = colour;
     
    }
    Thanks for the reply. But the code you have provided is for multi-texturing and not multisample texture

  7. #7
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207

    Multisampled Textures

    i want to use multisampled textures.

    What will be the fragment shader and how to pass multiple samplers to shader?

    Also, which API can be used to load texel data ?

    I want to use default FBO for this.

  8. #8
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,218
    Typically you would pass these into a shader via a sampler2DMS and sample them via texelFetch(). Web search those and you'll come up with some good sample code. There's some in the archives of these forums as well (see the search box above).

    And please don't cross-post. I re-merged your threads.
    Last edited by Dark Photon; 12-27-2012 at 02:51 PM.

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    wops - mis-read that here is a sample
    Code :
    uniform  sampler2DMS    u_2DMS; 
    uniform  float          u_Translucency;
     
    layout(location = 0, index = 0) out vec4 fFragColour;
     
    void main()
    {
      ivec2 st = ivec2(vData.texture0.st * u_Screen.xy);
     
      vec4 colour = texelFetch(u_2DMS,st,gl_SampleID);
     
      colour.w *= u_Translucency;
     
      fFragColour = colour;
     
    }

  10. #10
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by tonyo_au View Post
    wops - mis-read that here is a sample
    Code :
    uniform  sampler2DMS    u_2DMS; 
    uniform  float          u_Translucency;
     
    layout(location = 0, index = 0) out vec4 fFragColour;
     
    void main()
    {
      ivec2 st = ivec2(vData.texture0.st * u_Screen.xy);
     
      vec4 colour = texelFetch(u_2DMS,st,gl_SampleID);
     
      colour.w *= u_Translucency;
     
      fFragColour = colour;
     
    }
    Thanks for the reply..
    as gl_samplerID is supported on after 4.0 versions, what would replace it?

Posting Permissions

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