SOLVED Help finding UV coordinates for normal texture

Kahrabaa

Member
Hi,
I am semi-beginner in shaders and have normal mapping setup and working (from a tutorial).
The problem is that Im using seperate texture pages for all sprites in the project which causes a ton of texture swaps.
What i've understood is that if I turn off "seperate texture page", I need to send in the info about the normal map's uvs on the texture page.

This is how the shader works with 0-1 uvs (seperate texture page)

GML:
vec3 NormalMap = texture2D(Normal, v_vTexcoord).rgb;
vec3 N = normalize( NormalMap * 2.0 - 1.0 );
vec3 LightDir =LightPos.xyz;
vec3 L= normalize(LightDir);
vec3 Diffuse = LightColor.rgb * max(dot(N, L), 0.0);
gl_FragColor = Diffuse;
So I get the uvs now with sprite_get_uvs and send in the info as a vec4 uniform, but how do I calculate the correct position to be used?

Ive tried putting the left and top uv coords instead of v_vTexcoord:
vec3 NormalMap = texture2D(Normal, NormalUVS.xy ).rgb;
Didn't work.
I also tried to enter the center of the coordinates: NormalUVS.xy+ ( NormalUVS.zw - NormalUVS.xy) *0.5;
But that also didn't work.

I have no clue how to move forward here and am just guessing away.
If only I could do show_message inside the shader I could gradually understand more.

I hope my problem is clear.
Thanks for any help.

Ps. Will scaling the image using image_xscale,yscale mess up the uv's sent in? If so where do I multiply for correct transformation. I already have a vec3 Transform uniform sent in with xscale,yscale and angle.
 

kburkhart84

Firehammer Games
Check this out.

It does what you are wanting already, saving you time coding it(and it is now free too). You would just need to do some changes to get it updated for GMS2(which I spent some time doing as well). If nothing else, you can check out how it handled what you need as far as correcting the UVs.
 

Kahrabaa

Member
Awesomeness!

Big thanks to the TheMojoCollective for their contribution
And thanks kburkhart84 for the tip ✌

GML:
vec2 _duvs = vec2(
(v_vTexcoord.x-DiffuseUvs.x)/(DiffuseUvs.z-DiffuseUvs.x),
(v_vTexcoord.y-DiffuseUvs.y)/(DiffuseUvs.a-DiffuseUvs.y)
);

vec2 _nuvs = vec2(
mix(NormalUvs.x,NormalUvs.z,_duvs.x),
mix(NormalUvs.y,NormalUvs.a,_duvs.y)
);   

vec3 NormalMap = texture2D(Normal, _nuvs).rgb;
This did the job.
 

Tyg

Member
i have a little function that aligns other textures or channels with the base texture
if your texture is not the same size as the base texture
if its something your interested in i can dropbox it :)
 
Top