Jump to content
  • Advertisement
Sign in to follow this  
IceCave

Matrices for texture

This topic is 652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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! :)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!