Matrices for texture

Started by
0 comments, last by _WeirdCat_ 7 years, 3 months ago

I want to draw a seamless repeating texture as screen filling background.

My idea was, instead of drawing a lot of single quads, to draw a single static screen filling quad, set the texture to "repeat" and adjust the uv-coordinates in the shader.

I am in holidays right now and on my Mac OS X the GPU tracing tools do not start up so I can't check what is happening inside the shader to debug.

This is the simple Vertex-Shader


uniform mat4 projectionMatrix;
uniform mat4 modelMatrix;
uniform mat4 worldMatrix;
uniform sampler2D texture_diffuse;

in vec4 in_Position;
in vec2 in_TextureCoord;

out vec2 pass_TextureCoord;

void main(void) {
	gl_Position = projectionMatrix * modelMatrix * in_Position;
	vec4 uv_multiplier = vec4( 1.0, 1.0, 0, 0 ) / (projectionMatrix * worldMatrix * modelMatrix * vec4(textureSize( texture_diffuse, 0), 0, 0));
	pass_TextureCoord = in_TextureCoord * uv_multiplier.xy;
}

This is a 2D game, so there is no Z-coordinate.

I calculated it by hand, yet the screen is colored by the color of one single fragment of the used texture.

I am not asking you to calculate it for me, but maybe you have a quick idea what is wrong or maybe you have a better idea to achieve this effect! :)

Advertisement

this is wrong

vec4 uv_multiplier = vec4( 1.0, 1.0, 0, 0 ) / (projectionMatrix * worldMatrix * modelMatrix * vec4(textureSize( texture_diffuse, 0), 0, 0));
pass_TextureCoord = in_TextureCoord * uv_multiplier.xy;

maybe you could tell us what are you trying to achieve here why you use uv_multiplier, leaving pass_TextureCoord = in_TextureCoord; should fix the problem if you dont see proper tex coords then fragment shader is wrong too

This topic is closed to new replies.

Advertisement