[Supply] Matt's NormalMapping shader with 3 lights

Posted By: TWO

[Supply] Matt's NormalMapping shader with 3 lights - 03/18/07 11:02

Frank_G wanted to have matt's normalmapping shader with more than 2 lights, so here is it. I added the 3rd light and an ambient parameter you can change to prevent a total black modell. I also fixed that the shader ignored the first light (because matt used vecLighPos[1] instead of vecLightPos[0] as first)

Because of the additional registers I had the change the shader version target from 2.0 to 3.0; Maybe a guru can remove some registers, then it would be possible to have even more lights.

Anyone could post this shader in the wiki.

Code:

// -------------------------------------------------------------
// Diffuse and specular shader for models
// -------------------------------------------------------------
// [18/3/06 Bloodline] - Added ambient and a 3rd light


float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLightPos[8]; //light position
float4 vecLightColor[8]; //light color
float4 vecViewPos;

// Change ambient here
float4 Ambient = { 0.6f, 0.6f, 0.6f, 1.0f };

texture entSkin1; //this is the color map
texture entSkin2; //this is the normal map

sampler sColorMap = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};


sampler sBumpMap = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};




///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//first pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT0
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light1 : TEXCOORD2;
float3 View1 : TEXCOORD3;
float3 Att1 : TEXCOORD4;

float3 Light2 : TEXCOORD5;
float3 View2 : TEXCOORD6;
float3 Att2 : TEXCOORD7;

float3 Light3 : TEXCOORD8;
float3 View3 : TEXCOORD9;
float3 Att3 : TEXCOORD10;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT0 VS_PASS0(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 )
{
VS_OUTPUT0 Out = (VS_OUTPUT0)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

Out.Tex = texcoord0.xy;

float3 PosWorld = mul(Pos, matWorld);

float LightRange = 1/vecLightPos[0].w;
float LightRange2 = 1/vecLightPos[1].w;
float LightRange3 = 1/vecLightPos[2].w;

//light 1
float3 Light1 = PosWorld - vecLightPos[0] ;
Out.Light1.xyz = mul(worldToTangentSpace, -Light1); // L

float3 Viewer1 = PosWorld - vecViewPos;
Out.View1 = mul(worldToTangentSpace, -Viewer1); // V

Out.Att1 = Light1 * LightRange; // Point light

//light 2
float3 Light2 = PosWorld - vecLightPos[1] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

float3 Viewer2 = PosWorld - vecViewPos;
Out.View2 = mul(worldToTangentSpace, -Viewer2); // V

Out.Att2 = Light2 * LightRange2; // Point light

//light 3
float3 Light3 = PosWorld - vecLightPos[2] ;
Out.Light3.xyz = mul(worldToTangentSpace, -Light3); // L

float3 Viewer3 = PosWorld - vecViewPos;
Out.View3 = mul(worldToTangentSpace, -Viewer3); // V

Out.Att3 = Light3 * LightRange3; // Point light

return Out;
}


struct PS_INPUT0
{
float2 Tex : TEXCOORD0;

float3 Light1 : TEXCOORD2;
float3 View1 : TEXCOORD3;
float3 Att1 : TEXCOORD4;

float3 Light2 : TEXCOORD5;
float3 View2 : TEXCOORD6;
float3 Att2 : TEXCOORD7;

float3 Light3 : TEXCOORD8;
float3 View3 : TEXCOORD9;
float3 Att3 : TEXCOORD10;

};

float4 PS_PASS0( PS_INPUT0 psInStruct ):COLOR


{

float4 color = tex2D(sColorMap, psInStruct.Tex); // fetch color map
float3 bumpNormal = 2 * (tex2D(sBumpMap, psInStruct.Tex) - 0.5); // fetch bump map
float4 gloss = tex2D( sBumpMap, psInStruct.Tex );

//light1
float3 LightDir1 = normalize(psInStruct.Light1);
float3 ViewDir1 = normalize(psInStruct.View1);
float4 diff1 = saturate(dot(bumpNormal, LightDir1)); // diffuse component
float shadow1 = saturate(4 * diff1);
float3 Reflect1 = normalize(2 * diff1 * bumpNormal - LightDir1); // R
float4 spec1 = pow(saturate(dot(Reflect1, ViewDir1)), 15);
float4 Attenuation1 = saturate(dot(psInStruct.Att1, psInStruct.Att1));

//light2
float3 LightDir2 = normalize(psInStruct.Light2);
float3 ViewDir2 = normalize(psInStruct.View2);
float4 diff2 = saturate(dot(bumpNormal, LightDir2)); // diffuse component
float shadow2 = saturate(4 * diff2);
float3 Reflect2 = normalize(2 * diff2 * bumpNormal - LightDir2); // R
float4 spec2 = pow(saturate(dot(Reflect2, ViewDir2)), 15);
float4 Attenuation2 = saturate(dot(psInStruct.Att2, psInStruct.Att2));

//light3
float3 LightDir3 = normalize(psInStruct.Light3);
float3 ViewDir3 = normalize(psInStruct.View3);
float4 diff3 = saturate(dot(bumpNormal, LightDir3)); // diffuse component
float shadow3 = saturate(4 * diff3);
float3 Reflect3 = normalize(2 * diff3 * bumpNormal - LightDir3); // R
float4 spec3 = pow(saturate(dot(Reflect3, ViewDir3)), 15);
float4 Attenuation3 = saturate(dot(psInStruct.Att3, psInStruct.Att3));

return (
(0.1 * color + 0.2 * Ambient) +
((shadow1 * (color * diff1 + (spec1*gloss.w)) * (1 -Attenuation1))*vecLightColor[0])+
((shadow2 * (color * diff2 + (spec2*gloss.w)) * (1 -Attenuation2))*vecLightColor[1])+
((shadow3 * (color * diff3 + (spec3*gloss.w)) * (1 -Attenuation3))*vecLightColor[2])
);
}



// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique two_pass
{
pass P0
{
alphablendenable=false;
srcblend=zero;

VertexShader = compile vs_3_0 VS_PASS0();
PixelShader = compile ps_3_0 PS_PASS0();
}



}


Posted By: Machinery_Frank

Re: [Supply] Matt's NormalMapping shader with 3 lights - 03/18/07 13:11

That is a fantastic contribution. Thank you very much. I will rate you 5 stars for that (ups, I already rated you, nevermind, you are the man of the day)
Posted By: frazzle

Re: [Supply] Matt's NormalMapping shader with 3 lights - 03/18/07 14:04

This is indeed a nice effort resulted in a great shader
Great work Bloodline Btw, shouldn't there be HLSL too in the list of your occupation ^^ ??

Cheers

Frazzle
Posted By: TWO

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/18/07 14:28

Hell no, I just modified it via trial&error and some logic thinking

I think I can convert it to 2.0, maybe even today.
Posted By: Machinery_Frank

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/18/07 14:44

Quote:

I think I can convert it to 2.0, maybe even today.




Wow, that would be fantastic!
Posted By: frazzle

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/18/07 15:48

Quote:

Hell no, I just modified it via trial&error and some logic thinking

I think I can convert it to 2.0, maybe even today.




It's still a helpfull contribution

Cheers

Frazzle
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/19/07 14:53

I've messed with this shader several times. There are many things that can be optimized.

1) The vec_light[] array needs to start with 0, not 1. But you already caught that

2) You only need one Out.View in the vertex shader. Matt used multiple wiew texcoords, but they all return the same values.

3) Your Ambience is incorrectlt implemented. Change the ambient value to a simple float (instead of float4), and multiply the color by the ambient factor. [ex: 0.1 * color + 0.2 * Ambient becomes color.rgb * Ambient

4) While I did not have success, the way the lighting is calculated, and the attenuation could be optimized to run faster (use less math)...
Posted By: Machinery_Frank

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/19/07 18:40

xXxGuitar511:

Could you please make those changes and put it into the WIKI. You can also send it to me and I will post it in the WIKI for you.

That would be very nice of you.
Posted By: TWO

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/19/07 18:56

Ok, here is my super monster shader. It's a Normal Diffuse Specular Shader which handles 6 Lights in 3 passes with shader target version 2.o. Thanks to xXxGuitar for the view trick, I made the corrections. Now the shader could use even more lights, but I think it would be to slow (and you need the beta for the new light managerment). As additional feature I made a 1.1 fallback (the shader JCL postet).

Again, I'm not really skilled with HLSL, even after studying the shaderx2 series.

Code:

//--------------------------------------------------------------
// Diffuse and specular shader
// -------------------------------------------------------------

float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLightPos[8]; //light position
float4 vecLightColor[8]; //light position
float4 vecViewPos;
float4 vecFog;

texture entSkin1; //this is the color map
texture entSkin2; //this is the normal map

sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};


sampler BumpMapSampler = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};


// -------------------------------------------------------------
// 2.0
// -------------------------------------------------------------


struct VS_OUTPUT0
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;

float3 Light1 : TEXCOORD2;
float Att1 : TEXCOORD3;

float3 Light2 : TEXCOORD4;
float Att2 : TEXCOORD5;

float Fog : FOG;
};


VS_OUTPUT0 VS_PASS0(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0 )
{
VS_OUTPUT0 Out = (VS_OUTPUT0)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

Out.Tex = texcoord0.xy;

float3 PosWorld = mul(Pos, matWorld);

float3 Viewer = PosWorld - vecViewPos;
Out.View = mul(worldToTangentSpace, - Viewer); // V

//light 1
float3 Light1 = PosWorld - vecLightPos[0] ;
Out.Light1.xyz = mul(worldToTangentSpace, -Light1); // L

Out.Att1 = distance(PosWorld,vecLightPos[0])/vecLightPos[0].w; // Point light

//light 2
float3 Light2 = PosWorld - vecLightPos[1] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

Out.Att2 = distance(PosWorld,vecLightPos[1])/vecLightPos[1].w; // Point light

float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
Out.Fog = ofog;

return Out;
}


struct PS_INPUT0
{
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;

float3 Light1 : TEXCOORD2;
float Att1 : TEXCOORD3;

float3 Light2 : TEXCOORD4;
float Att2 : TEXCOORD5;
};


float4 PS_PASS0( PS_INPUT0 psInStruct ):COLOR
{

float4 color = tex2D(ColorMapSampler, psInStruct.Tex); // fetch color map
float3 bumpNormal = 2 * (tex2D(BumpMapSampler, psInStruct.Tex) - 0.5); // fetch bump map
float4 gloss = tex2D( BumpMapSampler, psInStruct.Tex );

float3 ViewDir = normalize(psInStruct.View);

//light1
float3 LightDir1 = normalize(psInStruct.Light1);
float4 diff1 = saturate(dot(bumpNormal, LightDir1)); // diffuse component
float shadow1 = saturate(4 * diff1);
float3 Reflect1 = normalize(2 * diff1 * bumpNormal - LightDir1); // R
float4 spec1 = pow(saturate(dot(Reflect1, ViewDir)), 15);
float4 Attenuation1 = saturate(dot(psInStruct.Att1, psInStruct.Att1));

//light2
float3 LightDir2 = normalize(psInStruct.Light2);
float4 diff2 = saturate(dot(bumpNormal, LightDir2)); // diffuse component
float shadow2 = saturate(4 * diff2);
float3 Reflect2 = normalize(2 * diff2 * bumpNormal - LightDir2); // R
float4 spec2 = pow(saturate(dot(Reflect2, ViewDir)), 15);
float4 Attenuation2 = saturate(dot(psInStruct.Att2, psInStruct.Att2));

return
(
(0.3 * color) + //ambient
((shadow1 * (color * diff1 + (spec1*gloss.w)) * (1 -Attenuation1))*vecLightColor[0])+
((shadow2 * (color * diff2 + (spec2*gloss.w)) * (1 -Attenuation2))*vecLightColor[1])
);
}


struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;

float3 Light3 : TEXCOORD2;
float Att3 : TEXCOORD3;

float3 Light4 : TEXCOORD4;
float Att4 : TEXCOORD5;

float Fog : FOG;
};


VS_OUTPUT1 VS_PASS1(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0 )
{
VS_OUTPUT1 Out = (VS_OUTPUT1)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

Out.Tex = texcoord0.xy;

float3 PosWorld = mul(Pos, matWorld);

float3 Viewer = PosWorld - vecViewPos;
Out.View = mul(worldToTangentSpace, -Viewer); // V

//light 3
float3 Light3 = PosWorld - vecLightPos[2] ;
Out.Light3.xyz = mul(worldToTangentSpace, -Light3); // L

Out.Att3 = distance(PosWorld,vecLightPos[2])/vecLightPos[2].w; // Point light


//light 4
float3 Light4 = PosWorld - vecLightPos[3] ;
Out.Light4.xyz = mul(worldToTangentSpace, -Light4); // L

Out.Att4 = distance(PosWorld,vecLightPos[3])/vecLightPos[3].w; // Point light

float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
Out.Fog = ofog;

return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;

float3 Light3 : TEXCOORD2;
float Att3 : TEXCOORD3;

float3 Light4 : TEXCOORD4;
float Att4 : TEXCOORD5;
};


float4 PS_PASS1( PS_INPUT1 psInStruct ):COLOR
{

float4 color = tex2D(ColorMapSampler, psInStruct.Tex); // fetch color map
float3 bumpNormal = 2 * (tex2D(BumpMapSampler, psInStruct.Tex) - 0.5); // fetch bump map
float4 gloss = tex2D( BumpMapSampler, psInStruct.Tex );

float3 ViewDir = normalize(psInStruct.View);

//light3
float3 LightDir3 = normalize(psInStruct.Light3);
float4 diff3 = saturate(dot(bumpNormal, LightDir3)); // diffuse component
float shadow3 = saturate(4 * diff3);
float3 Reflect3 = normalize(2 * diff3 * bumpNormal - LightDir3); // R
float4 spec3 = pow(saturate(dot(Reflect3, ViewDir)), 15);
float4 Attenuation3 = saturate(dot(psInStruct.Att3, psInStruct.Att3));

//light4
float3 LightDir4 = normalize(psInStruct.Light4);
float4 diff4 = saturate(dot(bumpNormal, LightDir4)); // diffuse component
float shadow4 = saturate(4 * diff4);
float3 Reflect4 = normalize(2 * diff4 * bumpNormal - LightDir4); // R
float4 spec4 = pow(saturate(dot(Reflect4, ViewDir)), 15);
float4 Attenuation4 = saturate(dot(psInStruct.Att4, psInStruct.Att4));

return
(
((shadow3 * (color * diff3 + (spec3*gloss.w)) * (1 -Attenuation3))*vecLightColor[2])+
((shadow4 * (color * diff4 + (spec4*gloss.w)) * (1 -Attenuation4))*vecLightColor[3])

);
}



struct VS_OUTPUT2
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;

float3 Light5 : TEXCOORD2;
float Att5 : TEXCOORD3;

float3 Light6 : TEXCOORD4;
float Att6 : TEXCOORD5;

float Fog : FOG;
};


VS_OUTPUT2 VS_PASS2(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0 )
{
VS_OUTPUT2 Out = (VS_OUTPUT2)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

Out.Tex = texcoord0.xy;

float3 PosWorld = mul(Pos, matWorld);

float3 Viewer = PosWorld - vecViewPos;
Out.View = mul(worldToTangentSpace, -Viewer); // V

//light 5
float3 Light5 = PosWorld - vecLightPos[4] ;
Out.Light5.xyz = mul(worldToTangentSpace, -Light5); // L

Out.Att5 = distance(PosWorld,vecLightPos[4])/vecLightPos[4].w; // Point light

//light 6
float3 Light6 = PosWorld - vecLightPos[5] ;
Out.Light6.xyz = mul(worldToTangentSpace, -Light6); // L

Out.Att6 = distance(PosWorld,vecLightPos[5])/vecLightPos[5].w; // Point light

float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
Out.Fog = ofog;

return Out;
}



struct PS_INPUT2
{
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;

float3 Light5 : TEXCOORD2;
float Att5 : TEXCOORD3;

float3 Light6 : TEXCOORD4;
float Att6 : TEXCOORD5;
};


float4 PS_PASS2( PS_INPUT2 psInStruct ):COLOR
{

float4 color = tex2D(ColorMapSampler, psInStruct.Tex); // fetch color map
float3 bumpNormal = 2 * (tex2D(BumpMapSampler, psInStruct.Tex) - 0.5); // fetch bump map
float4 gloss = tex2D( BumpMapSampler, psInStruct.Tex );

float3 ViewDir = normalize(psInStruct.View);

//light5
float3 LightDir5 = normalize(psInStruct.Light5);
float4 diff5 = saturate(dot(bumpNormal, LightDir5)); // diffuse component
float shadow5 = saturate(4 * diff5);
float3 Reflect5 = normalize(2 * diff5 * bumpNormal - LightDir5); // R
float4 spec5 = pow(saturate(dot(Reflect5, ViewDir)), 15);
float4 Attenuation5 = saturate(dot(psInStruct.Att5, psInStruct.Att5));

//light2
float3 LightDir6 = normalize(psInStruct.Light6);
float4 diff6 = saturate(dot(bumpNormal, LightDir6)); // diffuse component
float shadow6 = saturate(4 * diff6);
float3 Reflect6 = normalize(2 * diff6 * bumpNormal - LightDir6); // R
float4 spec6 = pow(saturate(dot(Reflect6, ViewDir)), 15);
float4 Attenuation6 = saturate(dot(psInStruct.Att6, psInStruct.Att6));

return
(
((shadow5 * (color * diff5 + (spec5*gloss.w)) * (1 -Attenuation5))*vecLightColor[4])+
((shadow6 * (color * diff6 + (spec6*gloss.w)) * (1 -Attenuation6))*vecLightColor[5])

);
}



// -------------------------------------------------------------
// 1.1
// -------------------------------------------------------------

float3x3 matTangent;
float4x4 matWorldView;
float4 vecSunDir;

float4 DoTransform(float4 Pos)
{
return mul(Pos,matWorldViewProj);
}

float DoFog(float4 Pos)
{
float3 P = mul(Pos,matWorldView); // convert vector to view space to get it's depth (.z)
return saturate((vecFog.y-P.z) * vecFog.z); // apply the linear fog formula
}

float4 DoPos(float4 Pos)
{
return (mul(Pos,matWorld));
}
float3 DoPos(float3 Pos)
{
return (mul(Pos,matWorld));
}

void CreateTangents(float3 inNormal,float3 inTangent)
{
matTangent[0] = DoPos(inTangent);
matTangent[1] = DoPos(cross(inTangent,inNormal)); // binormal
matTangent[2] = DoPos(inNormal);
}

float3 DoTangent(float3 inVector)
{
return normalize(mul(matTangent,inVector));
}

struct out_bump
{
float4 Pos: POSITION;
float Fog: FOG;
float4 Color: COLOR;
float2 Tex: TEXCOORD0;
float2 Bump: TEXCOORD1;
float3 Normal: TEXCOORD2;
float3 Light: TEXCOORD3;
};

out_bump vs_bump( in float4 inPos: POSITION, in float3 inNormal: NORMAL, in float2 inTex: TEXCOORD0, in float3 inTangent: TEXCOORD2)
{
out_bump Out;

Out.Pos = DoTransform(inPos);
Out.Tex = inTex;
Out.Bump = inTex; // different coordinates required for ps_1_1
Out.Color = float4(1.0,1.0,1.0,1.0);
Out.Fog = DoFog(inPos);

CreateTangents(inNormal,inTangent);
float3 N = matTangent[2];

// transform the output values into the 0..1 range
Out.Light = DoTangent(-vecSunDir) * 0.5 + 0.5;
Out.Normal = DoTangent(N) * 0.5 + 0.5;

return Out;
}


float4 ps_bump(out_bump In): COLOR
{
float4 base = tex2D(ColorMapSampler,In.Tex);
float3 bumpNormal = tex2D(BumpMapSampler,In.Bump);
float diffuse = saturate(dot(In.Light*2 - 1,bumpNormal*2 - 1));
diffuse *= saturate(4 * dot(In.Light*2 - 1,In.Normal*2 - 1));

return base * diffuse;
}


// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------

// 2.0
technique SpecularNormalMapping_20
{
pass P0
{
alphablendenable=false;
srcblend=zero;
// compile shaders
VertexShader = compile vs_2_0 VS_PASS0();
PixelShader = compile ps_2_0 PS_PASS0();
}

pass P1
{
//blend second pass additively with first
alphablendenable=true;
srcblend=one;
destblend=one;

// compile shaders
VertexShader = compile vs_2_0 VS_PASS1();
PixelShader = compile ps_2_0 PS_PASS1();
}

pass P2
{
//blend second pass additively with first and second
alphablendenable=true;
srcblend=one;
destblend=one;

// compile shaders
VertexShader = compile vs_2_0 VS_PASS2();
PixelShader = compile ps_2_0 PS_PASS2();
}
}

// 1.1
technique SpecularNormalMapping_11
{
pass P0
{
VertexShader = compile vs_1_1 vs_bump();
PixelShader = compile ps_1_1 ps_bump();
}
}

// Fallback; If nothing works
technique fallback { pass one { } }


Posted By: frazzle

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/19/07 19:47

Quote:


Ok, here is my super monster shader,...

Again, I'm not really skilled with HLSL, even after studying the shaderx2 series.





Well the monster shader is indeed quite impressive and still requires some HLSL skills which you own
Btw, thxn for this contribution Bloodline

Cheers

Frazzle
Posted By: TWO

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/19/07 20:07

Thanks for your kind words frazzle

The shader is now posted in the wiki. I also changed some other things just4fun
Posted By: Slin

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/19/07 20:17

Hey, thanks, it´s much faster than the shader I posted and still looks the same...

I´m just going to upload a simple picture...

Edit:


Thanks to Dexsoft for the nice Christmas gift, the model ist from!
Posted By: Ghost

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/19/07 20:44

Thanks Bloodline, this is great!!!
Posted By: cartoon_baboon

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/19/07 22:39

ok, ok, so I'm officially a dumb f... but how do I go about using this shader. I made a wdl file starting with:

material normalmapping{
effect="
then I pasted the code from the wiki
ended with:
";}
saved it as normalmapping.wdl , included it into the main script and made an action with my.material= normalmapping. Made an object with two skins, the second being a normal map and applied the action to it.

On running I get the error:
//---------
/>
normalmapping.wdl 331:-1 () String length effect="

//---------

/

So what did I do wrong?
Posted By: PHeMoX

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/20/07 02:39

Copy what you've pasted into a new txt file ( the shader code between the two " 's, save it as .FX file instead into your work folder, now write that name of that .FX between the two " 's in the material in your wdl. I'm not sure, but I think this shader is too big to be copied and pasted inside a material, but this is just a wild guess,

Cheers
Posted By: William

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/20/07 09:16

Thanks for the great contribution. Though I've got a question, how would someone have it so the first light is for sunlight? This was the problem I had with matt's shader, trying to get sunlight and dynamic lights to work together. Basically trying to use it on models for both outdoors and indoors.
Posted By: ulf

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/20/07 09:25

this looks like dark magic to me, but the results are nice - so great job bloodline!
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/20/07 14:09

Adding sunlight is not difficult. Instead of calculating the angle from the light to the world pos, you simply use the vecSunDir vector....


BTW: If you add sunlight, do NOT use attenuation on it, you'll get some crappy effects,
Posted By: William

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/21/07 04:07

Quote:


//light 1
float3 Light1 = PosWorld - vecSunDir[0] ;
Out.Light1.xyz = mul(worldToTangentSpace, -Light1); // L

Out.Att1 = distance(PosWorld,vecLightPos[0])/vecLightPos[0].w; // Point light





I've tried changing the code, but the sun doesn't seem to affect the model. Which lines were you referring too?

P.S - sorry about my n00b when trying to edit shaders.
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/21/07 14:52

Out.Sun = mul(worldToTangentSpace, -vecSunDir);

You may need to remove the (red) - ...

I'm not sure...
Posted By: William

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/22/07 01:17

Quote:

struct VS_OUTPUT0
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 View : TEXCOORD1;

float3 Light1 : TEXCOORD2;
float Att1 : TEXCOORD3;
float3 Sun : TEXCOORD6;

float3 Light2 : TEXCOORD4;
float Att2 : TEXCOORD5;

float Fog : FOG;
};


VS_OUTPUT0 VS_PASS0(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0 )
{
VS_OUTPUT0 Out = (VS_OUTPUT0)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

Out.Tex = texcoord0.xy;

float3 PosWorld = mul(Pos, matWorld);

float3 Viewer = PosWorld - vecViewPos;
Out.View = mul(worldToTangentSpace, - Viewer); // V

Out.Sun = mul(worldToTangentSpace, -vecSunDir);

//light 1
float3 Light1 = PosWorld - vecLightPos[0] ;
Out.Light1.xyz = mul(worldToTangentSpace, -Light1); // L
Out.Att1 = distance(PosWorld,vecLightPos[0])/vecLightPos[0].w; // Point light

//light 2
float3 Light2 = PosWorld - vecLightPos[1] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

Out.Att2 = distance(PosWorld,vecLightPos[1])/vecLightPos[1].w; // Point light

float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
Out.Fog = ofog;

return Out;
}




I tried adding it, but it gives an error and defaults to vertex lighting material. Then I added "float3 Sun : TEXCOORD6;" and theres no error, but it doesn't show the first light properly(and still no sun). I've also tried messing in the PS part and edited out light1 and put in Sun instead, but no luck. Am I messing things up?
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/22/07 14:10

I added some stuff, I'm gonna go "debug" it...

I'll post my results soon...
Posted By: William

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/22/07 23:59

Will be looking forward to it. Thanks for your help.
Posted By: MaxF

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/24/07 16:26

Hi

Its not working for me, it looks like the model is not change by the shader

What I'm doing wrong?

1) Put the shader in a fx file
2) wrote a wdl with the following statement:

material mat_nm3lights
{
effect = "nm3light.fx";
}

3) attached material in WED to model
Posted By: bstudio

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/24/07 18:09

did you include a light near the model (dynamic light that is)
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/24/07 20:31

add in effect_load() in a starter function


Code:

string fxNM3Light = "nm3light.fx";

material mat_nm3lights
{
effect = fxNM3Light;
}

starter loadFX
{
effect_load(mat_nm3lights, fxNM3Light);
}


Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/26/07 03:26

just thought I'd let you know I'm still workin on this. I accidently coppied it onto my work drive instead of my thumbdrive, so I havn't been able to work on it this weekend.

So far I [theoretically] have 5 lights in one pass. It should work, but needs to be tested. I did this by copying the light AttenuationX into the LightX:TEXCOORDX.

I'll be at work tomorrow, and post my results...
Posted By: William

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/26/07 04:38

Np, I'm looking forward to testing it.

BTW - why 5 lights in one pass? Is this needed to allow sunlight?
Posted By: bstudio

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/26/07 06:41

starter is no longer used as a function, to use a starter function use this:

Code:

function LoadFX_startup()
{
effect_load(mat_nm3lights, fxNM3Light);
}


Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/26/07 13:15

@bstudio: Thanks, I had heard of this update, but never got around to actually using it. I'll remember that...


@William: It's not required, it's just an optimization. Using less passes, yet still getting the same effect = better speeds... correct? I currently only have 5 lights, but it still has room for more in its pass... (1 or 2 texcoords left)
Posted By: TWO

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/26/07 14:16

wow, nice Theoratical you could make a 15 light shader with 3 passes xD
Posted By: MaxF

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/26/07 14:58

OK kool will try this code tonight
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/27/07 03:51

Alright...

A ran into another wall. The limit on the number of commands you can run in a shader. It's currently down to 3 lights per pass, but it runs good.


I'm gonna mess with it a lil more, then post whatever I get tomorrow morning.
Posted By: EX Citer

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/27/07 06:51

sounds good
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/28/07 02:40

Alright, it's getting there. I just need to add specular lighting to the sun, and some other little things.

Here's a (crappy) youtube preview of the shader applied to PSionics spider thing. Sorry for the quality, YouTube butchered it...


Preview 01

Note: It may take a minute for it to finish uploading, if it does not work, try again later...
Posted By: William

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/28/07 07:47

Looks great! Would it also be possible for the user to be able to change the diffuse and ambient for the model with normalmapping? Is this possible to do in the material and not in the fx(but the .fx recognizes it)? That way if it's too dark or light you can change it. Thanks.
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/28/07 13:44

Good idea, I'll add that in...

I will add the:
- Ambient: for adjusting brightness...
- Diffuse: for adjusting how much color is used (IE: 0 = grayscale)
- Static Lighting*


*I'll upload my current progress before I implement this, as I'm not sure how exacttly I'll do this. The only problem is that it only passes the colors, not direction. Therefor, when using static lighting, I'll either have to use it as an "ambience" sort of thing; Or I can make up a direction for it.
Posted By: bstudio

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/28/07 14:15

couldn't you just pass it with the skills which are predefined for shader passing?
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/28/07 15:15

Na, it would be easier to just use the pre-defined vector (vecAmbient, vecDiffuse, vecLight)...


Currently, my static light idea is using the suns position as the source direction for the light. I've already added Ambient & diffuse vectors.


It looks really good, and runs quite quickly with sun & 2 dynamic light sources (+ additionals such as static & ambience, etc). So I'm really happy with it. I think I'll rewrite it so that the first pass calculates sun + static + ambience, and the second just does dynamic lighting.
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/28/07 16:47

I'm having a problem with vecLight...

It doesn't seem to work properly. It's vey "jumpy" and sometimes returns strange values. It only works correctly a short portion of the time.
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 01:31

Alright... it's finished! (for now)...


It currently runs through 2 passes, supports 3 dynamic light, sun light, static lighting, and more...


Who wants to host it? I'll email it to you...
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 02:27

Here it is for now... I'm not sure how long the link will hold up though...


Download Here
Posted By: bstudio

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 06:39

I'll host it for you, just gimme a sec
Download normal mapping shader
here it is
Posted By: Mondivirtuali

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 09:03

Well, it gave me ton of errors
this is the code
Code:
 -------------------------------------------------------------
// Diffuse and specular shader for models
// -------------------------------------------------------------
// [18/3/06 Bloodline] - Added ambient and a 3rd light


float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLightPos[8]; //light position
float4 vecLightColor[8]; //light color
float4 vecViewPos;

// Change ambient here
float4 Ambient = { 0.6f, 0.6f, 0.6f, 1.0f };

texture entSkin1; //this is the color map
texture entSkin2; //this is the normal map

sampler sColorMap = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};


sampler sBumpMap = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};




///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//first pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT0
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light1 : TEXCOORD2;
float3 View1 : TEXCOORD3;
float3 Att1 : TEXCOORD4;

float3 Light2 : TEXCOORD5;
float3 View2 : TEXCOORD6;
float3 Att2 : TEXCOORD7;

float3 Light3 : TEXCOORD8;
float3 View3 : TEXCOORD9;
float3 Att3 : TEXCOORD10;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT0 VS_PASS0(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 )
{
VS_OUTPUT0 Out = (VS_OUTPUT0)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
float3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(Tangent, matWorld);
worldToTangentSpace[1] = mul(cross(Tangent, Normal), matWorld);
worldToTangentSpace[2] = mul(Normal, matWorld);

Out.Tex = texcoord0.xy;

float3 PosWorld = mul(Pos, matWorld);

float LightRange = 1/vecLightPos[0].w;
float LightRange2 = 1/vecLightPos[1].w;
float LightRange3 = 1/vecLightPos[2].w;

//light 1
float3 Light1 = PosWorld - vecLightPos[0] ;
Out.Light1.xyz = mul(worldToTangentSpace, -Light1); // L

float3 Viewer1 = PosWorld - vecViewPos;
Out.View1 = mul(worldToTangentSpace, -Viewer1); // V

Out.Att1 = Light1 * LightRange; // Point light

//light 2
float3 Light2 = PosWorld - vecLightPos[1] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

float3 Viewer2 = PosWorld - vecViewPos;
Out.View2 = mul(worldToTangentSpace, -Viewer2); // V

Out.Att2 = Light2 * LightRange2; // Point light

//light 3
float3 Light3 = PosWorld - vecLightPos[2] ;
Out.Light3.xyz = mul(worldToTangentSpace, -Light3); // L

float3 Viewer3 = PosWorld - vecViewPos;
Out.View3 = mul(worldToTangentSpace, -Viewer3); // V

Out.Att3 = Light3 * LightRange3; // Point light

return Out;
}


struct PS_INPUT0
{
float2 Tex : TEXCOORD0;

float3 Light1 : TEXCOORD2;
float3 View1 : TEXCOORD3;
float3 Att1 : TEXCOORD4;

float3 Light2 : TEXCOORD5;
float3 View2 : TEXCOORD6;
float3 Att2 : TEXCOORD7;

float3 Light3 : TEXCOORD8;
float3 View3 : TEXCOORD9;
float3 Att3 : TEXCOORD10;

};

float4 PS_PASS0( PS_INPUT0 psInStruct ):COLOR


{

float4 color = tex2D(sColorMap, psInStruct.Tex); // fetch color map
float3 bumpNormal = 2 * (tex2D(sBumpMap, psInStruct.Tex) - 0.5); // fetch bump map
float4 gloss = tex2D( sBumpMap, psInStruct.Tex );

//light1
float3 LightDir1 = normalize(psInStruct.Light1);
float3 ViewDir1 = normalize(psInStruct.View1);
float4 diff1 = saturate(dot(bumpNormal, LightDir1)); // diffuse component
float shadow1 = saturate(4 * diff1);
float3 Reflect1 = normalize(2 * diff1 * bumpNormal - LightDir1); // R
float4 spec1 = pow(saturate(dot(Reflect1, ViewDir1)), 15);
float4 Attenuation1 = saturate(dot(psInStruct.Att1, psInStruct.Att1));

//light2
float3 LightDir2 = normalize(psInStruct.Light2);
float3 ViewDir2 = normalize(psInStruct.View2);
float4 diff2 = saturate(dot(bumpNormal, LightDir2)); // diffuse component
float shadow2 = saturate(4 * diff2);
float3 Reflect2 = normalize(2 * diff2 * bumpNormal - LightDir2); // R
float4 spec2 = pow(saturate(dot(Reflect2, ViewDir2)), 15);
float4 Attenuation2 = saturate(dot(psInStruct.Att2, psInStruct.Att2));

//light3
float3 LightDir3 = normalize(psInStruct.Light3);
float3 ViewDir3 = normalize(psInStruct.View3);
float4 diff3 = saturate(dot(bumpNormal, LightDir3)); // diffuse component
float shadow3 = saturate(4 * diff3);
float3 Reflect3 = normalize(2 * diff3 * bumpNormal - LightDir3); // R
float4 spec3 = pow(saturate(dot(Reflect3, ViewDir3)), 15);
float4 Attenuation3 = saturate(dot(psInStruct.Att3, psInStruct.Att3));

return (
(0.1 * color + 0.2 * Ambient) +
((shadow1 * (color * diff1 + (spec1*gloss.w)) * (1 -Attenuation1))*vecLightColor[0])+
((shadow2 * (color * diff2 + (spec2*gloss.w)) * (1 -Attenuation2))*vecLightColor[1])+
((shadow3 * (color * diff3 + (spec3*gloss.w)) * (1 -Attenuation3))*vecLightColor[2])
);
}



// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique two_pass
{
pass P0
{
alphablendenable=false;
srcblend=zero;

VertexShader = compile vs_3_0 VS_PASS0();
PixelShader = compile ps_3_0 PS_PASS0();
}



}[\code]


Posted By: bstudio

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 09:06

did you put it in a .fx file and included it in a material like this:
Code:

material normal_map_map
{
effect = <normalmap.fx>;
}


Posted By: Mondivirtuali

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 10:31

ah Yes
this was the script
Code:
  // Diffuse and specular shader for models
// -------------------------------------------------------------
// [18/3/06 Bloodline] - Added ambient and a 3rd light
MATERIAL mtl_newman2
{

float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLightPos[8]; //light position
float4 vecLightColor[8]; //light color
float4 vecViewPos;....



ton of errors



Posted By: Mondivirtuali

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 10:56

Now works, I just use the NM files from Bstudio.
Posted By: Mondivirtuali

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 11:11



the risult

the maps





Posted By: TWO

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 11:28

Ugly modell ^^

Yes, the shader you posted was outdated
Posted By: Mondivirtuali

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 13:31

A test model, just an exercise for verify how the work flow ( modelling, texturing, animating and shaders ) does work.
Posted By: cartoon_baboon

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 13:49

Well I finally got the normal mapping to work, using bstudio's files. Thing is, when applied the model becomes super glossy how do you go about making the model less glossy? Must I do it in the normalmap itself or must I set the glossiness somewhere else?

Thanks,
cartoon_baboon
Posted By: bstudio

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 14:05

maybe lower the specular values?
Posted By: cartoon_baboon

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 14:12

and where do I find these specular values? I've looked in the fx file but am not sure what I'm looking for.
Posted By: bstudio

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/29/07 14:18

float4 spec1 = pow(saturate(dot(Reflect1, ViewDir1)), 15);

here you can change the specular values of the lights, they will be passed through to the model, so i quess you can adjust them here
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/30/07 00:46

The "glossiness" is controlled by the alpha channel of your normal map. This glossiness is simply specular lighting based on reflections.

*Use the alpha channel of your NormalMap...
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/30/07 00:47

And to Mondivirtuali, Your normal maps don't look right. Try using a model that already has normal maps.
Posted By: William

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/30/07 07:11

Wow, this shader is great, it does everything I needed and runs fast. Here are a couple of quick changes for further usability.

Currently, the ambient set thru your material doesn't work properly. Here is the change in your shader code:

Code:
 /*
return (
(color * 0.05f) + outSun +
((shadow1 * (color * diff1 + (spec1*gloss.w)) * (1 -Attenuation1))*vecLightColor[0])
);*/


return (
(color *vecAmbient) + outSun +
((shadow1 * (color * diff1 + (spec1*gloss.w)) * (1 -Attenuation1))*vecLightColor[0])
);



I hope that's changed right? But it works...

Also, fog doesn't work, if it's enabled your model will be all white. Change the technique in the shader code:

Code:
 
technique SpecularNormalMapping_20
{
pass P0
{
alphaBlendEnable = false;
srcBlend = zero;
//FogEnable=false;
//
VertexShader = compile vs_2_0 VS_PASS0();
PixelShader = compile ps_2_0 PS_PASS0();
}
//
pass P1
{
alphaBlendEnable = true;
srcBlend = One;
destBlend = One;
FogEnable=false;
VertexShader = compile vs_2_0 VS_PASS1();
PixelShader = compile ps_2_0 PS_PASS1();
}
}



Make sure the "fogenable = false" line isn't in your first pass or fog wont work at all. This is a common problem with A6 and fog.

Thanks alot for your work on this shader!
Posted By: Mondivirtuali

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/30/07 11:03

The question is: how to obtain right NM from H poly models..
Posted By: Machinery_Frank

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/30/07 12:10

Mondivirtuali:
There are plug-ins for all the big modelling-tools to create normal-maps from highpoly-models. Most of those plug-ins are based on the ATI sdk.
Besides that there is a tool called Melody from NVidia and another ORB (Open Render Bump) from an university.

To the others:
Could someone please add the improved version to the WIKI? With that we have the old shader 2.0 version and the new one supporting shader 3.0.
Posted By: Anonymous

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/30/07 19:58

Hi how i use the shader?
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 04:24

@Frank_G: A model 2 shader will work on a model 3 card... You don't need to change the code, it won't help.

@fear411: Simply include the <NM.wdl> in your project. Then apply the material to your models.

@All: Sorry, I forgot to add the static lighting code. I'll add it, fix the above mentioned problems, and maybe more.

I didn't use vecAmbient on purpose, because it wasn't working for me. I had included it (as a float4), but it always returned 1.0f in all slots.


I will update the code, and then send it to William, as he is currently my supervisor.
Posted By: Machinery_Frank

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 07:11

xxGuitar:

You misunderstood me. The shader from this thread compiles on shader 3.0. But Matt's older version on 2.0 (and on 3.0 cards as well). Because of that I would like to have both of them in the WIKI.

So we could create some kind of fallback solutions.
Posted By: Machinery_Frank

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 09:43

Hi,

I rendered a texture for you to play around with normal-mapping shaders with and without specularity. You can add the spec-map into the alpha channel if you need it.

If you need parallax- or relief-mapping then you can even use the height map.

Download: http://www.dexsoft-games.com/freebies/textures/freecrate.zip

Preview:


This is a gift for you. Use it but please put a finished version of this shader into the WIKI as an alternative to the 2.0 shader from Matt (please do not remove this one).

Best regards,
Frank
Posted By: Anonymous

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 13:18

ich bekomme immer fehler wenn ich das spiel starte.
ich nutze auch noch sylex und newton.

keyword unknown float4x4
und noch viele mehr
Posted By: DWilki

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 15:35

Very nice shader. I've applied this to models and it looks great.

A question. I am trying to apply this to a mesh to be used as world geometry. I have seen this problem before and I think its a UV mapping issue with the mesh I am using. I can remember how I fixed this problem once before.





Anyone have any suggestions as to what I am doing wrong with the mesh?
Posted By: Anonymous

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 15:56

how i apply the shader to a model?
Posted By: DWilki

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 16:06

Quote:

how i apply the shader to a model?




Paste this code into a script and follow the directions.

***********************************************************


//Copy the shader code into notepad and save the file as NM.fx in the root directory of your project
string fxNM3Light = "NM.fx";

//Assign this action to a mesh (box or sphere). Set the mesh to "cast" in properties and make sure the light is close to your model
action DynamicLight
{
my.red = 187;
my.green = 148;
my.blue = 11;
my.lightrange =600;
my.light = ON;
}


//Assign this material to the model you want normal map/specular effect by adding the material in the properties dialogue
//Make sure your model has a diffuse texture in skin1 and a normal map texture in skin 2.
//If you want more control of the specular, add a specular map to the alpha channel of the normalmap
material mat_nm3lights
{
flags = tangent;
effect = fxNM3Light;
}


starter LoadFX_startup()
{
effect_load(mat_nm3lights, fxNM3Light);
}

**********************************************************
Posted By: Anonymous

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 16:16

where can i look if the skins are right?
Posted By: DWilki

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 16:34

Quote:

where can i look if the skins are right?




Open your model in med, then go to "Edit" and select "Manage skins".
Posted By: Anonymous

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 16:36

@DWilki can you post an example model,please?
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 03/31/07 20:35

@Frank_G; Sorry, but I'm not understanding the problem.

The shader I posted is coded to compile at vs/ps 2.0
The only thing left in this shader from Matt is his techniques for lighting. Much has changed.
I'm not seeing where shader 3.0 is a problem.
Posted By: William

Re: [Supply] Matt's NormalMapping shader with 3 li - 04/01/07 01:23

I think Frank was reffering to Bloodlines shader posted in the beggining of this thread, it is 3.0. Though, theres 2 different normalmapping shaders here, the new one posted by Guitar takes Bloodlines/Matt's, adds ability for sunlight, makes it faster, more options, and does it in 2.0 with less pass's. If someones posting this on the wiki, I'd reccomend posting the second one, the 2.0 one.
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 04/01/07 01:33

Let me finish the shader, then I'll post it to the Wiki...
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 04/01/07 05:29

Oh yeah, I can't edit on the wiki, lol.

Whoever wants to post it, give me your email and I'll send you the two scripts (WDL & FX).


@William: I don't think any of the things I just added will help you, but I did improve/finish the shader if you want to update. The only problm I am having now, is the fog. Your suggestion worked (got rid of the brightness), but the fog is not applied to the second pass, so you will still see the second & third lughts through the fog.
Posted By: Sam_Be

Re: [Supply] Matt's NormalMapping shader with 3 li - 04/01/07 09:01

hi
can you send me the shader too????

thanks
sam
ps how do i include it into the main script??
Posted By: Machinery_Frank

Re: [Supply] Matt's NormalMapping shader with 3 li - 04/01/07 12:39

Okay. I created a WIKI account. You can send it to me and I will post it.
You can also add me to MSN, its all the same email:
info [att] geppert [minus] software [dot] de

Regards,
Frank
Posted By: TWO

Re: [Supply] Matt's NormalMapping shader with 3 li - 04/01/07 13:04

But Frank, edit my "Normalmapping" entry, don't create a new one.
Posted By: xXxGuitar511

Re: [Supply] Matt's NormalMapping shader with 3 li - 04/01/07 17:16

Moved Here!
© 2024 lite-C Forums