Page 1 of 4 1234 LastLast
Results 1 to 10 of 36

Thread: Multisample textures

  1. #1
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318

    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
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    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
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    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
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318

    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
    Join Date
    Oct 2004
    Posts
    4,649
    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.

  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
    Senior Member Regular Contributor
    Join Date
    Apr 2012
    Posts
    318
    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?

Page 1 of 4 1234 LastLast

Similar Threads

  1. Cube and shadow multisample textures
    By imported_JoshKlint in forum OpenGL: General
    Replies: 11
    Last Post: 04-15-2014, 02:37 AM
  2. Cube and shadow multisample textures
    By imported_JoshKlint in forum OpenGL: GLSL
    Replies: 4
    Last Post: 09-24-2013, 09:04 AM
  3. Multisample FBO
    By aronsatie in forum OpenGL: Advanced Coding
    Replies: 19
    Last Post: 02-20-2007, 08:02 AM
  4. FBO and Multisample
    By M27 in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 01-18-2007, 03:10 AM
  5. multisample
    By in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-16-2002, 07:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean