I assume your vertex shader has the texture coordinate in defined as a vec3?
Printable View
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); }
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
When I have errors like this that I can't understand I modify the frag shader to display the uv values, eg
Now you can see how the texture is being mapped onto the cube. It may give a clue as to what is wrongCode :fragColor=vec4(ps_texCoord.xy,0,1); fragColor=vec4(ps_texCoord.x,0,0,1); // to just see the u values
Great to here;)
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..
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.