heres the shader if anyone wants to play around with it, would be great if someone could get it to work
shared texture tNormalizer;
shared texture tBump;
shared texture tDiffuse;
shared texture tAtenuacionXY;
shared texture tAtenuacionZ;
shared float4 vPosLight;
shared float4 vPosViewer;
shared float4 vScaleLight;
shared float4 vColorLight;
shared float4x4 mViewProjection : WORLDVIEWPROJECTION;
vertexshader transformAttenuation =
asm
{
vs_1_1
//-------------------------------
//Constant registers
//-------------------------------
// c0-c3 - world*view*proj
// c8 - light position(In object space)
// c9 - 1 / lightRange
def c6, 0.5, 0, 0, 0 // helper constant
//------------------------------
// Used input registers
//------------------------------
dcl_position v0
//------------------------------
// output position
//------------------------------
//
m4x4 oPos, v0, c0
//------------------------------
// compute texture coordinates for attenuation
//------------------------------
//
add r7.xyz, -v0, c8 // light position - vertex pos
mul r2.xyz, r7, c9 // (light position - vertex pos) / lightRange
mad r4.xyz, r2, c6.x, c6.x // map to 0 to 1 range
mov oT0.xy, r4 // t0 = texture coordinates for attenuation texture 1
mov oT1.x, r4.z // t1 = texture coordinates for attenuation texture 2
mov oT1.y, c6.w
};
pixelshader shaderAttenuation =
asm
{
ps_1_1
//------------------------------
// load textures
//------------------------------
//
tex t0 // load attenuation texture 1
tex t1 // load attenuation texture 2
//------------------------------
// compute attenuation per pixel
//------------------------------
//
mul r0,t0,t1 // output = exp(-2*(x*x+y*y))*exp(-2*z*z)
};
vertexshader transformSpecularDiffuse =
asm
{
vs_1_1
//-------------------------------
//Constant registers
//-------------------------------
// c0-c3 - world*view*proj
// c8 - light position(In object space)
// c10 - vPosViewer(In object space)
def c6, -1, 0, 0, 0 // helper constant
def c7, 2, -1, 0, 0 // helper constant
//------------------------------
// Input registers
//------------------------------
dcl_position v0
dcl_tangent v1
dcl_binormal v2
dcl_normal v3
dcl_texcoord v4
//------------------------------
// output position
//------------------------------
//
m4x4 oPos, v0, c0
//------------------------------
// Compute the tangent space matrix to transform from object space to tangent space
//------------------------------
//
mad r7.xyz, c7.x, v1, c7.y //bias vector tangent to (-1,1)
mad r8.xyz, c7.x, v2, c7.y //bias vector binormal to (-1,1)
mad r9.xyz, c7.x, v3, c7.y //bias vector normal to (-1,1)
//------------------------------
// Compute L vector in tangent space
//------------------------------
//
add r10, -v0, c8 // light position - vPos
dp3 r7.w, r10, r10 // Normalize (lightpostion-vPos)
rsq r7.w, r7.w
mul r11.xyz, r10, r7.w
m3x3 oT2.xyz, r11, r7 // t2 = L vector in tangent space
//------------------------------
// Compute H vector in tangent space
//------------------------------
//
add r4, -v0, c4 // V vector
add r6, r10, r4 // L + V
dp3 r6.w, r6, r6 // Normalize (L+V)
rsq r6.w, r6.w
mul r5.xyz, r6, r6.w
m3x3 oT3.xyz, r5, r7 // t3 = H vector in tangent space
//------------------------------
// output texture coordinates
//------------------------------
//
mov oT0.xy, v4 // t0 = texture coordinate
mov oT1.xy, v4 // t1 = texture coordinate
};
pixelshader shaderSpecularDiffuse =
asm
{
ps_1_1
//-------------------------------
//Constant registers
//-------------------------------
// c1 - lightColor
def c0, 4.0f, 1.0f, 0.0f, -0.75f // Helper constant
//------------------------------
// Load textures
//------------------------------
//
tex t0 // Normal
tex t1 // diffuse
tex t2 // L
tex t3 // H
//------------------------------
// compute output color
//------------------------------
//
dp3_sat r1.xyzw,t3_bx2,t0_bx2 // max(0,dot(N,H))
dp3_sat r0.rgb,t2_bx2,t0_bx2 // max(0,dot(N,L))
+mad_x4_sat r1.w,r1.w,r1.w,c0.w // specular = saturate(4*(dot(N,H)^2-0.75))
mul r1.w,r1.w,r1.w // specular = specular*specular
mul r0.rgb,r0,t1 // diffuse = dot(N,L)*diffuse texture map
+mul_x2_sat r1.w,r1.w,t0.w // specular = saturate(specular*2*gloss map)
add_sat r0.rgb,r0,r1.w // specular + diffuse
mul r0.rgb,r0,c1 // (specular+diffuse)*lightColor
+mov r0.a,t1.a // alpha output = alpha diffuse map for transparency.
};
technique pixelShader1_1_asm
{
pass P0
{
ALPHABLENDENABLE = False;
ColorWriteEnable = 0x8;
Texture[0] = <tAtenuacionXY>;
Texture[1] = <tAtenuacionZ>;
AddressU[0] = Clamp;
AddressV[0] = Clamp;
AddressU[1] = Clamp;
AddressV[1] = Clamp;
VertexShaderConstant[0] = <mViewProjection>;
VertexShaderConstant1[8] = <vPosLight>;
VertexShaderConstant1[9] = <vScaleLight>;
Vertexshader = <transformAttenuation>;
PixelShader = <shaderAttenuation>;
}
pass P0
{
ALPHABLENDENABLE = True;
SrcBlend = DestAlpha;
DestBlend = One;
ColorWriteEnable = 0xF;
AddressU[0] = Wrap;
AddressV[0] = Wrap;
AddressU[1] = Wrap;
AddressV[1] = Wrap;
AddressU[2] = Clamp;
AddressV[2] = Clamp;
AddressU[3] = Clamp;
AddressV[3] = Clamp;
Texture[0] = <tBump>;
Texture[1] = <tDiffuse>;
Texture[2] = <tNormalizer>;
Texture[3] = <tNormalizer>;
VertexShaderConstant[0] = <mViewProjection>;
VertexShaderConstant1[8] = <vPosLight>;
VertexShaderConstant1[10] = <vPosViewer>;
PixelShaderConstant1[1] = <vColorLight>;
Vertexshader = <transformSpecularDiffuse>;
PixelShader = <shaderSpecularDiffuse>;
}
}
vertexshader transform_pixelshader1_4 =
asm
{
vs_1_1
//-------------------------------
//Constant registers
//-------------------------------
// c0-c3 - world*view*proj
// c8 - light position(In object space)
// c9 - 1 / lightRange
// c10 - vPosViewer(In object space)
def c6, 0.5, 0, 0, 0 // Helper constant
def c7, 2, -1, 0, 0 // Helper constant
//------------------------------
// Input registers
//------------------------------
dcl_position v0
dcl_tangent v1
dcl_binormal v2
dcl_normal v3
dcl_texcoord v4
//------------------------------
// output position
//------------------------------
//
m4x4 oPos, v0, c0
//------------------------------
// Compute the tangent space matrix to transform from object space to tangent space
//------------------------------
//
mad r7.xyz, c7.x, v1, c7.y //bias vector tangent to (-1,1)
mad r8.xyz, c7.x, v2, c7.y //bias vector binormal to (-1,1)
mad r9.xyz, c7.x, v3, c7.y //bias vector normal to (-1,1)
//------------------------------
// Compute L vector in tangent space
//------------------------------
//
add r10, -v0, c8 // light position - vPos
dp3 r7.w, r10, r10 // Normalize (lightpostion-vPos)
rsq r7.w, r7.w
mul r11.xyz, r10, r7.w
m3x3 oT1.xyz, r11, r7 // t1 = L vector in tangent space
//------------------------------
// Compute H vector in tangent space
//------------------------------
//
add r4, -v0, c4 // V vector
add r6, r10, r4 // L + V
dp3 r6.w, r6, r6 // Normalize (L+V)
rsq r6.w, r6.w
mul r5.xyz, r6, r6.w
m3x3 oT2.xyz, r5, r7 // t2 = H vector in tangent space
//------------------------------
// output texture coordinates
//------------------------------
//
mov oT0.xy, v4 // t0 = texture coordinate
//------------------------------
// compute texture coordinates for attenuation
//------------------------------
//
mul r2.xyz, r10, c9 // (light position - vertex pos) / lightRange
mad r4.xyz, r2, c6.x, c6.x // map to 0 to 1 range
mov oT3.xy, r4 // t3 = texture coordinates for attenuation texture 1
mov oT4.x, r4.z // t4 = texture coordinates for attenuation texture 2
mov oT4.y, c6.w
};
pixelshader shader_pixelshader1_4 =
asm
{
ps_1_4
//-------------------------------
//Constant registers
//-------------------------------
// c1 - lightColor
def c0, 4.0f, 1.0f, 0.0f, -0.75f // helper constant
//------------------------------
// Load textures
//------------------------------
//
texld r0,t0 // Diffuse
texld r1,t0 // Normal
texld r2,t1 // L
texld r3,t2 // H
texld r4,t3 // attenuation texture 1
texld r5,t4 // attenuation texture 2
//------------------------------
// compute output color
//------------------------------
//
dp3_sat r2.w,r1_bx2,r3_bx2 // max(0,dot(N,H))
dp3_sat r1.rgb,r2_bx2,r1_bx2 // max(0,dot(N,L))
+mad_x4_sat r2.w,r2.w,r2.w,c0.w // specular = saturate(4*(dot(N,H)^2-0.75))
mul_sat r5.rgb,r4,r5 // attenuation = attenuation(x,y)*attenuation(z)
+mul r2.w,r2.w,r2.w // specular = specular*specular
mul_sat r0.rgb,r0,r1 // diffuse = max(0,dot(N,L))*diffuse color
+mul_x2_sat r2.w,r2.w,r1.w // specular = saturate(specular*gloss*2)
add_sat r0.rgb,r0,r2.w // color = saturate(diffuse + specular)
mul r0.rgb,r0,c1 // color = color*lightColor
mul r0.rgb,r0,r5 // color = color*attenuation
};
technique pixelShader1_4_asm
{
pass P0
{
ALPHABLENDENABLE = True;
SrcBlend = ONE;
DestBlend = ONE;
ColorWriteEnable = 0xf;
Texture[0] = <tDiffuse>;
Texture[1] = <tBump>;
Texture[2] = <tNormalizer>;
Texture[3] = <tNormalizer>;
Texture[4] = <tAtenuacionXY>;
Texture[5] = <tAtenuacionZ>;
AddressU[0] = Wrap;
AddressV[0] = Wrap;
AddressU[1] = Wrap;
AddressV[1] = Wrap;
AddressU[2] = Clamp;
AddressV[2] = Clamp;
AddressU[3] = Clamp;
AddressV[3] = Clamp;
AddressU[4] = Clamp;
AddressV[4] = Clamp;
AddressU[5] = Clamp;
AddressV[5] = Clamp;
VertexShaderConstant[0] = <mViewProjection>;
VertexShaderConstant1[8] = <vPosLight>;
VertexShaderConstant1[9] = <vScaleLight>;
VertexShaderConstant1[10] = <vPosViewer>;
PixelShaderConstant1[1] = <vColorLight>;
Vertexshader = <transform_pixelshader1_4>;
PixelShader = <shader_pixelshader1_4>;
}
}
pixelshader shader_pixelshader2_0 =
asm
{
ps_2_0
//-------------------------------
//Constant registers
//-------------------------------
// c1 - lightColor
def c31, 2.0f, 1.0f, 0.0f, 4.0f // helper constant
def c30, 2.0f, 1.0f, 0.0f, -0.75f // helper constant
//------------------------------
// Input registers
//------------------------------
//
dcl t0.xy // texture coordinates
dcl t1.xyz // light vector tangent
dcl t2.xyz // eye vector tangent
dcl t3.xy // texture coords attenuation xy
dcl t4.xy // texture coords attenuation z
//------------------------------
// Input texture samplers
//------------------------------
dcl_2d s0 // diffuse
dcl_2d s1 // normal
dcl_2d s2 // attenuation xy
dcl_2d s3 // attenuation z
//------------------------------
// load normal
//------------------------------
//
texld r1, t0, s1 // load normal
mad r0.rgb, r1, c31.r, -c31.g // bias normal to range -1,1
//------------------------------
// compute diffuse contribution
//------------------------------
//
nrm r1.rgb,t1 // normalize L vector
dp3_sat r1.rgb,r1,r0 // dot(N,L)
texld r4,t0,s0 // load diffuse color
mul r1.rgb,r1,r4 // diffuse = dot(N,L)*matDiffuse
//------------------------------
// compute specular contribution
//------------------------------
//
nrm r2.rgb,t2 // Normalize half vector
dp3_sat r2.w,r2,r0 // dot(N,H)
mad_sat r2.w,r2.w,r2.w,c30.w // specular = saturate(dot(N,H)^2-0.75)
mul_sat r2.w,r2.w,c31.w // specular = specular*4
mul r2.w,r2.w,r2.w // specular = specular*specular
mul r2.w,r2.w, r1.w // specular = specular * gloss
add_sat r2.w,r2.w,r2.w // speuclar = specular*2
//------------------------------
// compute attenuation
//------------------------------
//
texld r6,t3,s2 // load attenuation texture 1
texld r7,t4,s3 // load attenuation texture 2
mul r6.rgb,r6,r7 // attenuation = attenuation(x,y)*attenuation(z)
//------------------------------
// compute final color
//------------------------------
//
add_sat r4.rgb, r1,r2.w // color = diffuse + specular
mul r4.rgb,r4,c1 // color = color*lightColor
mul r4.rgb,r4,r6 // color = color*attenuation
mov oC0, r4 //color output
};
technique pixelShader2_0_asm
{
pass P0
{
ALPHABLENDENABLE = True;
SrcBlend = ONE;
DestBlend = ONE;
ColorWriteEnable = 0xf;
Texture[0] = <tDiffuse>;
Texture[1] = <tBump>;
Texture[2] = <tAtenuacionXY>;
Texture[3] = <tAtenuacionZ>;
AddressU[0] = Wrap;
AddressV[0] = Wrap;
AddressU[1] = Wrap;
AddressV[1] = Wrap;
AddressU[2] = Clamp;
AddressV[2] = Clamp;
AddressU[3] = Clamp;
AddressV[3] = Clamp;
VertexShaderConstant[0] = <mViewProjection>;
VertexShaderConstant1[8] = <vPosLight>;
VertexShaderConstant1[9] = <vScaleLight>;
VertexShaderConstant1[10] = <vPosViewer>;
PixelShaderConstant1[1] = <vColorLight>;
Vertexshader = <transform_pixelshader1_4>;
PixelShader = <shader_pixelshader2_0>;
}
}
Once you start down the Dark Path, forever will it dominate your destiny...