Posted By: djfeeler
[Solved] I ask help to combine two shaders - 01/06/14 13:01
Hello,
I wonder if anyone can help me to combine these two shaders.
first shader tiling
And this other shader with light
I do this but I'm not sure if this is good.
Thanks in advance.
djfeeler
I wonder if anyone can help me to combine these two shaders.
first shader tiling
Code:
float4x4 matWorld; float4x4 matWorldViewProj; float4 vecSkill41; texture entSkin1; sampler TexSampler = sampler_state { Texture = <entSkin1>; MipFilter = Linear; AddressU = Wrap; Addressv = Wrap; }; struct out_tiling { float4 Pos : POSITION; float2 Tex0 : TEXCOORD0; }; out_tiling vs_20 ( in float4 inPos : POSITION, in float2 inTex0 : TEXCOORD0 ) { out_tiling Out; Out.Pos = mul(inPos,matWorldViewProj); Out.Tex0 = inTex0; return Out; } float4 ps_20 ( out_tiling In ): COLOR { float2 Coord; Coord.x = In.Tex0.x * vecSkill41.x; Coord.y = In.Tex0.y * vecSkill41.y; return tex2D ( TexSampler, Coord ); } technique TexTile { pass one { VertexShader = compile vs_2_0 vs_20(); PixelShader = compile ps_2_0 ps_20(); } }
And this other shader with light
Code:
float4x4 matWorldViewProj; float4x4 matWorld; float4 vecSunDir; float4 vecSunColor; float4 vecSkill41; texture entSkin1; sampler ColorMapSampler = sampler_state { Texture = <entSkin1>; }; void DiffuseVS( in float4 InPos: POSITION, in float3 InNormal: NORMAL, in float2 InTex: TEXCOORD0, out float4 OutPos: POSITION, out float2 OutTex: TEXCOORD0, out float3 OutNormal: TEXCOORD1) { OutPos = mul(InPos, matWorldViewProj); OutNormal = normalize(mul(InNormal, matWorld)); OutTex = InTex*vecSkill41.x; } float4 DiffusePS( in float2 InTex: TEXCOORD0, in float3 InNormal: TEXCOORD1): COLOR { float4 Diffuse = saturate(dot(-vecSunDir, normalize(InNormal))); Diffuse *= vecSunColor; float4 Color = tex2D(ColorMapSampler, InTex); return (0.5+Diffuse)*Color; } technique DiffuseTechnique { pass P0 { VertexShader = compile vs_2_0 DiffuseVS(); PixelShader = compile ps_2_0 DiffusePS(); } }
I do this but I'm not sure if this is good.
Code:
float4x4 matWorldViewProj; float4x4 matWorld; float4 vecSunDir; float4 vecSunColor; float4 vecSkill41; texture entSkin1; sampler ColorMapSampler = sampler_state { Texture = <entSkin1>; MipFilter = Linear; AddressU = Wrap; Addressv = Wrap; }; void DiffuseVS( in float4 InPos: POSITION, in float3 InNormal: NORMAL, in float2 InTex: TEXCOORD0, out float4 OutPos: POSITION, out float2 OutTex: TEXCOORD0, out float3 OutNormal: TEXCOORD1) { OutPos = mul(InPos, matWorldViewProj); OutNormal = normalize(mul(InNormal, matWorld)); OutTex = InTex; } float4 DiffusePS( in float2 InTex: TEXCOORD0, in float3 InNormal: TEXCOORD1): COLOR { float2 Coord; Coord.x = InTex.x * vecSkill41.x; Coord.y = InTex.y * vecSkill41.y; float4 finalCoord = tex2D ( ColorMapSampler, Coord ); float4 Diffuse = saturate(dot(-vecSunDir, normalize(InNormal))); Diffuse *= vecSunColor; float4 Color = tex2D(ColorMapSampler, InTex); return (0.5 + Diffuse) * Color * finalCoord; } technique DiffuseTechnique { pass P0 { VertexShader = compile vs_2_0 DiffuseVS(); PixelShader = compile ps_2_0 DiffusePS(); } }
Thanks in advance.
djfeeler