Posted By: txesmi
Texture coords in shaders, are not linearly proportional? - 06/04/10 18:10
Hi friends,
I have been playing with 3dgs terraintex3 shader. I thought that i could read texture colors from only one texture using each quadrant for each texture with a texture like this:
I modified terraintex3.fx file to this:
My main problem is in this blocks:
As you can see in pixelshader code, i tried to calculate four different coordinates to be used in the mixture with reference to the mask map. If the mask is black uses NW quadrant, if it is blue uses NE quadrant, and so...
My surprise comes when I run the shader and got this result:
As you can see, the mixed texture loses his proportions and it is drawn one bigsize and one small in a clear pattern while the colors are perfectly in place. Could anyone clarify why this happens? Texture coords in shaders, are not linearly proportional? How can i resolve it?
I'm not a good codder and i'm touching the roof of my limited understanding of these things, so any response will be appreciated.
thx in advance, txes.
Salud!
I have been playing with 3dgs terraintex3 shader. I thought that i could read texture colors from only one texture using each quadrant for each texture with a texture like this:
I modified terraintex3.fx file to this:
Code:
#define SHADOWMAP #include <define> #include <transform> #include <sun> #include <lights> #include <fog> #include <normal> Texture entSkin1; // Red/green/blue for blending Texture entSkin2; // MultiTexture file Texture entSkin3; // ShadowMap //Texture entSkin4; // NormalMap float4 vecSkill41; float fAmbient; sampler sMaskTex = sampler_state { Texture = <entSkin1>; MipFilter = Linear; }; sampler sQuadTex = sampler_state { Texture = <entSkin2>; MipFilter = Linear; }; sampler sShadowTex = sampler_state { Texture = <entSkin3>; MipFilter = Linear; }; //sampler sNormalTex = sampler_state { Texture = <entSkin4>; MipFilter = Linear; }; ////////////////////////////////////////////////////////////////////// struct out_QuadTex // Output to the pixelshader fragment { float4 Pos : POSITION; float4 Color : COLOR0; float Fog : FOG; float2 MaskCoord : TEXCOORD0; float2 NWCoord : TEXCOORD1; float2 NECoord : TEXCOORD2; float2 SWCoord : TEXCOORD3; float2 SECoord : TEXCOORD4; float2 ShadowCoord : TEXCOORD5; }; out_QuadTex vs_QuadTex ( float4 inPos : POSITION, float3 inNormal : NORMAL, float2 inTexCoord0 : TEXCOORD0 ) { out_QuadTex Out; Out.Pos = DoTransform(inPos); // transform to screen coordinates // rotate and normalize the normal float3 N = DoNormal(inNormal); float3 P = mul(inPos,matWorld); Out.Color = fAmbient; // Add ambient and sun light for (int i=0; i<8; i++) // Add 8 dynamic lights Out.Color += DoLight(P,N,i); Out.Fog = DoFog(inPos); // Add fog Out.MaskCoord = inTexCoord0.xy; Out.ShadowCoord = inTexCoord0.xy; // scale the texture coordinates for the masked textures Out.NWCoord = (inTexCoord0.xy * vecSkill41.w)%0.5; Out.NECoord.x = ((inTexCoord0.x * vecSkill41.w)%0.5)+0.5; Out.NECoord.y = (inTexCoord0.y * vecSkill41.w)%0.5; Out.SWCoord.x = (inTexCoord0.x * vecSkill41.w)%0.5; Out.SWCoord.y = ((inTexCoord0.y * vecSkill41.w)%0.5)+0.5; Out.SECoord = ((inTexCoord0.xy * vecSkill41.w)%0.5)+0.5;/**/ /*Out.NWCoord = inTexCoord0.xy * vecSkill41.w; Out.NECoord = inTexCoord0.xy * vecSkill41.w; Out.SWCoord = inTexCoord0.xy * vecSkill41.w; Out.SECoord = inTexCoord0.xy * vecSkill41.w;/**/ return Out; } float4 ps_QuadTex(out_QuadTex In): COLOR { // retrieve the pixels for the textures and the masks float4 MaskColor = tex2D(sMaskTex,In.MaskCoord); float4 NWColor = tex2D(sQuadTex,In.NWCoord); float4 NEColor = tex2D(sQuadTex,In.NECoord); float4 SWColor = tex2D(sQuadTex,In.SWCoord); float4 SEColor = tex2D(sQuadTex,In.SECoord); float4 ShadowColor = tex2D(sShadowTex,In.ShadowCoord); // blend the blue, red and green textures over the base texture float4 NEMixed = lerp(NWColor,NEColor,MaskColor.b); float4 SWMixed = lerp(NEMixed,SWColor,MaskColor.r); float4 FinalColor = lerp(SWMixed,SEColor,MaskColor.g); // Add the vertex light and shadow map #ifdef SHADOWMAP FinalColor *= ShadowColor; #else FinalColor *= In.Color; #endif FinalColor.a = 1.0f; // prevent transparency return FinalColor; } technique QuadTex_13 { pass one { sampler[0] = (sMaskTex); sampler[1] = (sQuadTex); sampler[2] = (sShadowTex); VertexShader = compile vs_2_0 vs_QuadTex(); PixelShader = compile ps_2_0 ps_QuadTex(); } } // fallback if nothing works technique fallback { pass one { } }
My main problem is in this blocks:
Code:
// scale the texture coordinates for the masked textures Out.NWCoord = (inTexCoord0.xy * vecSkill41.w)%0.5; Out.NECoord.x = ((inTexCoord0.x * vecSkill41.w)%0.5)+0.5; Out.NECoord.y = (inTexCoord0.y * vecSkill41.w)%0.5; Out.SWCoord.x = (inTexCoord0.x * vecSkill41.w)%0.5; Out.SWCoord.y = ((inTexCoord0.y * vecSkill41.w)%0.5)+0.5; Out.SECoord = ((inTexCoord0.xy * vecSkill41.w)%0.5)+0.5;/**/ /*Out.NWCoord = inTexCoord0.xy * vecSkill41.w; Out.NECoord = inTexCoord0.xy * vecSkill41.w; Out.SWCoord = inTexCoord0.xy * vecSkill41.w; Out.SECoord = inTexCoord0.xy * vecSkill41.w;/**/
As you can see in pixelshader code, i tried to calculate four different coordinates to be used in the mixture with reference to the mask map. If the mask is black uses NW quadrant, if it is blue uses NE quadrant, and so...
My surprise comes when I run the shader and got this result:
As you can see, the mixed texture loses his proportions and it is drawn one bigsize and one small in a clear pattern while the colors are perfectly in place. Could anyone clarify why this happens? Texture coords in shaders, are not linearly proportional? How can i resolve it?
I'm not a good codder and i'm touching the roof of my limited understanding of these things, so any response will be appreciated.
thx in advance, txes.
Salud!