Blend 8 textures pixel shader
I was asked to post the source. It's set up to work within fx composer:
#define LIGHT_COORDS "World" //----------------- // un-tweaks //----------------- matrix WorldVP:WorldViewProjection; matrix World:World; //----------------- // tweaks //----------------- float3 LightPosition : POSITION < string Object = "PointLight0"; string UIName = "Lamp 0 Position"; string Space = (LIGHT_COORDS); > = {150.0f, 150.0f, 0.0f}; float4 LightColor : COLOR < string UIName = "Lamp 0"; string Object = "Pointlight0"; string UIWidget = "Color"; > = {1.0f, 1.0f, 1.0f, 1.0f}; float LightRange < string UIWidget = "slider"; float UIMin = 10.0; float UIMax = 1000.0; float UIStep = 5.0; string UIName = "LightRange"; > = 250.0f; float4 Ambient < string UIName = "Ambient"; string UIWidget = "Color"; > = {0.1f, 0.1f, 0.1f, 1.0f}; float BlendTexUScale< string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 10.0; float UIStep = 0.01; string UIName = "BlendTexUScale"; > = 1.0f; float BlendTexVScale< string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 10.0; float UIStep = 0.01; string UIName = "BlendTexVScale"; > = 1.0f; float waver< string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 10.0; float UIStep = 0.01; > = 1.0f; //----------------- // Textures //----------------- texture tex1n; sampler2D tex1 = sampler_state{texture = ;}; texture tex2n; sampler2D tex2 = sampler_state{texture = ;}; texture tex3n; sampler2D tex3 = sampler_state{texture = ;}; texture tex4n; sampler2D tex4 = sampler_state{texture = ;}; texture tex5n; sampler2D tex5 = sampler_state{texture = ;}; texture tex6n; sampler2D tex6 = sampler_state{texture = ;}; texture tex7n; sampler2D tex7 = sampler_state{texture = ;}; texture tex8n; sampler2D tex8 = sampler_state{texture = ;}; texture texBlendn; sampler2D texBlend = sampler_state{texture = ;}; texture texBlend2n; sampler2D texBlend2 = sampler_state{texture = ;}; //----------------- // structs //----------------- struct input { float4 Pos:POSITION; float2 UV:TEXCOORD; float3 Normal : NORMAL; }; struct output { float4 OPos:POSITION; float2 Tex:TEXCOORD0; float3 Attenuation:TEXCOORD1; float Diffuse:TEXCOORD2; }; //----------------- // vertex shader //----------------- output VS(input IN) { output OUT; OUT.OPos=mul(IN.Pos,WorldVP); OUT.Tex=IN.UV; float3 Wnor=mul(IN.Normal,World); Wnor=normalize(Wnor); float3 WPos=mul(IN.Pos,World); float3 LightPos=LightPosition-WPos; OUT.Attenuation=-LightPos/LightRange; OUT.Diffuse=saturate(0.02f+mul(Wnor,LightPos)*0.02f); return OUT; } //----------------- // pixel shader //----------------- float4 PS(output IN) : COLOR { IN.Tex += float2(IN.Tex.x,sin(IN.Tex.x*waver)); float4 Texture1=tex2D(tex1,IN.Tex); float4 Texture2=tex2D(tex2,IN.Tex); float4 Texture3=tex2D(tex3,IN.Tex); float4 Texture4=tex2D(tex4,IN.Tex); float4 Texture5=tex2D(tex5,IN.Tex); float4 Texture6=tex2D(tex6,IN.Tex); float4 Texture7=tex2D(tex7,IN.Tex); float4 Texture8=tex2D(tex8,IN.Tex); float4 tBlend=tex2D(texBlend,IN.Tex*float2(BlendTexUScale,BlendTexVScale)); float4 tBlend2=tex2D(texBlend2,IN.Tex*float2(BlendTexUScale,BlendTexVScale)); float4 DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation)); float4 Light=DiffuseLight*LightColor*IN.Diffuse; return (tBlend.x*Texture1 + tBlend.y*Texture2 + tBlend.z*Texture3 + tBlend.w*Texture4 + tBlend2.x*Texture5 + tBlend2.y*Texture6 + tBlend2.z*Texture7 + tBlend2.w*Texture8 )*(Light+Ambient); } //----------------- // techniques //----------------- technique CubicLighting { pass p1 { vertexShader = compile vs_1_0 VS(); pixelShader = compile ps_2_0 PS(); } }
Comments
Post a Comment