|
|
Re: Blending textures
[Re: ChrisB]
#90452
09/19/06 19:36
09/19/06 19:36
|
Joined: Jul 2006
Posts: 783 London, UK
sheefo
OP
User
|
OP
User
Joined: Jul 2006
Posts: 783
London, UK
|
It's for models, and I need it in HLSL format. But thanks, that code looks nice  Can you convert it?
|
|
|
Re: Blending textures
[Re: sheefo]
#90453
09/19/06 20:06
09/19/06 20:06
|
Joined: Sep 2002
Posts: 1,604 Deutschland
ChrisB
Serious User
|
Serious User
Joined: Sep 2002
Posts: 1,604
Deutschland
|
Code:
float4x4 matWorldViewProj; texture entSkin1; texture entSkin2; sampler BlendSampler = sampler_state { Texture = <entSkin2>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; };
sampler ColorSampler =sampler_state { Texture=<entSkin1>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; };
void VS(in float4 inPos:POSITION, in float2 inTex:TEXCOORD0, out float4 outPos:POSITION, out float2 outTex:TEXCOORD0) { outPos=mul(inPos,matWorldViewProj); outTex=inTex; }
float4 PS(float2 inTex:TEXCOORD0) :COLOR { float4 color=tex2D(ColorSampler,inTex); float4 blend=tex2D(BlendSampler,inTex); return color*blend; } technique blend { pass p0 { VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_1_4 PS(); } }
didn't test it, so there should be many errors skin2 is your texture that darken the first skin i don't know why you don't wan't an ffe, doesn't makes sense for me 
|
|
|
Re: Blending textures
[Re: sheefo]
#90455
09/20/06 16:09
09/20/06 16:09
|
Joined: Sep 2002
Posts: 1,604 Deutschland
ChrisB
Serious User
|
Serious User
Joined: Sep 2002
Posts: 1,604
Deutschland
|
Ok, when you don't post what exactly you want nobody can help you.  so here is the code: Code:
// Declare pre-defined matrices to be included float4x4 matWorldViewProj; float4x4 matWorldView; float4x4 matWorldInv; // Declare additional vectors for optional features float4 vecSunDir; float4 vecFog;
float4 vecSkill41; // Declare the terrain's textures texture entSkin1; texture entSkin2; texture entSkin3; texture entSkin4; texture mtlSkin1; texture mtlSkin2; ////////////////////////////// // Base-Texture (BLACK) ////////////////////////////// sampler sTex1 = sampler_state { Texture = <entSkin1>; MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; ////////////////////////////// // Red-Texture (RED) ////////////////////////////// sampler sTex2 = sampler_state { Texture = <entSkin2>; MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; ////////////////////////////// // Blue-Texture (BLUE) ////////////////////////////// sampler sTex3 = sampler_state { Texture = <entSkin3>; MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; ////////////////////////////// // Green-Texture (GREEN) ////////////////////////////// sampler sTex4 = sampler_state { Texture = <entSkin4>; MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; ////////////////////////////// // Detail Map ////////////////////////////// sampler sTex5 = sampler_state { Texture = <mtlSkin1>; MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; }; ////////////////////////////// // Shadow Map ////////////////////////////// sampler sTex6 = sampler_state { Texture = <mtlSkin2>; MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; }; //////////////////////////////////////////////////////////// // Vertex Shader //////////////////////////////////////////////////////////// ////////////////////////////// // Input ////////////////////////////// struct VS_OUTPUT { float4 position : POSITION; float4 sunlight : COLOR0; float fog : FOG; float2 Tex1 : TEXCOORD0; float2 Tex2 : TEXCOORD1; float2 Tex3 : TEXCOORD2; float2 Tex4 : TEXCOORD3; float2 Tex5 : TEXCOORD4; }; ////////////////////////////// // Output ////////////////////////////// VS_OUTPUT VS(float4 position : POSITION, float3 inNormal : NORMAL, float2 inTexCoord0 : TEXCOORD0) { VS_OUTPUT Out; // Transform Vector Position to Screen Co-ordinates Out.position = mul(position, matWorldViewProj); // Calculate sunlighting float3 sunlighting = normalize(mul(inNormal, matWorldInv)); Out.sunlight = dot(sunlighting, -vecSunDir); // Calculate Fogging float3 fogging = mul(position, matWorldView); fogging = saturate((vecFog.y - fogging.z) * vecFog.z); Out.fog = fogging; // Scale Texture Co-ordinates Out.Tex1 = inTexCoord0.xy * vecSkill41.x; Out.Tex2 = inTexCoord0.xy * vecSkill41.x; Out.Tex3 = inTexCoord0.xy * vecSkill41.x; Out.Tex4 = inTexCoord0.xy * vecSkill41.x; Out.Tex5 = inTexCoord0.xy; return(Out); } //////////////////////////////////////////////////////////// // Pixel Shader //////////////////////////////////////////////////////////// ////////////////////////////// // Output ////////////////////////////// float4 PS(VS_OUTPUT In) : COLOR { float4 BaseColour = tex2D(sTex1, In.Tex1); float4 RedColour = tex2D(sTex2, In.Tex2); float4 GreenColour = tex2D(sTex3, In.Tex3); float4 BlueColour = tex2D(sTex4, In.Tex4); float4 MaskColour = tex2D(sTex5, In.Tex5); float4 ShadowColour = tex2D(sTex6, In.Tex5);
float4 BaseRed = lerp(BaseColour, RedColour, MaskColour.r); float4 BaseGreen = lerp(BaseRed, GreenColour, MaskColour.g); float4 FinalColour = lerp(BaseGreen, BlueColour, MaskColour.b); FinalColour = (FinalColour + (FinalColour * In.sunlight)) / 2; // Brightness FinalColour*=ShadowColour;
FinalColour.a = 1.0f; // prevent transparency return(FinalColour); } //////////////////////////////////////////////////////////// // The 'terrainshader' initialization //////////////////////////////////////////////////////////// technique terrainshader { pass p0 { VertexShader = compile vs_2_0 VS(); PixelShader = compile ps_2_0 PS(); } }
|
|
|
|