Original Post
Multi-texturing can be implemented via blending using a multi-pass technique.
The idea is as follows: We draw the geometry once on the first pass with a base texture;
we then draw the geometry again with alpha blending enabled and a second texture,
where the alpha channel and blend operations specify how the secondary texture should be blended with the geometry drawn in the first pass;
we next draw the geometry again with alpha blending enabled and a third texture, where the alpha channel and blend operations specify how the third texture should be blended with the previously drawn geometry. We can keep doing this repeatedly, each pass layering on more and more details. The benefit of this technique is that you are not limited by any hardware restrictions that might limit how many textures you can sample simultaneously in a single pass. The downside of this technique is that it requires you to render the same geometry repeatedly
//=============================================================================
// pointlight.fx by Frank Luna (C) 2004 All Rights Reserved.
//
// Does ambient, diffuse, and specular lighting with a point light source.
//=============================================================================
uniform extern float4x4 gWorld;
uniform extern float4x4 gWorldInvTrans;
uniform extern float4x4 gWVP;
uniform extern float3 gEyePosW;
uniform extern float4 gAmbientMtrl;
uniform extern float4 gDiffuseMtrl;
uniform extern float4 gSpecMtrl;
uniform extern float gSpecPower;
uniform extern float4 gAmbientLight;
uniform extern float4 gDiffuseLight;
uniform extern float4 gSpecLight;
uniform extern float3 gLightVecW;
uniform extern texture gTex;
//uniform extern texture gTex1;
//uniform extern texture gTex2;
//uniform extern texture gTexBlend;
sampler TexS = sampler_state
{
Texture = <gTex>;
MinFilter = Anisotropic;
MagFilter = LINEAR;
MipFilter = LINEAR;
MaxAnisotropy = 8;
AddressU = wrap;
AddressV = wrap;
};
struct OutputVS
{
float4 posH : POSITION0;
float4 diffuse : COLOR0;
float4 spec : COLOR1;
float2 tiledTexC : TEXCOORD0;
};
OutputVS DirLightTexVS(float3 posL : POSITION0, float3 normalL : NORMAL0, float2 tex0 : TEXCOORD0)
{
// Zero out our output.
OutputVS outVS = (OutputVS)0;
// Transform normal to world space.
float3 normalW = mul(float4(normalL, 0.0f), gWorldInvTrans).xyz;
normalW = normalize(normalW);
// Transform vertex position to world space.
float3 posW = mul(float4(posL, 1.0f), gWorld).xyz;
// Ambient Light Computation.
float3 ambient = (gAmbientMtrl*gAmbientLight).rgb;
// Diffuse Light Computation.
float s = max(dot(normalW, gLightVecW), 0.0f);
float3 diffuse = s*(gDiffuseMtrl*gDiffuseLight).rgb;
// Specular Light Computation.
float3 toEyeW = normalize(gEyePosW - posW);
float3 reflectW = reflect(-gLightVecW, normalW);
float t = pow(max(dot(reflectW, toEyeW), 0.0f), gSpecPower);
float3 spec = t*(gSpecMtrl*gSpecLight).rgb;
outVS.diffuse.rgb = diffuse + ambient;
outVS.diffuse.a = gDiffuseMtrl.a;
outVS.spec = float4(spec,0.0f);
// Transform to homogeneous clip space.
outVS.posH = mul(float4(posL, 1.0f), gWVP);
outVS.tiledTexC = tex0*16.0f;
// Done--return the output.
return outVS;
}
float4 DirLightTexPS(float4 diffuse : color0, float4 spec : color1, float2 tileTexC : texcoord0) : COLOR
{
float3 c0 = tex2D(TexS, tileTexC).rgb;
return float4(c0 + spec.rgb, diffuse.a);
}
technique DirLightTexTech
{
pass P0
{
// Specify the vertex and pixel shader associated with this pass.
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
//fillmode = wireframe;
}
pass P1
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaBlendEnable = true;
SrcBlend = zero;
DestBlend = SrcColor;
BlendOp = Add;
}
pass P2
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaBlendEnable = true;
SrcBlend = zero;
DestBlend = SrcColor;
BlendOp = Add;
}
/*pass P3
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaTestEnable = true;
AlphaFunc = GreaterEqual;
AlphaRef = 220;
}*/
}
[color=#ff0000]How to realize this problem, I now have 3 texture, I added alpha channel for them, here is my HLSL code, but no, hope this helps
we then draw the geometry again with alpha blending enabled and a second texture,
where the alpha channel and blend operations specify how the secondary texture should be blended with the geometry drawn in the first pass;
we next draw the geometry again with alpha blending enabled and a third texture, where the alpha channel and blend operations specify how the third texture should be blended with the previously drawn geometry. We can keep doing this repeatedly, each pass layering on more and more details. The benefit of this technique is that you are not limited by any hardware restrictions that might limit how many textures you can sample simultaneously in a single pass. The downside of this technique is that it requires you to render the same geometry repeatedly
//=============================================================================
// pointlight.fx by Frank Luna (C) 2004 All Rights Reserved.
//
// Does ambient, diffuse, and specular lighting with a point light source.
//=============================================================================
uniform extern float4x4 gWorld;
uniform extern float4x4 gWorldInvTrans;
uniform extern float4x4 gWVP;
uniform extern float3 gEyePosW;
uniform extern float4 gAmbientMtrl;
uniform extern float4 gDiffuseMtrl;
uniform extern float4 gSpecMtrl;
uniform extern float gSpecPower;
uniform extern float4 gAmbientLight;
uniform extern float4 gDiffuseLight;
uniform extern float4 gSpecLight;
uniform extern float3 gLightVecW;
uniform extern texture gTex;
//uniform extern texture gTex1;
//uniform extern texture gTex2;
//uniform extern texture gTexBlend;
sampler TexS = sampler_state
{
Texture = <gTex>;
MinFilter = Anisotropic;
MagFilter = LINEAR;
MipFilter = LINEAR;
MaxAnisotropy = 8;
AddressU = wrap;
AddressV = wrap;
};
struct OutputVS
{
float4 posH : POSITION0;
float4 diffuse : COLOR0;
float4 spec : COLOR1;
float2 tiledTexC : TEXCOORD0;
};
OutputVS DirLightTexVS(float3 posL : POSITION0, float3 normalL : NORMAL0, float2 tex0 : TEXCOORD0)
{
// Zero out our output.
OutputVS outVS = (OutputVS)0;
// Transform normal to world space.
float3 normalW = mul(float4(normalL, 0.0f), gWorldInvTrans).xyz;
normalW = normalize(normalW);
// Transform vertex position to world space.
float3 posW = mul(float4(posL, 1.0f), gWorld).xyz;
// Ambient Light Computation.
float3 ambient = (gAmbientMtrl*gAmbientLight).rgb;
// Diffuse Light Computation.
float s = max(dot(normalW, gLightVecW), 0.0f);
float3 diffuse = s*(gDiffuseMtrl*gDiffuseLight).rgb;
// Specular Light Computation.
float3 toEyeW = normalize(gEyePosW - posW);
float3 reflectW = reflect(-gLightVecW, normalW);
float t = pow(max(dot(reflectW, toEyeW), 0.0f), gSpecPower);
float3 spec = t*(gSpecMtrl*gSpecLight).rgb;
outVS.diffuse.rgb = diffuse + ambient;
outVS.diffuse.a = gDiffuseMtrl.a;
outVS.spec = float4(spec,0.0f);
// Transform to homogeneous clip space.
outVS.posH = mul(float4(posL, 1.0f), gWVP);
outVS.tiledTexC = tex0*16.0f;
// Done--return the output.
return outVS;
}
float4 DirLightTexPS(float4 diffuse : color0, float4 spec : color1, float2 tileTexC : texcoord0) : COLOR
{
float3 c0 = tex2D(TexS, tileTexC).rgb;
return float4(c0 + spec.rgb, diffuse.a);
}
technique DirLightTexTech
{
pass P0
{
// Specify the vertex and pixel shader associated with this pass.
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
//fillmode = wireframe;
}
pass P1
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaBlendEnable = true;
SrcBlend = zero;
DestBlend = SrcColor;
BlendOp = Add;
}
pass P2
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaBlendEnable = true;
SrcBlend = zero;
DestBlend = SrcColor;
BlendOp = Add;
}
/*pass P3
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaTestEnable = true;
AlphaFunc = GreaterEqual;
AlphaRef = 220;
}*/
}
[color=#ff0000]How to realize this problem, I now have 3 texture, I added alpha channel for them, here is my HLSL code, but no, hope this helps
we next draw the geometry again with alpha blending enabled and a third texture, where the alpha channel and blend operations specify how the third texture should be blended with the previously drawn geometry. We can keep doing this repeatedly, each pass layering on more and more details. The benefit of this technique is that you are not limited by any hardware restrictions that might limit how many textures you can sample simultaneously in a single pass. The downside of this technique is that it requires you to render the same geometry repeatedly
//=============================================================================
// pointlight.fx by Frank Luna (C) 2004 All Rights Reserved.
//
// Does ambient, diffuse, and specular lighting with a point light source.
//=============================================================================
uniform extern float4x4 gWorld;
uniform extern float4x4 gWorldInvTrans;
uniform extern float4x4 gWVP;
uniform extern float3 gEyePosW;
uniform extern float4 gAmbientMtrl;
uniform extern float4 gDiffuseMtrl;
uniform extern float4 gSpecMtrl;
uniform extern float gSpecPower;
uniform extern float4 gAmbientLight;
uniform extern float4 gDiffuseLight;
uniform extern float4 gSpecLight;
uniform extern float3 gLightVecW;
uniform extern texture gTex;
//uniform extern texture gTex1;
//uniform extern texture gTex2;
//uniform extern texture gTexBlend;
sampler TexS = sampler_state
{
Texture = <gTex>;
MinFilter = Anisotropic;
MagFilter = LINEAR;
MipFilter = LINEAR;
MaxAnisotropy = 8;
AddressU = wrap;
AddressV = wrap;
};
struct OutputVS
{
float4 posH : POSITION0;
float4 diffuse : COLOR0;
float4 spec : COLOR1;
float2 tiledTexC : TEXCOORD0;
};
OutputVS DirLightTexVS(float3 posL : POSITION0, float3 normalL : NORMAL0, float2 tex0 : TEXCOORD0)
{
// Zero out our output.
OutputVS outVS = (OutputVS)0;
// Transform normal to world space.
float3 normalW = mul(float4(normalL, 0.0f), gWorldInvTrans).xyz;
normalW = normalize(normalW);
// Transform vertex position to world space.
float3 posW = mul(float4(posL, 1.0f), gWorld).xyz;
// Ambient Light Computation.
float3 ambient = (gAmbientMtrl*gAmbientLight).rgb;
// Diffuse Light Computation.
float s = max(dot(normalW, gLightVecW), 0.0f);
float3 diffuse = s*(gDiffuseMtrl*gDiffuseLight).rgb;
// Specular Light Computation.
float3 toEyeW = normalize(gEyePosW - posW);
float3 reflectW = reflect(-gLightVecW, normalW);
float t = pow(max(dot(reflectW, toEyeW), 0.0f), gSpecPower);
float3 spec = t*(gSpecMtrl*gSpecLight).rgb;
outVS.diffuse.rgb = diffuse + ambient;
outVS.diffuse.a = gDiffuseMtrl.a;
outVS.spec = float4(spec,0.0f);
// Transform to homogeneous clip space.
outVS.posH = mul(float4(posL, 1.0f), gWVP);
outVS.tiledTexC = tex0*16.0f;
// Done--return the output.
return outVS;
}
float4 DirLightTexPS(float4 diffuse : color0, float4 spec : color1, float2 tileTexC : texcoord0) : COLOR
{
float3 c0 = tex2D(TexS, tileTexC).rgb;
return float4(c0 + spec.rgb, diffuse.a);
}
technique DirLightTexTech
{
pass P0
{
// Specify the vertex and pixel shader associated with this pass.
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
//fillmode = wireframe;
}
pass P1
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaBlendEnable = true;
SrcBlend = zero;
DestBlend = SrcColor;
BlendOp = Add;
}
pass P2
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaBlendEnable = true;
SrcBlend = zero;
DestBlend = SrcColor;
BlendOp = Add;
}
/*pass P3
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaTestEnable = true;
AlphaFunc = GreaterEqual;
AlphaRef = 220;
}*/
}
[color=#ff0000]How to realize this problem, I now have 3 texture, I added alpha channel for them, here is my HLSL code, but no, hope this helps
//=============================================================================
// pointlight.fx by Frank Luna (C) 2004 All Rights Reserved.
//
// Does ambient, diffuse, and specular lighting with a point light source.
//=============================================================================
uniform extern float4x4 gWorld;
uniform extern float4x4 gWorldInvTrans;
uniform extern float4x4 gWVP;
uniform extern float3 gEyePosW;
uniform extern float4 gAmbientMtrl;
uniform extern float4 gDiffuseMtrl;
uniform extern float4 gSpecMtrl;
uniform extern float gSpecPower;
uniform extern float4 gAmbientLight;
uniform extern float4 gDiffuseLight;
uniform extern float4 gSpecLight;
uniform extern float3 gLightVecW;
uniform extern texture gTex;
//uniform extern texture gTex1;
//uniform extern texture gTex2;
//uniform extern texture gTexBlend;
sampler TexS = sampler_state
{
Texture = <gTex>;
MinFilter = Anisotropic;
MagFilter = LINEAR;
MipFilter = LINEAR;
MaxAnisotropy = 8;
AddressU = wrap;
AddressV = wrap;
};
struct OutputVS
{
float4 posH : POSITION0;
float4 diffuse : COLOR0;
float4 spec : COLOR1;
float2 tiledTexC : TEXCOORD0;
};
OutputVS DirLightTexVS(float3 posL : POSITION0, float3 normalL : NORMAL0, float2 tex0 : TEXCOORD0)
{
// Zero out our output.
OutputVS outVS = (OutputVS)0;
// Transform normal to world space.
float3 normalW = mul(float4(normalL, 0.0f), gWorldInvTrans).xyz;
normalW = normalize(normalW);
// Transform vertex position to world space.
float3 posW = mul(float4(posL, 1.0f), gWorld).xyz;
// Ambient Light Computation.
float3 ambient = (gAmbientMtrl*gAmbientLight).rgb;
// Diffuse Light Computation.
float s = max(dot(normalW, gLightVecW), 0.0f);
float3 diffuse = s*(gDiffuseMtrl*gDiffuseLight).rgb;
// Specular Light Computation.
float3 toEyeW = normalize(gEyePosW - posW);
float3 reflectW = reflect(-gLightVecW, normalW);
float t = pow(max(dot(reflectW, toEyeW), 0.0f), gSpecPower);
float3 spec = t*(gSpecMtrl*gSpecLight).rgb;
outVS.diffuse.rgb = diffuse + ambient;
outVS.diffuse.a = gDiffuseMtrl.a;
outVS.spec = float4(spec,0.0f);
// Transform to homogeneous clip space.
outVS.posH = mul(float4(posL, 1.0f), gWVP);
outVS.tiledTexC = tex0*16.0f;
// Done--return the output.
return outVS;
}
float4 DirLightTexPS(float4 diffuse : color0, float4 spec : color1, float2 tileTexC : texcoord0) : COLOR
{
float3 c0 = tex2D(TexS, tileTexC).rgb;
return float4(c0 + spec.rgb, diffuse.a);
}
technique DirLightTexTech
{
pass P0
{
// Specify the vertex and pixel shader associated with this pass.
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
//fillmode = wireframe;
}
pass P1
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaBlendEnable = true;
SrcBlend = zero;
DestBlend = SrcColor;
BlendOp = Add;
}
pass P2
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaBlendEnable = true;
SrcBlend = zero;
DestBlend = SrcColor;
BlendOp = Add;
}
/*pass P3
{
vertexShader = compile vs_3_0 DirLightTexVS();
pixelShader = compile ps_3_0 DirLightTexPS();
AlphaTestEnable = true;
AlphaFunc = GreaterEqual;
AlphaRef = 220;
}*/
}