Ulitimate lighting shader pack v1.0

Posted By: Matt_Aufderheide

Ulitimate lighting shader pack v1.0 - 11/25/04 03:00

After a bit of struggle im happy to release the first version of my Ultimate Lighting shader pack. Included now are two shaders, one for world geometry and one for models. Here is a shot of them in action:


it can render all the dynamic lights except sunlight.
first you need to have light objects in your level..attach this action to them in WED:

Code:

var light_dist=400; //this is how far away form a light it will be visible.
action light_pos_object
{
wait(5);
my.invisible=on;
my.passable=on;

while(1)
{

if vec_dist(my.x,player.x)<light_dist
{

my.light=on;
my.lightrange=300; //could be set also to a skill

my.red=my.skill1; //just put in the r,g,b values
my.green=my.skill2;
my.blue=my.skill3;

my.cast=on; //casts a shadow when on
}


else
{
my.lightrange=0; //if too far away turn it off
my.light=off;
my.cast=off;

}

wait(1);
}


}



Here is the world geometry shader:
Code:

// -------------------------------------------------------------
// Diffuse and specular shader for world geometry
// -------------------------------------------------------------
//this is a 3 pass shader rendering 3 lights in each pass,3 rd pass has the last light

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

texture entSkin1; //this is the color map
texture mtlSkin1; //this is the normal map..define in your shader defs

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


sampler BumpMapSampler = sampler_state
{
Texture = <mtlSkin1>;
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 = 0.01;

//light 1
float3 Light1 = PosWorld - vecLightPos[1] ;
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[2] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

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

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

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

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

Out.Att3 = Light3 * LightRange; // 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;

};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//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) + //ambient
((shadow1 * (color * diff1 + (spec1*gloss.w)) * (1 -Attenuation1))*vecLightColor[1])+
((shadow2 * (color * diff2 + (spec2*gloss.w)) * (1 -Attenuation2))*vecLightColor[2])+
((shadow3 * (color * diff3 + (spec3*gloss.w)) * (1 -Attenuation3))*vecLightColor[3])
);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//second pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light4 : TEXCOORD2;
float3 View4 : TEXCOORD3;
float3 Att4 : TEXCOORD4;

float3 Light5 : TEXCOORD5;
float3 View5: TEXCOORD6;
float3 Att5 : TEXCOORD7;

float3 Light6 : TEXCOORD8;
float3 View6 : TEXCOORD9;
float3 Att6 : TEXCOORD10;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT1 VS_PASS1(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 )
{
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);
float LightRange = 0.01;

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

float3 Viewer4 = PosWorld - vecViewPos;
Out.View4 = mul(worldToTangentSpace, -Viewer4); // V

Out.Att4 = Light4 * LightRange; // Point light


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

float3 Viewer5 = PosWorld - vecViewPos;
Out.View5 = mul(worldToTangentSpace, -Viewer5); // V

Out.Att5 = Light5 * LightRange; // Point light

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

float3 Viewer6 = PosWorld - vecViewPos;
Out.View6 = mul(worldToTangentSpace, -Viewer6); // V

Out.Att6 = Light6 * LightRange; // Point light

return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;

float3 Light4 : TEXCOORD2;
float3 View4 : TEXCOORD3;
float3 Att4 : TEXCOORD4;

float3 Light5 : TEXCOORD5;
float3 View5: TEXCOORD6;
float3 Att5 : TEXCOORD7;

float3 Light6 : TEXCOORD8;
float3 View6 : TEXCOORD9;
float3 Att6 : TEXCOORD10;

};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
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 );

//light4
float3 LightDir4 = normalize(psInStruct.Light4);
float3 ViewDir4 = normalize(psInStruct.View4);
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, ViewDir4)), 15);
float4 Attenuation4 = saturate(dot(psInStruct.Att4, psInStruct.Att4));

//light5
float3 LightDir5 = normalize(psInStruct.Light5);
float3 ViewDir5 = normalize(psInStruct.View5);
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, ViewDir5)), 15);
float4 Attenuation5 = saturate(dot(psInStruct.Att5, psInStruct.Att5));

//light6
float3 LightDir6 = normalize(psInStruct.Light6);
float3 ViewDir6 = normalize(psInStruct.View6);
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, ViewDir6)), 15);
float4 Attenuation6 = saturate(dot(psInStruct.Att6, psInStruct.Att6));

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

);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//third pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT2
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT2 VS_PASS2(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 )
{
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);
float LightRange = 0.01;

//light 7
float3 Light7 = PosWorld - vecLightPos[7] ;
Out.Light7.xyz = mul(worldToTangentSpace, -Light7); // L

float3 Viewer7 = PosWorld - vecViewPos;
Out.View7 = mul(worldToTangentSpace, -Viewer7); // V

Out.Att7 = Light7 * LightRange; // Point light

return Out;
}


struct PS_INPUT2
{
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;

};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
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 );

//light7
float3 LightDir7 = normalize(psInStruct.Light7);
float3 ViewDir7 = normalize(psInStruct.View7);
float4 diff7 = saturate(dot(bumpNormal, LightDir7)); // diffuse component
float shadow7 = saturate(4 * diff7);
float3 Reflect7 = normalize(2 * diff7 * bumpNormal - LightDir7); // R
float4 spec7 = pow(saturate(dot(Reflect7, ViewDir7)), 15);
float4 Attenuation7 = saturate(dot(psInStruct.Att7, psInStruct.Att7));

return
(
((shadow7 * (color * diff7 + (spec7*gloss.w)) * (1 -Attenuation7))*vecLightColor[7])
);
}
// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique two_pass
{
pass P0
{
alphablendenable=false;
srcblend=zero;
// compile shaders
VertexShader = compile vs_3_0 VS_PASS0();
PixelShader = compile ps_3_0 PS_PASS0();
}

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

// compile shaders
VertexShader = compile vs_3_0 VS_PASS1();
PixelShader = compile ps_3_0 PS_PASS1();
}

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

// compile shaders
VertexShader = compile vs_3_0 VS_PASS2();
PixelShader = compile ps_3_0 PS_PASS2();
}


}



here is the model shader:
Code:

// -------------------------------------------------------------
// Diffuse and specular shader for models
// -------------------------------------------------------------
//this is a 3 pass shader rendering 3 lights in each pass,3 rd pass has the last light

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

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;
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//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 = 0.01;

//light 1
float3 Light1 = PosWorld - vecLightPos[1] ;
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[2] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

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

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

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

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

Out.Att3 = Light3 * LightRange; // 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;

};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//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) + //ambient
((shadow1 * (color * diff1 + (spec1*gloss.w)) * (1 -Attenuation1))*vecLightColor[1])+
((shadow2 * (color * diff2 + (spec2*gloss.w)) * (1 -Attenuation2))*vecLightColor[2])+
((shadow3 * (color * diff3 + (spec3*gloss.w)) * (1 -Attenuation3))*vecLightColor[3])

);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//second pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light4 : TEXCOORD2;
float3 View4 : TEXCOORD3;
float3 Att4 : TEXCOORD4;

float3 Light5 : TEXCOORD5;
float3 View5: TEXCOORD6;
float3 Att5 : TEXCOORD7;

float3 Light6 : TEXCOORD8;
float3 View6 : TEXCOORD9;
float3 Att6 : TEXCOORD10;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT1 VS_PASS1(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 )
{
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);
float LightRange = 0.01;

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

float3 Viewer4 = PosWorld - vecViewPos;
Out.View4 = mul(worldToTangentSpace, -Viewer4); // V

Out.Att4 = Light4 * LightRange; // Point light


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

float3 Viewer5 = PosWorld - vecViewPos;
Out.View5 = mul(worldToTangentSpace, -Viewer5); // V

Out.Att5 = Light5 * LightRange; // Point light

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

float3 Viewer6 = PosWorld - vecViewPos;
Out.View6 = mul(worldToTangentSpace, -Viewer6); // V

Out.Att6 = Light6 * LightRange; // Point light

return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;

float3 Light4 : TEXCOORD2;
float3 View4 : TEXCOORD3;
float3 Att4 : TEXCOORD4;

float3 Light5 : TEXCOORD5;
float3 View5: TEXCOORD6;
float3 Att5 : TEXCOORD7;

float3 Light6 : TEXCOORD8;
float3 View6 : TEXCOORD9;
float3 Att6 : TEXCOORD10;

};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
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 );

//light4
float3 LightDir4 = normalize(psInStruct.Light4);
float3 ViewDir4 = normalize(psInStruct.View4);
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, ViewDir4)), 15);
float4 Attenuation4 = saturate(dot(psInStruct.Att4, psInStruct.Att4));

//light5
float3 LightDir5 = normalize(psInStruct.Light5);
float3 ViewDir5 = normalize(psInStruct.View5);
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, ViewDir5)), 15);
float4 Attenuation5 = saturate(dot(psInStruct.Att5, psInStruct.Att5));

//light6
float3 LightDir6 = normalize(psInStruct.Light6);
float3 ViewDir6 = normalize(psInStruct.View6);
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, ViewDir6)), 15);
float4 Attenuation6 = saturate(dot(psInStruct.Att6, psInStruct.Att6));

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

);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//third pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT2
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT2 VS_PASS2(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD2 )
{
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);
float LightRange = 0.01;

//light 7
float3 Light7 = PosWorld - vecLightPos[7] ;
Out.Light7.xyz = mul(worldToTangentSpace, -Light7); // L

float3 Viewer7 = PosWorld - vecViewPos;
Out.View7 = mul(worldToTangentSpace, -Viewer7); // V

Out.Att7 = Light7 * LightRange; // Point light

return Out;
}


struct PS_INPUT2
{
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;

};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
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 );

//light7
float3 LightDir7 = normalize(psInStruct.Light7);
float3 ViewDir7 = normalize(psInStruct.View7);
float4 diff7 = saturate(dot(bumpNormal, LightDir7)); // diffuse component
float shadow7 = saturate(4 * diff7);
float3 Reflect7 = normalize(2 * diff7 * bumpNormal - LightDir7); // R
float4 spec7 = pow(saturate(dot(Reflect7, ViewDir7)), 15);
float4 Attenuation7 = saturate(dot(psInStruct.Att7, psInStruct.Att7));

return
(
((shadow7 * (color * diff7 + (spec7*gloss.w)) * (1 -Attenuation7))*vecLightColor[7])
);
}
// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique two_pass
{
pass P0
{
alphablendenable=false;
srcblend=zero;
// compile shaders
VertexShader = compile vs_3_0 VS_PASS0();
PixelShader = compile ps_3_0 PS_PASS0();
}

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

// compile shaders
VertexShader = compile vs_3_0 VS_PASS1();
PixelShader = compile ps_3_0 PS_PASS1();
}

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

// compile shaders
VertexShader = compile vs_3_0 VS_PASS2();
PixelShader = compile ps_3_0 PS_PASS2();
}


}



now paste these shaders into new files and save as spec_bump_model.fx and spec_bump_world.fx(they must be in your "worlds" folder).

now all you need is to define your materials in script. Here is an example:

material spec_bump_model //assaign all models this material in script
{
flags = tangent;
}

d3d_automaterial=1;
bmap your_world_texture_normalmap = <your_world_texture_normalmap.tga>;
material your_world_texture_normalmap_tga
{
skin1 = your_world_texture_normalmap;
flags = tangent;
}

then call this function in main():

function load_shaders()
{
effect_load(spec_bump_model,"spec_bump_model.fx");

effect_load(your_world_texture_normalmap_tga,"spec_bump_world.fx");

wait(5);
}

Now you will have the Doom3 engine!! Some basic things to keep in mind: the more lights you have active at once the slower it renders, so try to limit your visible active lights to maybe 3-4 at once, depending on target video card. My next version will have lightrange determined by the dynamic light, not hard-coded as it is now.. this is an easy mod to make- i just forgot. Also there will be the ability to use_max lights reduce the number of passes. Have fun and feel free to ask for help.
-Matt Aufderheide
Posted By: Orange Brat

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 03:03

Superb work. I'm sure when I try it out that I'll fail miserably like I always do 50% of the time with shaders.
Posted By: ventilator

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 03:05

wow! this is the first convincing 3dgs normal mapping screenshot i have seen.
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 03:17

SWEEEEEEEEEEEEEEEEEEEEEEEEEEEEET!!!!!!
(catches breath)
Man, you just made my day. Can't wait to see it with Newton Physics... this should be added this to the shader index...
Thank you!


I update my tutorial sometime, after a few versions...



Posted By: TimeOut

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 03:20

I can say it in two words.
Fantastic work.
Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 04:00

Looks great -- I made the two fx files, saved the light script as a wdl and set the behavior of a ball model with the light action. I pasted the material code at the end of my main script. When complied and run, the error " empty pointer in light_pos_object:vec dist(my.x,player.x)>light_dist" appears twice then the level loads but no effects. Also, how do you assign a material to a model or object -- I usually use modified terrain multishaders for models -- is the "yournormalmap" texture applied from a WAD? Thanks for any help -- its a great loooking shadera nd I cant wait to apply it.

6.31.4 comm
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 04:12

That looks awsome.
Nice work Matt.
Thanks very much for sharing.

Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 04:22

you have to have a player entity assigned.. like player_walk_fight. Alternatively you can change the line where it says vec dist(my.x,player.x)>light_dist to this - vec dist(my.x,camera.x)>light_dist
Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 04:25

Changed it to my.camera and a red light shines! Now how to assign the material to models...
Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 04:33

Looks great! A very generous contribution.
Posted By: Migueljb01

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 04:43

First off very nice Matt! I was wondering for a level designer like myself if you could maybe put out a readme file on how someone like me which has no programming experience go about doing this. Step by step on how to use the code for lighting and level geometry. If you need any good test levels I have some nice ones that you could use also. Email me at mjbenitez001@msn.com if you need any. Thanks for an awesome contribution.

-spider21
Posted By: EX Citer

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 04:43

Looks fantastic.

Does the v1.0 means pixel &vertex shader v 1
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 04:51

Quote:

First off very nice Matt! I was wondering for a level designer like myself if you could maybe put out a readme file on how someone like me which has no programming experience go about doing this. Step by step on how to use the code for lighting and level geometry. If you need any good test levels I have some nice ones that you could use also. Email me at mjbenitez001@msn.com if you need any. Thanks for an awesome contribution.

-spider21





this should get you started, I will update the code soon hopefully... the basics of making normal maps and applying them is here...
http://216.46.205.166/ubbthreads/showflat.php?Cat=&Number=403149&page=0&view=collapsed&sb=5&o=&fpart=&vc=1&PHPSESSID=
Posted By: dleuen

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 04:56

Outstanding Matt! Thanks so much for the contribution.

Don
Posted By: TheExpert

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 05:42

Outstanding work !
It would be part of 3DGS downloable package because it's a very great package
perhaps in a repertory named users contributions.

I will test it as soon as possible.
Thanks very much for this great package.
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 05:47

nope that means its version 1 of my shader pack...
it requires pixel shader 3.0 right now,. alhtough it might compile to 2.0 I havent tried (i just got me a nice gForce6800) Give it a try and see if it works under 2.0 if you cant run 3.0.

In my next update i will try to include a sample level with better script files.. i just released it now cause i thought poeple would want to get thier hands dirty with this sooner rather than wait. All 3DGS needs now is Z-Fail stencil shadowing , and it's basically on par with Doom3 engine. Remember cause its all per pixel you can use models or world geometry and it all blends together , so you can do all the wierd curved sufaces stuff already if you use c-trace and c-move

And im sure someone can convert this shader technique to use a directional sunlight, so you can have FarCry style out-doors.. I hope Conitec will make a kick ass demo showing off this kind of lighting and such to show that A6 is a top flight engine now.
Posted By: oliver2s

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 05:48

Really amazing shader, good work.
Posted By: TheExpert

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 05:52

that's a little disapinting :
i have radeon 9800 Pro XT is not all people that have some cards like that
and that's pixel and vertex shader V2.
And V3 shaders only a more few minority than V2 shaders
will have the 3D cards.
if it not work with V2 only a very little minority will use it.

i 'll test if it do something with V2.
but great job
Posted By: TheExpert

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 05:57

and yes like you said : people can use any level geometry exported from 3DSMAX or others modelers if they use C_move and C_trace (no more need of WED and very long compilation time), and levels made of models are a lot more fast than
blocks geometry for the engine (i've tested all that a lot).
No geometry limitation and really fast level construction, for example under 3DSMAX creating stairs, copying rooms , building arches and
other things etc ... is very quick (not like WED).
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 05:58

OK currently these shaders require 3.0 but in my next release i will include a 2.0 fallback so dont worry (eventually i may even do a 1.4 fallback also but it may be slower.. i have to wait unltil the next beta version of a6 tho)
Posted By: TheExpert

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 06:07

Cool thanks .
But you know it was just a remark : not a lot of people have the last V3 shaders ,there are the latest 3D cards and the cost is not low !
And with the V2 i 've played Doom3 (with ini file modification to have a boost)
and HL2 with graphic options full.
Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 06:33

I thought WED blocks were faster than models -- why does 3dgs use them then?
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 06:48

It would be nice to get this thing down to a lower ps and vs version.
I can't even see the fx 'cause my card doesn't support the shader versions.
Posted By: Matt_Coles

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 07:06

Excellent work Matt, haven't tested it out yet, but if I can get something looking like what your screen shows, I'll be over the moon .

Was trying for this last night to no avail.

btw, would you consider releasing a small demo showing off this?

Thanks,

Matt Coles
Posted By: Matt_Coles

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 17:55

Works fine, although the shader isn't working properly, but that's as I'm running it on a P.S 2.0 ATi 9800 pro.
It'd be great if it was made with 2.0 support
anywayz, to avoid getting really weird renders caused by the sun when running the shader post the following code at the start of function main:
sun_light = 0; // no sun
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 20:06

can someone please post an exact step by step on getting the shader into code? Evrything I try produces ertors.
What gets put in what order? I follow the steps, but couldnt do it :(
Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 20:59

Drew & The Master: I have some questions about the Tangent and have posted it in the bug hunt.... You can get my version that is running okay with PS20 there and compare:

other page

It would be easy enough to add passes to that version to integrate more lights.
Posted By: TheExpert

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 21:50

Muralist :
No Blocks are really a lot more slow than models , if you don't need
lightmapping or only need baked textures for some parts of your level ,
use MDLs the FPS will be a lot greater.
a lot of people already know that MDL are faster than blocks here.
Yhe new octree system will allow you to use models for your levels and WED
will do the lightmapping on them. It will be great and it will be released.

Well , let's return to the shader discussion, yes i hope ot find V2 shaders one day
for this great lightning pack.
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 22:13

it will be easy to convert to 2.0 i just need to limit the number of lights per pass to two..
Posted By: TheExpert

Re: Ulitimate lighting shader pack v1.0 - 11/25/04 23:15

OK if you could that for PS2 and fix the distance for the ligths instead of having it hard coded it would be cool, or perhaps i'll try (i'm very newbbie with shaders).

I see you've put a gorgeous screen , why not give us a little demo also ,
just one or two rooms ?
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 00:00

Quote:

Evrything I try produces ertors.





Drew.. what kind of errors do you get.. i cant help unless i know what isnt working .. whether its a scripting problem or a shder problem. As said the shader requires ps v3.0 to work right now.
Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 03:47

Drew,

1. Make the two fx files

2. Save the light script as DynLight.wdl and set the behavior of a ball model with the light action. Set skill 1,2,3, to rgb -- I used 200 50 100 for example
Change player.x to camera.x

//DYNLIGHT.WDL:

var light_dist=2000; //this is how far away form a light it will be visible.
action light_pos_object
{
wait(5);
my.invisible=on;
my.passable=on;

while(1)
{

if vec_dist(my.x,camera.x)<light_dist
{

my.light=on;
my.lightrange=1000; //could be set also to a skill

my.red=my.skill1; //just put in the r,g,b values
my.green=my.skill2;
my.blue=my.skill3;

my.cast=on; //casts a shadow when on
}


else
{
my.lightrange=0; //if too far away turn it off
my.light=off;
my.cast=off;

}

wait(1);
}


}


3. Paste the material code at the end of main script. (didnt even put it inside main function, just tacked it onto the end) -- note my addition of VAR before d3dautomaterial like so:

//TACK ONTO END OF MAIN SCRIPT:

material spec_bump_model //assaign all models this material in script
{
flags = tangent;
}

var d3d_automaterial=1;
bmap your_world_texture_normalmap = <your_world_texture_normalmap.tga>;
material your_world_texture_normalmap_tga
{
skin1 = your_world_texture_normalmap;
flags = tangent;
}

//then call this function in main():

function load_shaders()
{
effect_load(spec_bump_model,"spec_bump_model.fx");

effect_load(your_world_texture_normalmap_tga,"spec_bump_world.fx");

wait(5);
}

Then I put in a couple of normal mapped models (which I used to use with your pointspeclight demo -- thanks for that by the way) and a couple of your crates -- one of which showed up partly transparent in the level... but I think the normal mapping works -- also add an image called yournormalmap.tga

Thats it.


I am only sure that this produces colored lights but it sure looks like the normalmap effect smooths the models ( I made low res versions of hires models, norrmal mapped them per your instructions...) I dont know how to apply textures to level blocks so I only use models.


Can someone tell me how to assign a normalmapped material to a model or object -- I usually use modified terrain multishaders for models -- is the "yournormalmap" texture applied from a WAD? How do I get the textures into the wads?
Posted By: Nadester

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 03:53

I have a Geforce 6800 GT, and while testing this it isn't giving me too much results. Everything is very bright, and I can see the dynamic lights are becoming visible when I move close, but there is no diffuse/specular. (Although I am not actually getting any script errors). Can you be specific on how this should be setup? For skin1, on the level objects, I am assigning a 32bit targa normal map. What about a specular map?

Is it possible that you could post the source to a very simple demo that shows a model and level object being lit?

Thanks!
Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 04:11

How do you apply 32 bit textures? I think my version of MED only uses 16 or so -- they dont look deep/
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 06:42

Put the specular map in alpha of the normalmap for world textures, put the specular in the alpha of the colormap for models..
Posted By: Nadester

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 10:25

I'm still getting the same results as before, I have no idea what I am doing wrong. Everything is just incredibly bright, and my normal maps aren't doing anything. Do you have any plans to post a simple demo?
Posted By: Nadester

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 10:36

This is what I am getting:

On A6 Professional 6.31.4. This entire level is rigged so that everything *should* be normal mapped.
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 11:58

Wierd, mine doesn't seem to react to any light at all. I placed two light_pos_object in the level. One behind the model and one infront of him.
He is almost completely black.
Posted By: Matt_Coles

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 13:46

Muralist:

to assign this code to your models paste this at the end of the normal mapping script

action Shader_NormalMap
{
my.material = spec_bump_model;
}

then assign it to an entity in WED.
Also you'll have to have a bump map in skin2 of whatever entity you put in there


Matt
Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 15:40

thanks.

Well, now the entities with the action assigned turn black and white.
Back to the drawing board...
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 16:32

tried the suggestions...closest I got was having it not crash, but no bump showing. I was getting the lighting fromthe light object though...

too many weird errors to post...just going to start over again... does object scale have any effect?
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 20:11

scale might make a difference, i haven't tested it , but it could screw up the normalization, try setting everything to scale of 1.

I cant really help unless you tell me what errors you are getting.

Nadester: i have no idea what's happening there.. it looks like your normalmap is wierd. Are you sure you have colormap set as entSkin1 and normalmap (with specular map in alpha) as mtlSkin1? Are the textures from a WAD or a tga in a folder? If they are in a WAD they probably wont work.
Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 11/26/04 21:32

Quote:

Wierd, mine doesn't seem to react to any light at all. I placed two light_pos_object in the level. One behind the model and one infront of him.
He is almost completely black.




In the Object Properties, give your a light(s) a color. For example;
skill1 = 255
skill2 = 255
skill3 = 128

Otherwise, the light is going to be "black".
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 03:02

The model still stays black.
Posted By: Nadester

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 05:24

Fiddled with it for another hour or so, same results as before. Can you please post something for us to see how it is setup?
Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 05:31

Quote:

The model still stays black.




Next, I would troubleshoot it by making "nofog" true (if you have fog setup in your project)... If that solves it, then you will need to add fog code to the shader or have no fog.
Posted By: Samb

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 05:59

how about a little demo with a testlevel as a wmp?
Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 06:25

They claim that the proof is in the pudding... This is a good shader that Matt has tweaked.

This shot is using pixelshader 2.0 with (2) lights in (1) pass. One with a bit of a red, and the other a bit of a yellow hue.

The crate is a model and the wall is level geometry.

The lights behave well and the scaling is not a problem.


Posted By: TheExpert

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 07:51

Steempipe have you modified the shader code to make it work under V2 shaders ?
Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 09:39

Quote:

Steempipe have you modified the shader code to make it work under V2 shaders ?




This is correct. Fun stuff!
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 09:47

yes its quite easy to mod it for ps 2.0.. you just have to reduce the number of lights per pass to two..
Posted By: Nadester

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 09:50

Ahhh... Ok, Steempipe's mod works well (Thanks Eric!), except for the fact that it messes with the scale of the textures, and some other strange glitches.

Strangely enough, the original still doesn't work, I am getting the same results as before. It's as if I don't have ps3.0 support, but I have a BFG GeForce 6800 GT.
Posted By: Nadester

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 10:21

Bingo! Needed the latest Nvidia drivers. Truly impressive Matt.

@Everyone - I'm going to make a killer demo and post it soon.
Posted By: Samb

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 10:41

i've got this error:"invaild arguments in load shaders: effect_load(normal,@4)" maybe it isn't a shader for DX9?
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 10:42

NAdester- can you also post the wmp so we can check model settings too? thanks!
Im getting close...
Posted By: Nadester

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 10:47

Will do, Drew.

@Samb, no - it is directx 9. But you need version 9c, a Geforce 6 card, the latest edition of A6 (the beta is required I believe?), and the latest NVidia drivers to run it - at least in its current state.
Posted By: Samb

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 11:15

[censored]... i have a radeon 9600
so it won't work right?
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 11:32

I beleive the 9600 only supports ps 2.0.. as said its quite easy to modify it to compile to that, and i will release a new version soon that includes a ps 2.0 fallback technique.
Posted By: Nadester

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 14:22

http://www.conitecserver.com/ubbthreads/showflat.php?Cat=&Number=453421&page=0&view=collapsed&sb=5&o=&fpart=1#453421

It's a mockup of my official normal mapping tech demo, but still pretty sweet.
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 15:42

Edit:

okay, thanks to everyone (xtra help from Nadester and Steempipe) I got it working... whew...
Screenshots soon!

again, Thanks Matt!

BTW,sorry I cant post a demo since it uses shared resources from other people and they asked me not to share yet.



Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 18:34

Will someone please post a simple demo --
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 22:37

Here is a playable demo of Matt's Shader, shows normal mapping working with Newton Physics...no source yet, but the only difference is coming soon anyway(ps2.0). these guys are kicking butt!! Extra thanks to Matt,Nadester and Steempipe, A6 is busting open.

Download HERE


Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 11/27/04 23:30

YeeHaw!
thanks.
Posted By: LogantheHogan

Re: Ulitimate lighting shader pack v1.0 - 11/28/04 02:56

Holy crap that's awesome.

Thanks a lot guys, you are really making this engine better.
Posted By: LogantheHogan

Re: Ulitimate lighting shader pack v1.0 - 11/28/04 03:04

Haha well I downloaded it, and I ended up having a LOT more fun with the physics objects than the shader. Why, oh why did you make an ammo limit?!

It looked really great, though. The textures on the walls - were those baked, or did they have the shader applied too?
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 11/28/04 05:10

Quote:

It looked really great, though. The textures on the walls - were those baked, or did they have the shader applied too?




From the screenshot it looks to me like it has the shader applied using a baked normal-map.
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/28/04 06:26

yup, all shaders! thats the beauty of it...the normal map is actually just the map image run through the normal filter in photoshop...
Im looking forward to making a flashlight or dynamic lightsource....sorry about the ammo limit
Posted By: EX Citer

Re: Ulitimate lighting shader pack v1.0 - 11/28/04 16:56

Hello,
thanks for the demo. I was really impressed...


... that my grafic card supports ps&vs shader 2 Ver good demo too, BUT I always saw only small rooms with good frame rate and shader applied to walls/level. I only heard one time of a complete level applied with shaders and the frame rate was very bad. I still didn´t tried it by myself because I am waiting for steempipes parallax mapping. I hope that clipping will work if bsp fails. I know that clipping and bsp is similar but it isn´t the same.

EX Citer
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/28/04 19:48

my shaders run on large levels, if you have the blocks set to "flat" and "tesselate flat" set to "auto"
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/28/04 22:22

(edited by me)
Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 11/28/04 22:41

When I ran the demo it seemed that my fps was very low -- how can I adjust my video settings to improve it?

AMD 64 (on 32-bit winxp home), 3200+, 2.oo Ghz, 1 GB ram, geforce FX 5400, 1534mb paging file size
Posted By: TheExpert

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 00:06

Great demo !

And for the lightening pack, i have a suggestion , why not make it evolves.
For example if someone has volumetric light , the code could be incorporated in this pack no ?
and we could perhaps have an official lighting package for community in shader
forum no ? is that a bad or good idea ?
Posted By: blaaaaa

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 00:33

In Antwort auf:

When I ran the demo it seemed that my fps was very low -- how can I adjust my video settings to improve it?

AMD 64 (on 32-bit winxp home), 3200+, 2.oo Ghz, 1 GB ram, geforce FX 5400, 1534mb paging file size




same for me, fps is very low if the objects are drawn.

system specs (too lazy to write them down, ill modify your ones )
AMD (on winxp home sp2),3200+, 2.20 Ghz, 512 MB ram, geforce FX 5700 Ultra, 1024mb paging file size
Posted By: DARKLORD

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 02:42

Great work Matt

but my graphic card supports only ps and vs 2.0 so can somebody please post the modified code for ps and vs 2.0

thanks
Posted By: XNASorcerer

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 04:10

Nice demo!
But your demo is trying to connect to the internet. Why?
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 05:47

connecting to internet!?
geeez I have no idea...make sure you virus scan it, although I did already twice. Ive never heard of this.
Posted By: M3PHiSTOPH3L3S

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 06:06

@Sorcerer: Is this related to winxp SP2's security features perhaps? I've seen some "unsigned" programs that give a similar message as the firewall warnings. Just a thought.

Can you give more details?

M3PHiSTO
Posted By: Locoweed

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 07:43

The demo was cool Drew.

Great work Matt on the shaders.

Now all we need is a simple snippet of a working level with source so we can see how it is all put together. Hopefully someone puts up an example with the source included soon.

Loco
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 08:06

eveything you need to get it working is in my original post
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 08:57

Matt... any progress on the fallback code for PS 2 and 1.4?


--Mike
Posted By: Locoweed

Re: Ulitimate lighting shader pack v1.0 - 11/29/04 09:17

Very true Matt,

It still is nice to see some simple working source though, especially for us that are newer to shaders. I have been playing around with it for most of the day trying to get it working here, I am feeling a bit deflated I suppose. I am such a nOOb, heh. I'll keep plugging along.

Loco
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 04:20

hey... can Eric or Rhuarc or Matt post the dumbed down PS 2.0 version of the shader code for the level and model...

just the shader code that goes into the fx files...

i can't seem to get it working here... no errors, just no effects on either geometry or models.

using 6.31.4 and GeforceFX 5200 dx9c (Eric's demo ran fine)

btw, how do you assign the shader to a level geometry?


thx

--Mike
Posted By: Orange Brat

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 06:02

The shader runs on my GeForce FX 5200, but the framerate is very low.
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 06:07

it will be slow if you have a lot of lights in one area.. try making the light range smaller and using fewer lights at one time.. when the next beta is relased i will do a new version that will hopefully run faster by lowering the number of passes and lights. Also, if you are using it on level geometry make sure it the blocks are set to "flat" instead of shaded, and "tesselate flat" should be set to "auto"..
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 06:15

tesselate flat auto- is this a pro feature?
I dont see it...
Posted By: myrlyn68

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 06:35

It's an option in the map compiler popup if I remember right.
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 06:41

yeah its in the compile window.. this is absolutely critical to get good framerates in level geometry
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 06:42

MATT... the PS2 shader code... is it up anywhere...

i can't seem to do the mods correctly...


--Mike
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 08:01

no i ahvent done it yet..
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 08:06

k... thx


looking at Eric's code in the bug section... but shader makes objects invisible...

???


--Mike
Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 08:09

Quote:

MATT... the PS2 shader code... is it up anywhere...

i can't seem to do the mods correctly...


--Mike




Maybe this version will get you started in the right direction, Mike.

Be sure to change the Tangent in the vertex input to:
TEXCOORD2, insteas of TEXCOORD1.

web page
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 08:13

thx Eric... looking now...

[added]

model is invisible with shader applied... i'm doing something wrong...

actually, it's not invisible... the model is the same color as the background or fog ( i took out the fog)...

model is made with med, texture 0 is the skin, texure 1 is the normalmap...

16 bit in med

--Mike
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 12/01/04 16:49

check it out...cool shot of my characters shoulder, just thought I would share...hopefully updating the tutorial soon...



Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 12/02/04 09:04

Quote:

thx Eric... looking now...

[added]

model is invisible with shader applied... i'm doing something wrong...

actually, it's not invisible... the model is the same color as the background or fog ( i took out the fog)...

model is made with med, texture 0 is the skin, texure 1 is the normalmap...

16 bit in med

--Mike




Maybe you can make a small demo (pm a link) with it not working and I can see what is up with the thing.

16 bit in MED just may mean no mipmap levels??

Do you have mapping on the model that was made in MED?? Have you tried adding a normalmap to an existing model, for example Cbabe?? To see what happens.
Posted By: danthaman015

Re: Ulitimate lighting shader pack v1.0 - 12/02/04 12:59

This looks great!

Is there any way you could post a demo of this with the source code? When I copy/paste the formatting gets screwed up and I don't feel like fixing it. Also, someone like me would have a hard time setting it up I think...

Thanks,
Dan
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 12/02/04 19:41



-Test level-

Here is a small test scene, just to get it working.
Its just a room and a crate, but includes everything,
especially Steeempipe's juicy "2.0" version of the shader!!
Its very rough, and I might have messed up some of the code.
Be warned... I also included my Normal mapping tutorial, Its good for creation of normal maps.
The shader/A6 part is old (dx8.1), so skim it. The principals are the same, but look at this scene
and read the threads to get the DX9 version going in your project. (readme.txt)

Drew

Download it HERE
Posted By: Matt_Coles

Re: Ulitimate lighting shader pack v1.0 - 12/02/04 20:42

you're a legend drew, thanks,

MattColes
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/02/04 22:14

He's a Godsend...

Looking At it now...

THANKS again Drew...

and all the guys who have contributed.
i know that this represents a 'few' hours of hard work.

--Mike
Posted By: muralist

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 02:22

Thanks to all who built this .

SDrew, I see in the script that video screen is set to 1 but the demo is still windowed.
Posted By: DARKLORD

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 04:27

Hey great work!

But when I try to use the code i see the texture only for some seconds and then i get a black screen.

whats wrong?(I can play Drew's demo)

You can get my data here!

Thanks
Posted By: Gazzbass

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 04:31

Drew,

Absolutely stunning stuff by yourself and Steempipe! Awesome!

I have a couple of notes. I noticed in the mat_lighting.wdl that you had commented that only two lights work. I think this is because the shader code in normalmap_level_ps2.0.fx only makes provisions for two lights, i.e.:

Code:
 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 );

//LIGHT 1
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));

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



I guess its just a case of copying the code and pasting, then changing things like LightDir2 to LightDir3 and ViewDir2 to ViewDir3 etc.

Also, I altered the code within the light_pos_object action in mat_lighting.wdl to accomodate the new template scripts, since the demo came with the old ones.

Code:
 
var light_dist=2700; //Distance Light LOD...how far away from a light you can be until it shuts off/on


action light_pos_object
{
wait(5);
my.invisible=on;
my.passable=on;
//NewtonCreateGravityEntity (wood_material);
while(1)
{

if vec_dist(my.x, plBiped01_entity.x )<light_dist// or camera
{

my.light=on;
my.lightrange=1800; //could be set also to a skill

my.red= my.skill1; //just put in the r,g,b values
my.green= my.skill2;
my.blue= my.skill3;

my.cast=on; //casts a shadow when on
}

else
{
my.lightrange=0; //if too far away turn it off
my.light=off;
my.cast=off;

}

wait(1);

}



Hopefully this is the start of something BIG for 3DGS. I've been using it on and off since A4.12 but only recently got up a head of steam. It must be said that the Commercial Edition, at $199 is a total bargain considering what this development studio is capable of!
Posted By: Gazzbass

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 04:40

I had a similar problem, but I realised something was wrong when I got an empty pointer error "player.x", which is used in the old templates. I am using the new templates.

See post HERE

I also just got a new GeForce 6800GT, and I changed some of the shader code to PS3.0 (i.e. changed TEXCOORD2 to TEXCOORD1 in the vertex and pixel shader input STRUCTS, then in the technique two_pass section, I changed

VertexShader = compile vs_2_0 VS_PASS0();
PixelShader = compile ps_2_0 PS_PASS0();

to

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

I realise this limits potential customers somewhat at the moment, but I wanted to see the effect in all its glory so to speak!!!

Hope this helps some!
Posted By: Gazzbass

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 04:47

I got a nice ice effect with the shader, too! Its good stuff... pity we're limited to 8 dynamic lights...



Ooohhh, looks slippy!!!
Posted By: Gazzbass

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 05:37

Well, the copying and pasting of shader code with a change in subscript numbers didn't work... think its time to get me a book on DX9 shader programming instead of making guesses...
Posted By: TheExpert

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 06:04

Well , very good.

i have pixel shader V2 on my radeon 9800 Pro , but a lot of people have 3D cards
with 1.4 version, perhaps someone will adapt the code for them ?
a lot of people play Far Cry with shaders V1.4, that's just the engine that have differents versions of code i think.
But because it isn't a package included in official 3DGS download, that's not
perhaps necessary to adapt under V2 version ?
Posted By: danthaman015

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 07:16

Hmm Drew I downloaded your demo and it works but I don't see the shaders working. The rooms just bright. I thought it would work, I tested on two computers, one is a Radeon 9200 which does support shaders... is there something I need to download?

Thanks,
Dan
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 07:25

Update the driver for your card.
Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 07:54

Quote:

Hmm Drew I downloaded your demo and it works but I don't see the shaders working. The rooms just bright. I thought it would work, I tested on two computers, one is a Radeon 9200 which does support shaders... is there something I need to download?

Thanks,
Dan




9200 supports pixelshader.1.4. The card needs to support 2.0 or better.
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 07:59

Quote:

9200 supports pixelshader.1.4. The card needs to support 2.0 or better.




LOL, I don't know very much about ATI cards.
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 08:07

how are you guys doing performance wise... my moving water is slowing down, just able to notice it, and fraps shows around 14fps ...

--Mike
Posted By: Migueljb01

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 09:53

Hey Drew just one question how do you do the normal maps and specular maps for level geometry like in your example. Thanks.

-spider21
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 10:46

Find a good texture, save it. Make a B/W version, save it.
Run the black and white image through photoshops normal plugin (ati or nvidia's cant remember). copy the b/w version into the alpha channel of your normal map, save that as name_maps.
I included a turtorial with that download...
Posted By: Migueljb01

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 11:21

Wow thanks for the quick reply I'll go try that.

-spider21
Posted By: myrlyn68

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 12:26

http://www.zarria.net/

Here is a good bit of info for something that is a bit more accurate than just using a single grey scale image for the normal map.

I myself tend to model out most of my normal maps...it takes a bit longer (not too much since you don't have to worry about topology or polycounts) and then create the normal map from the actual mesh itself.
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 13:09

IMPORTANT:
my shader code uses an unflipped y in the normal map.. many dot3 converters flip the y in the normal automatically--including ATIs converter.. so basically if you use that make black the "highest" color and white the "lowest" so just invert your normal map(normally you think of white as the highest and black as the lowest). Some converters do have the option to change your y vector.. i suggest ORB (open render bump).
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 16:35

thanks matt! theres an option in the nvidia photoshop plug to flip y...

myrlyn68 - GREAT LINK! love the digital cam normal map technique! Excellent.

also, part of my tutorial is how to make a normal map from meshes in max, and exported to A6...

Anyone know a way to make a dynamic light for this shader? like a flashlight, or attached to a swinging physics lantarn...thx

Posted By: myrlyn68

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 17:10

I haven't had a chance to try this one out yet - but it looks as though normal dynamic lights should work with it.



As far as the tutorial goes...I would recomend a change (but he had already written such a nice one which covers most of it...). As opposed to using a normal flashlight, use something which will diffuse the light on your target object. I have a few photography flood lights in the studio which have diffusers on them for this purpose, but for those who don't have access to those try using a large sheet of white poster board. Shine the flashlight onto that and then "bounce" the reflected light onto your subject. This helps to avoid hot spots on the subject matter that will occur with certain materials (plastics, metals, polished wood/stone...) and ruin the normal map. This also becomes important if you are making a normal map of larger subjects.
Posted By: Thomas_Nitschke

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 22:45

These are great shots, Matt! How far down could we expect this to be converted, btw?
It would be cool to have those shaders working on g4 cards, too (PS 1.3)... would that be possible?
Posted By: DARKLORD

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 23:39

Thanks Gazzbass, but this doesn't help
i have only a black screen
Posted By: Gazzbass

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 23:46

Is anyone having texture tesselation matching problems when implementing this shader?

I tried using a tile texture with normal map in this test level, all unscaled, and got this:



The floor is a simple block, no CSG subtract operations done on it, etc, therefore its not an offset problem.

Is there some sort of translation matrix that can be tweaked within the shader code, or is it perhaps something really dumb that I'm overlooking? Any Ideas?

Anyway, I'm off to my book store to buy a book on DX9 HLSL!

Gary.
Posted By: Gazzbass

Re: Ulitimate lighting shader pack v1.0 - 12/03/04 23:58

Hi DARKLORD,

I don't know too much about ATI card shader versions (I have an nVidia GF6800GT), could you tell me what shader version your card supports?

Also, I have a test level using new template scripts and the shader converted to PS3.0. If you wish, I'll zip the folder up and give you a link for download. I could also try and convert the shader to your cards version.

Let me know.

Gary.
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 00:06

DArklord: make sure your blocks are all set to "flat"
Posted By: Peter Churness

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 03:09

Don't want to beat a dead horse, but I'll add my voice to the cries for pixelshader 1.4 support. Or at least get a consesus from the experts on this thread of:
1. Can it be done?
2. What would it look like?

My first born son to the whoever can get something close to these amazing effects working on 1.4 cards

Peter
Posted By: Rhuarc

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 03:40

Lol... but I'm too young to have kids

1. I've got a basic design done for a 1.4 version, but getting it to work has proven a royal pain in the bum . I'm afraid I might have to step back into ASM instead of HLSL .

2. It will actually looks pretty much just the same...unless you want to open two shots of it in photoshop and compare pixel-level differences by looking at the hex you won't notice any difference .

In any case... it's getting there . My latest progress is in ASM and it compiles without errors- but it renders the level in unlit blue...

-Rhuarc

PS: You gonna be in town this weekend?
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 03:46

I've got the models shader working great... but for the life of me, i can't get the level geomtry shader working... texture and lighting seem ok, but no bumpmapping...

(1) am i supposed to apply it to a map entity?

(2) if no, how do i associate the material with a block?

i am using textures from a folder not a wad...



thx... i feel so helpless when it comes to this shader stuff


--Mike
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 04:00

Quote:

i am using textures from a folder not a wad...




You have to have the texture that you want to bumpmap in your .wad and the normal map in your folder. Change the name of the material to the name of your wad texture and add var d3d_automaterial = 1; at the top of your script.
Also be sure to apply the texture that you want to bumpmap to a level block.
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 04:36

thx hsb... did that about 2 hours ago... it seems as if i'm having a problem with fog...

i had to set the NoFog option on my model to get it to be seen... and it appears that the same holds true for the level block...

i set the level fog to 0 0 0 but it doesn't seem to help

i also made a map entity out of it, so that i could assign the material directly to it... that worked, but the scale of the texture was about 100th of the original size...


talk about frustration... anyway, thx again...


--Mike
Posted By: Gazzbass

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 04:49

When I assigned the "Flat" flag to all level geometry, I got the same, "tiny texture" scaling problem.

It seemed to be a vertex shader scaling problem so I found the following line in the vertex shader code section:

Out.Tex = texcoord0.xy*50;

This deals with texture scaling. So instead of texcoord0.xy*50, I messed around with smaller values like texcoord0.xy*3 and got results, but with tesselation problems. I just bought a Direct3D book and am furiously trying to learn HLSL and texture mapping theory...

Anyway, give this a whirl (I think messing with the HLSL code and viewing the results helps the learning experience!)

Gary.
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 05:06

sounds like a plan Gazz... the map entities seem to shader up ok, with just that one exception... thx... i'll look into it...

man... my head's startin' to hurt...


--Mike
Posted By: Gazzbass

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 05:15

LOL!
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 15:58

1.4 support can of course be added.. i have an asm shader that works. I suggest modifying my orignal asm dx8 shader to run in dx9.. its a quite a trivial task.. just fix the syntax and change a little in the vertex shader.

Eventually i plan on making a ps 2.0 and 1.4 fallback for my HLSL shader but right now.. maybe someone else can do this if they want... its not a big deal really.
Posted By: DARKLORD

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 21:07

Thanks for your help, but this wasn't the error.
There is a problem with the display00.wdl.
If I don't use this wdl then there are no problems

PS: It looks great and the fps are also very good!!!
Posted By: DARKLORD

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 21:58

Can somebody tell me why i can't change the lightrange!

There are only 2 possibilities:
1. The lightrange from the dynamic light is 0 then there is no light
or
2. The lightrange from the dynamic light is >0 then there always the same lightrange!(There is no difference between 1 and 10000)

Can somebody help?
Posted By: Rhuarc

Re: Ulitimate lighting shader pack v1.0 - 12/04/04 23:30

Could you post your dx9 version of the ASM one?

-Rhuarc
Posted By: Gazzbass

Re: Ulitimate lighting shader pack v1.0 - 12/05/04 07:01

Matt,

I just want to say thank you on behalf of all of us for this shader work! I worked out my normal map tesselation problem and I'm now using flat color textures with detailed normal maps and the results are truly awesome! With a little attenuation and gloss tweaking, I can get great bump and specular effects! Here's a shot of how it stands now, very doom-like in appearance!



I think I'll stick with this formula if it checks out OK on my other PC's (mixture of hardware).

Thanks for the great work!

Gary.

P.S. Ignore the gun model!!!
Posted By: Matt_Coles

Re: Ulitimate lighting shader pack v1.0 - 12/05/04 12:43

In Drew and Steempipes 2.0 version is there anyway to get more than 2 dynamic lights working?

Thanks,

Matt
Posted By: Steempipe

Re: Ulitimate lighting shader pack v1.0 - 12/05/04 12:46

I would suspect that adding more passes would work at a cost to framerate. I have not changed any code to accomplish this, but looking at Matt A's original code might get you in the right direction.
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 12/05/04 12:59

I believe in PS 2.0 you can probably render a maximum of two per pixel lights per pass.. so 8 lights is 4 passes. i recommend doing only 6 lights..that should be 3 passes..
Posted By: Red Ocktober

Re: Ulitimate lighting shader pack v1.0 - 12/05/04 13:42

great looking stuff Gazz...

and i want to second your appreciation and thanks to Matt and Drew And Steem... and all those who helped with this...

you guys are all in my will...


--Mike
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 12/08/04 18:58

anybody have problems with sorting on your normal mapped entities? Im creating them in max using polybump (crytek),
everything is good except when my character turns i can see through him to the other side, the normals all face out though... it only happens at certain angles...

thanks
Posted By: Matt_Coles

perpixel ps2 - 4 lights! - 12/17/04 07:51

I edited Matt's code and converted it down to ps2.0 with 4 lights working!
Here's a screenshot:



In line 141 of the level_normal mapping file you can change the ambience of the level, all textures have to be flat else they screw up etc etc


Normal Mapping Level FX File Code:

// -------------------------------------------------------------
// Diffuse and specular shader for world geometry
// -------------------------------------------------------------
//this is a 3 pass shader rendering 3 lights in each pass,3 rd pass has the last light

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

texture entSkin1; //this is the color map
texture mtlSkin1; //this is the normal map..define in your shader defs

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


sampler BumpMapSampler = sampler_state
{
Texture = <mtlSkin1>;
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;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

//light 1
float3 Light1 = PosWorld - vecLightPos[1] ;
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[2] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

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

Out.Att2 = Light2 * LightRange; // 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;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//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));

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

);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//second pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

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

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

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


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

float3 Viewer4 = PosWorld - vecViewPos;
Out.View4 = mul(worldToTangentSpace, -Viewer4); // V

Out.Att4 = Light4 * LightRange; // Point light
return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
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 );

//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));

//light4
float3 LightDir4 = normalize(psInStruct.Light4);
float3 ViewDir4 = normalize(psInStruct.View4);
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, ViewDir4)), 15);
float4 Attenuation4 = saturate(dot(psInStruct.Att4, psInStruct.Att4));

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


);
}

// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique three_pass
{
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();
}
}



And Normal Mapping Entity FX File Code



// -------------------------------------------------------------
// Diffuse and specular shader for models
// -------------------------------------------------------------
//this is a 3 pass shader rendering 3 lights in each pass,3 rd pass has the last light

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

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;
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//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;
};

// -------------------------------------------------------------
// 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 = 0.01;

//light 1
float3 Light1 = PosWorld - vecLightPos[1] ;
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[2] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

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

Out.Att2 = Light2 * LightRange; // 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;

};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//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));

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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//second pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.01;

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

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

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


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

float3 Viewer4 = PosWorld - vecViewPos;
Out.View4 = mul(worldToTangentSpace, -Viewer4); // V

Out.Att4 = Light4 * LightRange; // Point light
return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
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 );

//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));

//light4
float3 LightDir4 = normalize(psInStruct.Light4);
float3 ViewDir4 = normalize(psInStruct.View4);
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, ViewDir4)), 15);
float4 Attenuation4 = saturate(dot(psInStruct.Att4, psInStruct.Att4));

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

);
}

// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique two_pass
{
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();
}
}


Then You Just Use Matt's Standard Lighting Shader Code And Effect Loading Code (You Can Get It At The Start Of The Thread)
Also to make the dynamic shadows appear nicer on the level geometry and stuff put this line in your levels main function:

mat_shadow.alpha = 25;

Enjoy:)

Matt Coles
Posted By: Blattsalat

Re: perpixel ps2 - 4 lights! - 12/17/04 08:45

I am kind of impressed right now... very impressed by the quality.

need to test it asap.
Posted By: Drew

Re: perpixel ps2 - 4 lights! - 12/17/04 08:48

AWESOME!!!!! (screams like little kid)
I was getting a little tired of 2 lights...not complaining though!!
thanks! (especially for 2.0 support)
Posted By: Matt_Coles

Re: perpixel ps2 - 4 lights! - 12/17/04 08:58

You guys are welcome, I might make a small test level for people, but I'll need to find a place to upload it unless drew is going to make one.
I'm going to try to slowly incorporate up to 7 lights and the sun, or 8 lights and no sun.


Matt Coles
Posted By: Drew

Re: perpixel ps2 - 4 lights! - 12/17/04 09:04

maybe I can plug it into my other demo, but no promises..no time right now... 8 lights, or even 7...Drool
Posted By: Matt_Coles

Re: perpixel ps2 - 4 lights! - 12/17/04 14:30

It should be able to plug straight into the other demo
Is the code working well for everybody?

Matt Coles
Posted By: Matt_Coles

perpixel ps2 - 7 lights!!!! - 12/17/04 16:53

Okay, this is one mother! 7 Lights and bad frame rate (like 27fps on an 9800 pro) with all lights on

Screenshot:





Level Geometry Code:

// -------------------------------------------------------------
// Diffuse and specular shader for world geometry
// -------------------------------------------------------------
//this is a 3 pass shader rendering 3 lights in each pass,3 rd pass has the last light

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

texture entSkin1; //this is the color map
texture mtlSkin1; //this is the normal map..define in your shader defs

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


sampler BumpMapSampler = sampler_state
{
Texture = <mtlSkin1>;
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;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

//light 1
float3 Light1 = PosWorld - vecLightPos[1] ;
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[2] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

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

Out.Att2 = Light2 * LightRange; // 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;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//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));

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

);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//second pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

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

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

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


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

float3 Viewer4 = PosWorld - vecViewPos;
Out.View4 = mul(worldToTangentSpace, -Viewer4); // V

Out.Att4 = Light4 * LightRange; // Point light
return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
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 );

//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));

//light4
float3 LightDir4 = normalize(psInStruct.Light4);
float3 ViewDir4 = normalize(psInStruct.View4);
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, ViewDir4)), 15);
float4 Attenuation4 = saturate(dot(psInStruct.Att4, psInStruct.Att4));

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


);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//third pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT2
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light5 : TEXCOORD2;
float3 View5 : TEXCOORD3;
float3 Att5 : TEXCOORD4;

float3 Light6 : TEXCOORD5;
float3 View6 : TEXCOORD6;
float3 Att6 : TEXCOORD7;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

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

float3 Viewer5 = PosWorld - vecViewPos;
Out.View5 = mul(worldToTangentSpace, -Viewer5); // V

Out.Att5 = Light5 * LightRange; // Point light

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

float3 Viewer6 = PosWorld - vecViewPos;
Out.View6 = mul(worldToTangentSpace, -Viewer6); // V

Out.Att6 = Light6 * LightRange; // Point light
return Out;
}


struct PS_INPUT2
{
float2 Tex : TEXCOORD0;

float3 Light5 : TEXCOORD2;
float3 View5 : TEXCOORD3;
float3 Att5 : TEXCOORD4;

float3 Light6 : TEXCOORD5;
float3 View6 : TEXCOORD6;
float3 Att6 : TEXCOORD7;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//light5
float3 LightDir5 = normalize(psInStruct.Light5);
float3 ViewDir5 = normalize(psInStruct.View5);
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, ViewDir5)), 15);
float4 Attenuation5 = saturate(dot(psInStruct.Att5, psInStruct.Att5));

//light2
float3 LightDir6 = normalize(psInStruct.Light6);
float3 ViewDir6 = normalize(psInStruct.View6);
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, ViewDir6)), 15);
float4 Attenuation6 = saturate(dot(psInStruct.Att6, psInStruct.Att6));

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

);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//fourth pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT3
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT3 VS_PASS3(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0 )
{
VS_OUTPUT3 Out = (VS_OUTPUT3)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 = 0.002;

//light 7
float3 Light7 = PosWorld - vecLightPos[7] ;
Out.Light7.xyz = mul(worldToTangentSpace, -Light7); // L

float3 Viewer7 = PosWorld - vecViewPos;
Out.View7 = mul(worldToTangentSpace, -Viewer7); // V

Out.Att7 = Light7 * LightRange; // Point light

return Out;
}


struct PS_INPUT3
{
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

float4 PS_PASS3( PS_INPUT3 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 );

//light7
float3 LightDir7 = normalize(psInStruct.Light7);
float3 ViewDir7 = normalize(psInStruct.View7);
float4 diff7 = saturate(dot(bumpNormal, LightDir7)); // diffuse component
float shadow7 = saturate(4 * diff7);
float3 Reflect7 = normalize(2 * diff7 * bumpNormal - LightDir7); // R
float4 spec7 = pow(saturate(dot(Reflect7, ViewDir7)), 15);
float4 Attenuation7 = saturate(dot(psInStruct.Att7, psInStruct.Att7));

return
(
((shadow7 * (color * diff7 + (spec7*gloss.w)) * (1 -Attenuation7))*vecLightColor[7])
);
}


// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique three_pass
{
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();
}

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

// compile shaders
VertexShader = compile vs_2_0 VS_PASS3();
PixelShader = compile ps_2_0 PS_PASS3();
}
}






Entity Code:

// -------------------------------------------------------------
// Diffuse and specular shader for models
// -------------------------------------------------------------
//this is a 3 pass shader rendering 3 lights in each pass,3 rd pass has the last light

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

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;
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//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;
};

// -------------------------------------------------------------
// 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 = 0.002;

//light 1
float3 Light1 = PosWorld - vecLightPos[1] ;
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[2] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

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

Out.Att2 = Light2 * LightRange; // 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;

};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//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));

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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//second pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

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

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

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


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

float3 Viewer4 = PosWorld - vecViewPos;
Out.View4 = mul(worldToTangentSpace, -Viewer4); // V

Out.Att4 = Light4 * LightRange; // Point light
return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
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 );

//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));

//light4
float3 LightDir4 = normalize(psInStruct.Light4);
float3 ViewDir4 = normalize(psInStruct.View4);
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, ViewDir4)), 15);
float4 Attenuation4 = saturate(dot(psInStruct.Att4, psInStruct.Att4));

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

);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//third pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT2
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light5 : TEXCOORD2;
float3 View5 : TEXCOORD3;
float3 Att5 : TEXCOORD4;

float3 Light6 : TEXCOORD5;
float3 View6 : TEXCOORD6;
float3 Att6 : TEXCOORD7;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

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

float3 Viewer5 = PosWorld - vecViewPos;
Out.View5 = mul(worldToTangentSpace, -Viewer5); // V

Out.Att5 = Light5 * LightRange; // Point light

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

float3 Viewer6 = PosWorld - vecViewPos;
Out.View6 = mul(worldToTangentSpace, -Viewer6); // V

Out.Att6 = Light6 * LightRange; // Point light
return Out;
}


struct PS_INPUT2
{
float2 Tex : TEXCOORD0;

float3 Light5 : TEXCOORD2;
float3 View5 : TEXCOORD3;
float3 Att5 : TEXCOORD4;

float3 Light6 : TEXCOORD5;
float3 View6 : TEXCOORD6;
float3 Att6 : TEXCOORD7;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//light5
float3 LightDir5 = normalize(psInStruct.Light5);
float3 ViewDir5 = normalize(psInStruct.View5);
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, ViewDir5)), 15);
float4 Attenuation5 = saturate(dot(psInStruct.Att5, psInStruct.Att5));

//light2
float3 LightDir6 = normalize(psInStruct.Light6);
float3 ViewDir6 = normalize(psInStruct.View6);
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, ViewDir6)), 15);
float4 Attenuation6 = saturate(dot(psInStruct.Att6, psInStruct.Att6));

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

);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//fourth pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT3
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT3 VS_PASS3(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0 )
{
VS_OUTPUT3 Out = (VS_OUTPUT3)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 = 0.002;

//light 7
float3 Light7 = PosWorld - vecLightPos[7] ;
Out.Light7.xyz = mul(worldToTangentSpace, -Light7); // L

float3 Viewer7 = PosWorld - vecViewPos;
Out.View7 = mul(worldToTangentSpace, -Viewer7); // V

Out.Att7 = Light7 * LightRange; // Point light

return Out;
}


struct PS_INPUT3
{
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

float4 PS_PASS3( PS_INPUT3 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 );

//light7
float3 LightDir7 = normalize(psInStruct.Light7);
float3 ViewDir7 = normalize(psInStruct.View7);
float4 diff7 = saturate(dot(bumpNormal, LightDir7)); // diffuse component
float shadow7 = saturate(4 * diff7);
float3 Reflect7 = normalize(2 * diff7 * bumpNormal - LightDir7); // R
float4 spec7 = pow(saturate(dot(Reflect7, ViewDir7)), 15);
float4 Attenuation7 = saturate(dot(psInStruct.Att7, psInStruct.Att7));

return
(
((shadow7 * (color * diff7 + (spec7*gloss.w)) * (1 -Attenuation7))*vecLightColor[7])
);
}


// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique three_pass
{
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();
}

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

// compile shaders
VertexShader = compile vs_2_0 VS_PASS3();
PixelShader = compile ps_2_0 PS_PASS3();
}
}


Now to incorporate the sun... And Find a nice way to add up not having shaded level geometry. Dynamic shadows? Or Texture Projectors?


Anywayz, Enjoy

Matt Coles
Posted By: Drew

Re: perpixel ps2 - 7 lights!!!! - 12/17/04 19:43

I'm loving it. THANK YOU.
Just messing around with 5 lights shows great results...
my 9600 starts to chug a bit at 5, and REALLY slows at 8, but thats okay...


Posted By: Matt_Coles

Re: perpixel ps2 - 7 lights!!!! - 12/18/04 08:45

I think we should implement a trigger system along with the light distance system so we can only have the number of lights we want in the scene and not 7 the whole time.

Also the sun is coming along well

MattColes
Posted By: Drew

Re: perpixel ps2 - 7 lights!!!! - 12/18/04 08:49

that is an EXCELLENT idea! This way you turn on and off your objects around hall corners, behind doors... also maybe another way (maybe easier or cheaper) is a view distance around the player that turns them on and off, just never make your hall/room bigger than that value...

Can the sun double as a n ambient reflective lightsource, like in EA games (boxing, defjam NY)
Posted By: Matt_Coles

Re: perpixel ps2 - 7 lights!!!! - 12/18/04 08:51

Should be able to

Matt Coles
Posted By: Nadester

Re: perpixel ps2 - 7 lights!!!! - 12/18/04 13:48

Code:
action light_pos_object{

wait(5);
my.invisible=on;
my.passable=on;

while(1){

vec_set(temp,my.x);
if (vec_to_screen(temp,camera)){

my.light=on;
my.lightrange=300; //could be set also to a skill

my.red=my.skill1; //just put in the r,g,b values
my.green=my.skill2;
my.blue=my.skill3;

my.cast=on; //casts a shadow when on
}

else{
my.lightrange=0; //if too far away turn it off
my.light=off;
my.cast=off;

}

wait(1);
}
}



Use that for your dynamic light action. That *should* only show a light if it is on the screen itself, though I havn't tried it out. It would be better to use trace though I suppose... Let me know if it bugs out though, and I'll fix it.
Posted By: Matt_Aufderheide

Re: perpixel ps2 - 7 lights!!!! - 12/18/04 16:59

I dont think using light code such as that is a good idea.. if the light is behind the camera.. it could still affect the faces that are visible...so you will get lights blinking out and on..better to use a simple range-based approach as in my example.
Posted By: Drew

Re: perpixel ps2 - 7 lights!!!! - 12/19/04 13:44

anothher idea is attaching a light to the player, like a torch or flashlight...then you can concentrate on that source and others are just ambient...
or a flare object too...
Posted By: Matt_Coles

Re: perpixel ps2 - 7 lights!!!! - 12/19/04 17:15

I've attached a torch to the player and it worked well , what I was thinking of doing is having a trigger set off by the player walking through hollow blocks which you'd place in corridors about a room or two before the light
Posted By: Drew

Re: perpixel ps2 - 7 lights!!!! - 12/19/04 17:34

how did you do it? attach entity? or just in player code?
any code to share? I'll try again too...
thanks
Posted By: Matt_Coles

Re: perpixel ps2 - 7 lights!!!! - 12/19/04 17:56

I posted something like this into the players script:

my.light = ON; // illuminate myself
my.lightrange=2000; //could be set also to a skill


my.red=my.skill1; //just put in the r,g,b values
my.green=my.skill2;
my.blue=my.skill3;

and it worked fine, a real flashlight held by the player should not be much harder to implement
Posted By: Matt_Coles

Re: perpixel ps2 - 7 lights!!!! - 12/22/04 15:26

I've converted olivers env and spec shaders so that they work outside with the sun on level geometry now.
Slowly getting a move along
I'm hoping to release everything as sort of a shader pack. My project for the holidays
Posted By: Drew

Re: perpixel ps2 - 7 lights!!!! - 12/28/04 16:30

LOVE NORMAL MAPPING!!
made a test of normal mapping from a high poly model, using polybump plugin...Hint: use cylinder mapping! best way to get a smooth seamless normal map...


Posted By: Drew

Re: perpixel ps2 - 7 lights!!!! - 12/29/04 21:43




Heres a new demo, just player control and some actor follows...tgought it was cool and wanted to share the organic possibilities for skin...
The characters are 800 polys each, with normal maps made from 600,000 poly original.

Download HERE



.
Posted By: Matt_Coles

Re: perpixel ps2 - 7 lights!!!! - 12/30/04 16:19

Extremely nice work drew, what program did you use to make the normal maps again?
Posted By: Drew

Re: perpixel ps2 - 7 lights!!!! - 12/30/04 16:27

used polybump, its a free normal tool that comes with the Farcry SDK... important thing is that it uses the same UVW set... its amazing the diffrence a true normal map makes as opposed to a converted texture map.
Posted By: PHeMoX

Re: perpixel ps2 - 7 lights!!!! - 12/30/04 22:56

Yeah, also the photoshop plug-in somehow does weird with some textures I try to make a normal map for...
So I think I'll download the FarCry SDK (or is it included on the dvd?)

Cheers
Posted By: Drew

Re: perpixel ps2 - 7 lights!!!! - 12/31/04 05:00

polybump is part of the sdk download, its a max and maya plugin... you need a very highpoly model that is uvw mapped, create a low version (multires) and run them both through polybump... it can be a frustrating experience, it took my months to finally get it to work with minimal seams and shared UVW.
Posted By: PHeMoX

Re: perpixel ps2 - 7 lights!!!! - 12/31/04 05:40

Mmmm, I doubt my version of 3d max works with it though, but I can't try it out now anyways...
How high poly should it be to have a notable effect? I heard some guys talking rather extreme; from 300.000 polys to 2600 or so...
Posted By: Matt_Coles

Re: perpixel ps2 - 7 lights!!!! - 01/12/05 19:02

Going to wait until A6.4 is released with Octree as having some real bad frame rate problems with the sun (ATi 9800 pro's run with 1 fps) before I release the new code, also it's more of an editted shader pack now, looks real mean, especially with bloom. I'll just work on some new scripts and shaders whilst waiting for A6.4...



Matt Coles
Posted By: zazang

Re: perpixel ps2 - 7 lights!!!! - 02/07/05 14:34

Hi

I just tried the Normal mapping PS2.0 code on a level block and the code works awesome!
I'm running it on a Ati 9600 xt.

Great thanks to Matt,Drew,Steampipe and all others who built the code!!!

Btw here is one good link for normal mapping I found :-

http://www.monitorstudios.com/bcloward/tutorials_normal_maps1.html

zazang
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 02/09/05 10:08

Hey Matt or anyone else, 2 questions-

- How can I change the position of the highlite of the light pos object? Ive attached light code to my player but the reflection is offset...
- How can I use fog with this shader?

thanks!
Posted By: Matt_Coles

Re: Ulitimate lighting shader pack v1.0 - 02/09/05 12:49

Fog should be easy to incorporate, what do you mean by highlight of the light_pos_object? As the position of the actual light? That depends on what object is casting it and where it is placed. Or the intensity of the highlight?
Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 02/09/05 19:32

The specular highlight is calculated in the standard way using the Blinn simplification..it based on the halfvector between the angle of light incidence and view position...theres no reason to move it around. The lighting should be correct from all angles.

Using fog is not difficult. just add this stuff to the first pass:
fist declare these at he beginning:
float4 vecViewPos;
float4 vecFog;

thi in the vs output struct:
float Fog : FOG;

then in the vertex shader:
float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z);
Out.Fog = ofog;

now you must do the same thing for the otehr passes, except vertex shaders put this instead:
Out.Fog = 10000;
the resaon is you only want to calculate foging correctly one the first pass, the passes you make fog way way out so it is bascially disabled. Then you should get corect fog color. Just make sure you lights arent visible form a long way away.
Posted By: Drew

Re: Ulitimate lighting shader pack v1.0 - 02/10/05 04:47

Thanks Matt! I appreciate the help
Posted By: VampireLord

Re: Ulitimate lighting shader pack v1.0 - 02/24/05 07:04

Thank you guys, just thank you....

I just wanted to mention that if anybody should need webspace for uploading shaders and shader demos I would be more than happy to supply it!

And if anybody would be interested in making a kick as demo of this new shader I would like to invite him to join me... I am thinking of making a larger level...like the Bronx level just with this shader!
So any modeller and 2d graphics guru as well as you shader guys, feel free to contact me under webmaster@team-blacksun.de

Cu
and thx again

Greetz
VampireLord
Posted By: Gafgar

Re: Ulitimate lighting shader pack v1.0 - 03/01/05 05:10

i got an malfunction... it says:
malfunction W1550
error in effect:
your_world_texture_normalmap_tag

does any one had the same problem or is able to help me?
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 05/07/05 22:49

Would it be possible to chop this thing down to where it maybe doesn't have the normalmapping, still has 7 per-pixel dynamic lights and works on vs and ps1.1?

Code:
 // -------------------------------------------------------------
// Diffuse and specular shader for world geometry
// -------------------------------------------------------------
//this is a 3 pass shader rendering 3 lights in each pass,3 rd pass has the last light

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

texture entSkin1; //this is the color map
texture mtlSkin1; //this is the normal map..define in your shader defs

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


sampler BumpMapSampler = sampler_state
{
Texture = <mtlSkin1>;
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;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

//light 1
float3 Light1 = PosWorld - vecLightPos[1] ;
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[2] ;
Out.Light2.xyz = mul(worldToTangentSpace, -Light2); // L

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

Out.Att2 = Light2 * LightRange; // 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;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//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));

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

);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//second pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT1
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

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

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

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


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

float3 Viewer4 = PosWorld - vecViewPos;
Out.View4 = mul(worldToTangentSpace, -Viewer4); // V

Out.Att4 = Light4 * LightRange; // Point light
return Out;
}


struct PS_INPUT1
{
float2 Tex : TEXCOORD0;

float3 Light3 : TEXCOORD2;
float3 View3 : TEXCOORD3;
float3 Att3 : TEXCOORD4;

float3 Light4 : TEXCOORD5;
float3 View4: TEXCOORD6;
float3 Att4 : TEXCOORD7;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------
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 );

//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));

//light4
float3 LightDir4 = normalize(psInStruct.Light4);
float3 ViewDir4 = normalize(psInStruct.View4);
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, ViewDir4)), 15);
float4 Attenuation4 = saturate(dot(psInStruct.Att4, psInStruct.Att4));

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


);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//third pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT2
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light5 : TEXCOORD2;
float3 View5 : TEXCOORD3;
float3 Att5 : TEXCOORD4;

float3 Light6 : TEXCOORD5;
float3 View6 : TEXCOORD6;
float3 Att6 : TEXCOORD7;
};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
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);
float LightRange = 0.002;

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

float3 Viewer5 = PosWorld - vecViewPos;
Out.View5 = mul(worldToTangentSpace, -Viewer5); // V

Out.Att5 = Light5 * LightRange; // Point light

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

float3 Viewer6 = PosWorld - vecViewPos;
Out.View6 = mul(worldToTangentSpace, -Viewer6); // V

Out.Att6 = Light6 * LightRange; // Point light
return Out;
}


struct PS_INPUT2
{
float2 Tex : TEXCOORD0;

float3 Light5 : TEXCOORD2;
float3 View5 : TEXCOORD3;
float3 Att5 : TEXCOORD4;

float3 Light6 : TEXCOORD5;
float3 View6 : TEXCOORD6;
float3 Att6 : TEXCOORD7;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

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 );

//light5
float3 LightDir5 = normalize(psInStruct.Light5);
float3 ViewDir5 = normalize(psInStruct.View5);
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, ViewDir5)), 15);
float4 Attenuation5 = saturate(dot(psInStruct.Att5, psInStruct.Att5));

//light2
float3 LightDir6 = normalize(psInStruct.Light6);
float3 ViewDir6 = normalize(psInStruct.View6);
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, ViewDir6)), 15);
float4 Attenuation6 = saturate(dot(psInStruct.Att6, psInStruct.Att6));

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

);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//fourth pass
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------
// Output channels
// -------------------------------------------------------------
struct VS_OUTPUT3
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;

};

// -------------------------------------------------------------
// vertex shader function (input channels)
// -------------------------------------------------------------
VS_OUTPUT3 VS_PASS3(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float3 Normal : NORMAL, float3 Tangent : TEXCOORD0 )
{
VS_OUTPUT3 Out = (VS_OUTPUT3)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 = 0.002;

//light 7
float3 Light7 = PosWorld - vecLightPos[7] ;
Out.Light7.xyz = mul(worldToTangentSpace, -Light7); // L

float3 Viewer7 = PosWorld - vecViewPos;
Out.View7 = mul(worldToTangentSpace, -Viewer7); // V

Out.Att7 = Light7 * LightRange; // Point light

return Out;
}


struct PS_INPUT3
{
float2 Tex : TEXCOORD0;

float3 Light7 : TEXCOORD2;
float3 View7 : TEXCOORD3;
float3 Att7 : TEXCOORD4;
};

// -------------------------------------------------------------
// Pixel Shader (input channels):output channel
// -------------------------------------------------------------

float4 PS_PASS3( PS_INPUT3 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 );

//light7
float3 LightDir7 = normalize(psInStruct.Light7);
float3 ViewDir7 = normalize(psInStruct.View7);
float4 diff7 = saturate(dot(bumpNormal, LightDir7)); // diffuse component
float shadow7 = saturate(4 * diff7);
float3 Reflect7 = normalize(2 * diff7 * bumpNormal - LightDir7); // R
float4 spec7 = pow(saturate(dot(Reflect7, ViewDir7)), 15);
float4 Attenuation7 = saturate(dot(psInStruct.Att7, psInStruct.Att7));

return
(
((shadow7 * (color * diff7 + (spec7*gloss.w)) * (1 -Attenuation7))*vecLightColor[7])
);
}


// -------------------------------------------------------------
// techniques//
// -------------------------------------------------------------
technique three_pass
{
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();
}

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

// compile shaders
VertexShader = compile vs_2_0 VS_PASS3();
PixelShader = compile ps_2_0 PS_PASS3();
}
}


Posted By: Matt_Aufderheide

Re: Ulitimate lighting shader pack v1.0 - 05/07/05 23:12

I suppose it could be done, but im not going to :P With ps 1_1 you are better off using assembly instead of HLSL anyway.
Posted By: Josh_Arldt

Re: Ulitimate lighting shader pack v1.0 - 05/08/05 02:09

Quote:

you are better off using assembly instead of HLSL anyway.




I figured that.
The best way would be just to write it from scratch huh?
Posted By: XNASorcerer

Re: Ulitimate lighting shader pack v1.0 - 08/13/05 16:02

Matt_Aufderheide,
I am trying to use your shader converted to ps_2, but it gives me the following error message:
Error in effect:
your_world_texture_normalmap_tga(187):error X4502: invalida output semantic 'TEXCOORD9'(416): ID3DXEffectCompile::CompileEffect: There was an error compliling expresion ID3DXEffect

compiler: Compilation failed.

Can you help me?
Posted By: slacker

stumped - 08/16/05 17:13

Struggling to get this up and running. I went through many of the issues others have here and made alot of progress - and now have the model showing up not black and the normal map appears to be showing through, but has issues:

1) the light cuts off abruptly
2) the spec doesn't seem to be doing anything - I have a radial black to white gradient in the alpha of the color map (have tried a bunch of things here)
3)The surface doesn't look bumpy - the low areas are white and the high areas are grey.
4) light range doesn't seem to have an affect. The light always seems to have a range of about 300.

- and finally stripped everything down to the most basic level. Hopefully didn't strip out too much.

Running 6800 forceware 77.77 - GS 6.314 commercial - here is my data


model fx file
world fx file
model 2.0 fx file
wmb
wdl
screen shot
model
tga normal map

I have tried the 2.0 version, although my card is speced for 3.0. I have tried using maps with and without alpha for both the color and normal map.

I am just working on getting the model shader working right now - world shader is another story.

Any help is always appreciated. Somehow I suspect my videocard and drivers, although I have updated to the latest dx9c and nvidia drivers.



Right now the sphere model color map is only grey with a normal map in skin 2 - as I am just trying to see the normal mapping working right now.

oh-- It says that the fx files need to be in the 'worlds' folder. I tried making a folder named worlds and putting them in it, but they were not found - then moved them back to the root and no longer got the error - so I assumed the 'world' folder meant the folder with your world data in it?
Posted By: Matt_Coles

Re: stumped - 08/18/05 23:57

have a look at this page, there is a file and test example of normal mapping as well as other shaders

http://www.coniserver.net/ubbthreads/showflat.php?Cat=0&Number=548704&an=0&page=0#548704

Matt Coles
Posted By: Schmerzmittel

Re: Ulitimate lighting shader pack v1.0 - 08/19/05 17:49

Hallo an alle!

Ich bin hier neu und arbeite das erste mal mit dem Gamestudio. Ich hätte da ein paar Fragen.

1. Ich habe mich mit den Tutorials eingearbeitet und auch mit dem scripten. Bis jetzt funktioniert alles sehr gut. Ich wollte den Shaderpack installieren, aber leider weiß ich nicht genau wie. Alle Scripts werden fehlerlos erkannt aber ich sehe nichts.
Könnte jemand eine genaue Schritt für Schritt Anleitung hier reinstellen, damit auch die Anfänger alles etwas leichter verstehen? Wäre sehr nett von euch.

2. Ich habe mal wo gelesen, dass man die Dynamischen Lichter nach einer gewissen Entfernung abschalten kann, so dass immer 8 gleichzeitig zu sehen sind. Wie geht das nochmal? Finde den Artikel nicht mehr. Danke schon mal im Vorraus.

3. Wie weiße ich per Script einem Model, oder einem World objekt den Shader zu?
Ich kenne zwar das:
Z.B.

material spec_bump_model
{
my.material=spec_bump_model;
}

Aber wie weiße ich es z.b. einem Stuhl zu oder einer Fließe?
Bitte helft mir.

P.S. Ich habe auch die Suchfunktion verwendet, konnte aber keine hilfreichen Artikel finden. Sorry.

Grüße

Schmerzmittel
Posted By: Matt_Coles

Re: Ulitimate lighting shader pack v1.0 - 08/21/05 00:21

action apply_model
{
my.material = spec_bump_model;
}


you have to apply the material through an action, then apply that action to the model in wed. Hope this helps,

Matt Coles
Posted By: NMS

Re: Ulitimate lighting shader pack v1.0 - 08/28/05 09:56

I know this look like a stupid question... but i'm a newbie.. :S

what is this? ------> "your_world_texture_normalmap_tga"???
Posted By: NMS

Re: stumped - 08/29/05 10:47

Quote:

Struggling to get this up and running. I went through many of the issues others have here and made alot of progress - and now have the model showing up not black and the normal map appears to be showing through, but has issues:

1) the light cuts off abruptly
2) the spec doesn't seem to be doing anything - I have a radial black to white gradient in the alpha of the color map (have tried a bunch of things here)
3)The surface doesn't look bumpy - the low areas are white and the high areas are grey.
4) light range doesn't seem to have an affect. The light always seems to have a range of about 300.

- and finally stripped everything down to the most basic level. Hopefully didn't strip out too much.

Running 6800 forceware 77.77 - GS 6.314 commercial - here is my data


model fx file
world fx file
model 2.0 fx file
wmb
wdl
screen shot
model
tga normal map

I have tried the 2.0 version, although my card is speced for 3.0. I have tried using maps with and without alpha for both the color and normal map.

I am just working on getting the model shader working right now - world shader is another story.

Any help is always appreciated. Somehow I suspect my videocard and drivers, although I have updated to the latest dx9c and nvidia drivers.



Right now the sphere model color map is only grey with a normal map in skin 2 - as I am just trying to see the normal mapping working right now.

oh-- It says that the fx files need to be in the 'worlds' folder. I tried making a folder named worlds and putting them in it, but they were not found - then moved them back to the root and no longer got the error - so I assumed the 'world' folder meant the folder with your world data in it?





I downloaded theses files, and how lucky i am... i open the project, he say that cant find ap.wad, and when i do run, e gives me many error in the script!

Whats going on with my Engine?
Posted By: Matt_Aufderheide

Re: stumped - 08/29/05 16:37

Sorry, but you need to learn some more about how A6 works before adding shaders and such to your projects..
Posted By: NMS

Re: stumped - 08/29/05 21:15

so where i learn that?
Posted By: Josh_Arldt

Re: stumped - 08/29/05 22:35

Quote:

so where i learn that?




1.The manual...
2.Experimenting and asking questions...
Posted By: Matt_Coles

Re: stumped - 08/29/05 23:00

Ok NMS, to help I think the best thing I can do is show you a open source demo that I made with the effect, so you can look at it and compare it to your project.
This file: http://www.matt.brightwatch.com/renderview.zip
goes in your acknex_plugins folder and this file is the actual project
http://coniroot.de/~pirvu/au/scripts/shadercollection.zip

Hope this helps and makes it easier for you to set it up and understand in your own project

Matt Coles
Posted By: Machinery_Frank

Re: stumped - 08/30/05 09:02

Hi Matt_Coles,

I cannot download the renderview.zip.

Frank
Posted By: Matt_Aufderheide

Re: stumped - 08/30/05 10:26

yes because i took it down.. i no longer distribute this dll..
wait till Sphere comes out!
Posted By: Matt_Coles

Re: stumped - 08/30/05 11:21

you can still use the file without bloom which is what is in the dll. you will just have to take this command out of your main script:
screengrab():

Hope this helps,

Matt Coles
Posted By: NMS

Re: stumped - 08/31/05 10:31

The shadercollection gives me many error messages :S

Maybe cuz i've the 6.1 engine no?
I cant update, the downloads appear like broken in my browser.
Posted By: Matt_Coles

Re: stumped - 08/31/05 22:46

Yeah you need A6.31.4 as it is direct x 9. Have you tried downloading the update from the downloads page?
Posted By: NMS

Re: stumped - 09/01/05 13:41

yes but my mozzila doesnt work with download links anymore, he says "links broken", and my internet explorer doenst exists anymore... i have to format this xit...

can someone send me the update? plz...
Posted By: Paul_L_Ming

Re: stumped - 09/03/05 22:24

Hiya.

Try opening up "My Computer", then in the "Address" bar type in the URL of the download? If that doesn't work, they your OS shouldn't even be running. I guess you've tried uninstalling Firefox, restarting, re-installing Firefox? What about updating IE? If you have, then you should just go and reformat your hard drive and get back to work...if you're having this much trouble from a simple URL, it will only get worse for your other programs I'm sure. Good luck!
Posted By: zefor

Re: stumped - 11/28/05 15:56

I have a ati 9600 all in wonder. I am using Gamestudio Comercial v.6.31.4 and I have dx9.0c on my comp. I have installed the latest vid card driver files.I cannot get this working, everything "shader applied" is black. I did get steempipes bumpmapping to work off of the wiki, but this lighted shader is kicking my butt. I would love to get this working, does something need to be changed in the .fx files to work with this version of gstudio?
Posted By: Sebe

Re: stumped - 11/28/05 17:09

Code:
        // compile shaders
VertexShader = compile vs_3_0 VS_PASS2();
PixelShader = compile ps_3_0 PS_PASS2();



Sadly, your card only supports shader 2.0 - and as you can see, this seem to be 3.0 - shaders.
Posted By: Matt_Aufderheide

Re: stumped - 11/28/05 17:23

Yes, this shader is done using 3.0 shaders, because that saved passes.
However, it can easily be converted to 2.0 .. just make each pass do only 2 lights..and add some passes.

For instance here is the normal mapping shader form the SPhere Engine(you wont be able to use this as is, but it will show you waht to do):
Code:
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//normalmapping

struct VS_INPUT_STRUCT
{
half4 position: POSITION;
half3 tangent: TEXCOORD1;
half3 binormal: TEXCOORD2;
half3 normal: NORMAL;
half2 texcoord0: TEXCOORD0;
};

struct VS_OUTPUT_STRUCT
{
half4 position: POSITION;
half2 bump_map: TEXCOORD0;
half3 tangentlight: TEXCOORD1;
half3 tangenteye: TEXCOORD3;
half3 Att1 : TEXCOORD4;
half3 Att2 : TEXCOORD6;
half3 tangentlight2: TEXCOORD2;
half4 eyeLinear: TEXCOORD5;
half Fog : FOG;
};

VS_OUTPUT_STRUCT VS_PASS0( VS_INPUT_STRUCT vsInStruct )
{
VS_OUTPUT_STRUCT vsOutStruct;
vsOutStruct.Fog = 10000;
vsOutStruct.position = mul( vsInStruct.position,matWorldViewProj );
vsOutStruct.bump_map = vsInStruct.texcoord0;

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
half3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(vsInStruct.tangent, matWorld);
// worldToTangentSpace[1] = mul(cross(vsInStruct.tangent, vsInStruct.normal), -matWorld);
worldToTangentSpace[1] = mul(vsInStruct.binormal, -matWorld);
worldToTangentSpace[2] = mul(vsInStruct.normal, matWorld);

half3 PosWorld = mul(vsInStruct.position, matWorld);

// Output the projective texture coordinates
vsOutStruct.eyeLinear= mul( vsInStruct.position, matTexture );

//light 1
half3 objectspace_light_vector = PosWorld - vecLightPos ;
vsOutStruct.tangentlight = mul(worldToTangentSpace, -objectspace_light_vector); // L
half3 objectspace_view_vector = PosWorld - vecViewPos;
vsOutStruct.tangenteye = mul(worldToTangentSpace, -objectspace_view_vector); // V
vsOutStruct.Att1 = objectspace_light_vector * (vecLightColor.w*0.6);

//light 2
half3 objectspace_light_vector2 = PosWorld - vecLightPos2 ;
vsOutStruct.tangentlight2 = mul(worldToTangentSpace, -objectspace_light_vector2); // L
vsOutStruct.Att2 = objectspace_light_vector2 * (vecLightColor2.w*0.6);

return vsOutStruct;
}

struct PS_INPUT_STRUCT
{
half2 bump_map: TEXCOORD0;
half3 tangentlight: TEXCOORD1;
half3 tangenteye: TEXCOORD3;
half3 Att1 : TEXCOORD4;
half3 Att2 : TEXCOORD6;
half3 tangentlight2: TEXCOORD2;
half4 eyeLinear: TEXCOORD5;
};

struct PS_OUTPUT_STRUCT
{
half4 color0: COLOR0;
};


PS_OUTPUT_STRUCT PS_PASS0( PS_INPUT_STRUCT psInStruct )
{
PS_OUTPUT_STRUCT psOutStruct;

half4 Attenuation1 = mul(psInStruct.Att1, psInStruct.Att1);
half4 Attenuation2 = mul(psInStruct.Att2, psInStruct.Att2);

half3 eyevect = normalize(psInStruct.tangenteye);

// half2 modified_texcoord = ParallaxTexCoord(psInStruct.bump_map, BumpMapSampler, eyevect, parallax);

// half4 base = tex2D( ColorMapSampler, modified_texcoord);
half4 base = tex2D( ColorMapSampler, psInStruct.bump_map);
// half3 bump = bumpheight * (tex2D(BumpMapSampler, modified_texcoord) - 0.5); // fetch bump map
half3 bump = bumpheight * (tex2D(BumpMapSampler, psInStruct.bump_map) - 0.5); // fetch bump map
// normalize(bump);

half3 LightDir1 = normalize(psInStruct.tangentlight);
half3 ViewDir1 = normalize(psInStruct.tangenteye);
half4 diff1 = saturate(dot(bump, LightDir1)); // diffuse component
half3 Reflect1 = normalize(2 * diff1 * bump - LightDir1); // R
half4 spec1 = pow(saturate(dot(Reflect1, ViewDir1)), 15);

half3 LightDir2 = normalize(psInStruct.tangentlight2);
half4 diff2 = saturate(dot(bump, LightDir2)); // diffuse component
half3 Reflect2 = normalize(2 * diff2 * bump - LightDir2); // R
half4 spec2 = pow(saturate(dot(Reflect2, ViewDir1)), 15);

// half shadow1 = saturate(4 * diff1);
// half shadow2 = saturate(4 * diff2);

half4 shadow_map =tex2Dproj(shadowmap_1, psInStruct.eyeLinear);

if (enable_shadows==0)
{
shadow_map =1;
}


half4 shadow_map1 = shadow_map.r;
half4 shadow_map2 = shadow_map.g;

psOutStruct.color0.rgb = (ambientcolor * base) + saturate((((/*shadow1*/ (base * diff1 + (spec1*base.w)) * (1-Attenuation1))*(vecLightColor)))*saturate(shadow_map1))+
saturate(((/*shadow2*/ (base * diff2 + (spec2*base.w)) * (1-Attenuation2))*(vecLightColor2))*saturate(shadow_map2));

psOutStruct.color0.a = 1.0f;

return psOutStruct;
}


///////////////////////////////////////////////////////////////////////////////////////////
struct VS_INPUT_STRUCT1
{
half4 position: POSITION;
half3 tangent: TEXCOORD1;
half3 binormal: TEXCOORD2;
half3 normal: NORMAL;
half2 texcoord0: TEXCOORD0;
};

struct VS_OUTPUT_STRUCT1
{
half4 position: POSITION;
half2 bump_map: TEXCOORD0;
half3 tangentlight: TEXCOORD1;
half3 tangentlight2:TEXCOORD2;
half3 tangenteye: TEXCOORD3;
half3 Att1 : TEXCOORD4;
half3 Att2 : TEXCOORD6;
half4 eyeLinear: TEXCOORD5;
half Fog : FOG;
};

VS_OUTPUT_STRUCT1 VS_PASS1( VS_INPUT_STRUCT1 vsInStruct )
{
VS_OUTPUT_STRUCT1 vsOutStruct;
vsOutStruct.Fog = 10000;
vsOutStruct.position = mul( vsInStruct.position,matWorldViewProj );
vsOutStruct.bump_map = vsInStruct.texcoord0;

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
half3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(vsInStruct.tangent, matWorld);
// worldToTangentSpace[1] = mul(cross(vsInStruct.tangent, vsInStruct.normal), -matWorld);
worldToTangentSpace[1] = mul(vsInStruct.binormal, -matWorld);
worldToTangentSpace[2] = mul(vsInStruct.normal, matWorld);

half3 PosWorld = mul(vsInStruct.position, matWorld);

vsOutStruct.eyeLinear= mul( vsInStruct.position, matTexture );

half3 objectspace_light_vector = PosWorld - vecLightPos3 ;
vsOutStruct.tangentlight = mul(worldToTangentSpace, -objectspace_light_vector); // L
half3 objectspace_view_vector = PosWorld - vecViewPos;
vsOutStruct.tangenteye = mul(worldToTangentSpace, -objectspace_view_vector); // V
vsOutStruct.Att1 = objectspace_light_vector * (vecLightColor3.w*0.6);

half3 objectspace_light_vector2 = PosWorld - vecLightPos4 ;
vsOutStruct.tangentlight2 = mul(worldToTangentSpace, -objectspace_light_vector2); // L
vsOutStruct.Att2 = objectspace_light_vector2 * (vecLightColor4.w*0.6);

return vsOutStruct;
}

struct PS_INPUT_STRUCT1
{
half2 bump_map: TEXCOORD0;
half3 tangentlight: TEXCOORD1;
half3 tangentlight2:TEXCOORD2;
half3 tangenteye: TEXCOORD3;
half3 Att1 : TEXCOORD4;
half3 Att2 : TEXCOORD6;
half4 eyeLinear: TEXCOORD5;
};

struct PS_OUTPUT_STRUCT1
{
half4 color0: COLOR0;
};

PS_OUTPUT_STRUCT1 PS_PASS1( PS_INPUT_STRUCT1 psInStruct )
{
PS_OUTPUT_STRUCT1 psOutStruct;

half4 Attenuation1 = mul(psInStruct.Att1, psInStruct.Att1);
half4 Attenuation2 = mul(psInStruct.Att2, psInStruct.Att2);

half3 eyevect = normalize(psInStruct.tangenteye);

// half2 modified_texcoord = ParallaxTexCoord(psInStruct.bump_map, BumpMapSampler, eyevect, parallax);

// half4 base = tex2D( ColorMapSampler, modified_texcoord);
half4 base = tex2D( ColorMapSampler, psInStruct.bump_map);
// half3 bump = bumpheight * (tex2D(BumpMapSampler, modified_texcoord) - 0.5); // fetch bump map
half3 bump = bumpheight * (tex2D(BumpMapSampler, psInStruct.bump_map) - 0.5); // fetch bump map
// normalize(bump);

half3 LightDir1 = normalize(psInStruct.tangentlight);
half3 ViewDir1 = normalize(psInStruct.tangenteye);
half4 diff1 = saturate(dot(bump, LightDir1)); // diffuse component
half3 Reflect1 = normalize(2 * diff1 * bump - LightDir1); // R
half4 spec1 = pow(saturate(dot(Reflect1, ViewDir1)), 15);


half3 LightDir2 = normalize(psInStruct.tangentlight2);
half4 diff2 = saturate(dot(bump, LightDir2)); // diffuse component
half3 Reflect2 = normalize(2 * diff2 * bump - LightDir2); // R
half4 spec2 = pow(saturate(dot(Reflect2, ViewDir1)), 15);


// half shadow1 = saturate(4 * diff1);
// half shadow2 = saturate(4 * diff2);

half4 shadow_map = tex2Dproj(shadowmap_1, psInStruct.eyeLinear);
half4 shadow_mapa = tex2Dproj(shadowmap_2, psInStruct.eyeLinear);

if (enable_shadows==false)
{
shadow_map =1;
shadow_mapa =1;
}

half4 shadow_map1 = shadow_map.b;
half4 shadow_map2 = shadow_mapa.r;

psOutStruct.color0.rgb =saturate((((/*shadow1*/ (base * diff1 + (spec1*base.w)) * (1-Attenuation1))*(vecLightColor3)))*saturate(shadow_map1))+
saturate(((/*shadow2*/ (base * diff2 + (spec2*base.w)) * (1-Attenuation2))*(vecLightColor4))*saturate(shadow_map2));

psOutStruct.color0.a = 1.0f;

return psOutStruct;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


struct VS_INPUT_STRUCT2
{
half4 position: POSITION;
half3 tangent: TEXCOORD1;
half3 binormal: TEXCOORD2;
half3 normal: NORMAL;
half2 texcoord0: TEXCOORD0;
};

struct VS_OUTPUT_STRUCT2
{
half4 position: POSITION;
half2 bump_map: TEXCOORD0;
half3 tangentlight: TEXCOORD1;
half3 tangenteye: TEXCOORD3;
half3 Att1 : TEXCOORD4;
half3 Att2 : TEXCOORD6;
half3 tangentlight2: TEXCOORD2;
half4 eyeLinear: TEXCOORD5;
half Fog : FOG;
};

VS_OUTPUT_STRUCT2 VS_PASS2( VS_INPUT_STRUCT2 vsInStruct )
{
VS_OUTPUT_STRUCT2 vsOutStruct;
vsOutStruct.Fog = 10000;
vsOutStruct.position = mul( vsInStruct.position,matWorldViewProj );
vsOutStruct.bump_map = vsInStruct.texcoord0;

// compute the 3x3 tranform matrix
// to transform from world space to tangent space
half3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(vsInStruct.tangent, matWorld);
// worldToTangentSpace[1] = mul(cross(vsInStruct.tangent, vsInStruct.normal), -matWorld);
worldToTangentSpace[1] = mul(vsInStruct.binormal, -matWorld);
worldToTangentSpace[2] = mul(vsInStruct.normal, matWorld);

half3 PosWorld = mul(vsInStruct.position, matWorld);

// Output the projective texture coordinates
vsOutStruct.eyeLinear= mul( vsInStruct.position, matTexture );

//light 1
half3 objectspace_light_vector = PosWorld - vecLightPos5 ;
vsOutStruct.tangentlight = mul(worldToTangentSpace, -objectspace_light_vector); // L
half3 objectspace_view_vector = PosWorld - vecViewPos;
vsOutStruct.tangenteye = mul(worldToTangentSpace, -objectspace_view_vector); // V
vsOutStruct.Att1 = objectspace_light_vector * (vecLightColor5.w*0.6);

//light 2
half3 objectspace_light_vector2 = PosWorld - vecLightPos6 ;
vsOutStruct.tangentlight2 = mul(worldToTangentSpace, -objectspace_light_vector2); // L
vsOutStruct.Att2 = objectspace_light_vector2 * (vecLightColor6.w*0.6);

return vsOutStruct;
}


struct PS_INPUT_STRUCT2
{
half2 bump_map: TEXCOORD0;
half3 tangentlight: TEXCOORD1;
half3 tangenteye: TEXCOORD3;
half3 Att1 : TEXCOORD4;
half3 Att2 : TEXCOORD6;
half3 tangentlight2: TEXCOORD2;
half4 eyeLinear: TEXCOORD5;
};

struct PS_OUTPUT_STRUCT2
{
half4 color0: COLOR0;
};


PS_OUTPUT_STRUCT2 PS_PASS2( PS_INPUT_STRUCT2 psInStruct )
{
PS_OUTPUT_STRUCT2 psOutStruct;

half4 Attenuation1 = mul(psInStruct.Att1, psInStruct.Att1);
half4 Attenuation2 = mul(psInStruct.Att2, psInStruct.Att2);

half4 base = tex2D( ColorMapSampler, psInStruct.bump_map);

half3 bump = bumpheight * (tex2D(BumpMapSampler, psInStruct.bump_map) - 0.5); // fetch bump map
// normalize(bump);

half3 LightDir1 = normalize(psInStruct.tangentlight);
half3 ViewDir1 = normalize(psInStruct.tangenteye);
half4 diff1 = saturate(dot(bump, LightDir1)); // diffuse component
half3 Reflect1 = normalize(2 * diff1 * bump - LightDir1); // R
half4 spec1 = pow(saturate(dot(Reflect1, ViewDir1)), 15);

half3 LightDir2 = normalize(psInStruct.tangentlight2);
half4 diff2 = saturate(dot(bump, LightDir2)); // diffuse component
half3 Reflect2 = normalize(2 * diff2 * bump - LightDir2); // R
half4 spec2 = pow(saturate(dot(Reflect2, ViewDir1)), 15);

// half shadow1 = saturate(4 * diff1);
// half shadow2 = saturate(4 * diff2);

half4 shadow_map =tex2Dproj(shadowmap_2, psInStruct.eyeLinear);

if (enable_shadows==false)
{
shadow_map =1;

}

half4 shadow_map1 = shadow_map.g;
half4 shadow_map2 = shadow_map.b;

psOutStruct.color0.rgb = (ambientcolor * base) + saturate((((/*shadow1**/ (base * diff1 + (spec1*base.w)) * (1-Attenuation1))*(vecLightColor5)))*saturate(shadow_map1))+
saturate(((/*shadow2* */(base * diff2 + (spec2*base.w)) * (1-Attenuation2))*(vecLightColor6))*saturate(shadow_map2));

psOutStruct.color0.a = 1.0f;

return psOutStruct;
}


Posted By: zefor

Re: stumped - 11/28/05 17:57

Mat coles posted a 2.0 script earlier in the post
http://www.coniserver.net/ubbthreads/sho...art=15&vc=1
That "should" work with my card, correct?
Posted By: Matt_Aufderheide

Re: stumped - 11/28/05 18:16

yes that should work
Posted By: zefor

Re: stumped - 11/28/05 18:31

If I set my level geometry up the same way I did with the tutorial from the wiki, this should work, since the tutorial worked right? I still see black instead of bumpmapping. Do I need to use more than 1 dynamic light? Does it have to be far away or close? I am determined to get this working. Thank you for your help and patience.
Posted By: Matt_Aufderheide

Re: stumped - 11/28/05 20:43

Im not sure why its not working , but it's not reccomended for level geometry anyway.. because it will be extremely slow, and have lighting errors. A6 level geometry is not meant for normal mapping/per pixel lighting.

Stick with making worlds out of models.
Posted By: zefor

Re: stumped - 11/28/05 21:24

My model is black too, but maybe I am not setting it up right. Let me describe my process.
I texture a model in med. Export to bmp. Open bmap in photoshop. create new channel "Alpha1". select rgb image, copy, and paste over alpha image, which turns it grayscale. save as a .tga. import back into med and apply over original texture. Is that the correct procedure for preparing a model? If not then maybe that is my problem. I have never got bumpmapping, or any shaders to work on models.
Posted By: Matt_Aufderheide

Re: stumped - 11/28/05 22:40

Well, that's a very basic way of doing that.. the alpha channel is for specular values.. meaning that you make the brightest areas the areas you want to have the most 'shine'. But you then need a normal map too, put that in skin2 in MED.

Then you have to have dynamic lights in your level.
Posted By: zefor

Re: stumped - 11/29/05 17:41

This is probably stupid, but.... when you say skin2 in MED do you mean when you add another skin under the "veiw skins" tab and select "add after last skin" or is there actually a "skin2" checkbox somewhere that I just have not seen. Other wise I was just trying to add it to code like this:

bmap box = <box1.tga>;

material spec_bump_model //assaign all models this material in script
{
skin2 = box;
flags = tangent;
}

I still get a black model though . Also, do I need an alpha channel or can I just have a regular skin and a normal map? I tried this and saw no change to the model. Not black, but also no bumpmap.
Posted By: Matt_Aufderheide

Re: stumped - 11/29/05 18:39

Quote:

when you say skin2 in MED do you mean when you add another skin under the "veiw skins" tab and select "add after last skin"




Yes this is what i mean .. you should have an alpha channel, because this controls the specular highlight intensity, with no alpha channel you will get no specular highlights. The normal map doesnt need an alpha channel.
Posted By: zefor

Re: stumped - 11/29/05 21:53

My models are still black, but when I have no action assigned to them, they are the purple, blue normal map. Did I at least set my model up right or should I see the regular texture instead. Maybe its the way I am assigning the action. I have:

action Shader_NormalMap
{
my.material = spec_bump_model;
}

in the bottom of my game.wdl and I apply that action in wed. Is the action supposed to be somewhere else other than the bottom of the game.wdl? ( I appologize, I realize these are probably common sense questions, but I am getting desperate )

I want to Thank you for working me through this mat. THANK YOU. I think I may be getting close
Posted By: Matt_Aufderheide

Re: stumped - 11/30/05 04:33

Put color map w/alpha in skin 1, put normal map in skin 2. assing the material in the action. Also try putting this : my.frame+=1; in the action too. Set my flare=off; , and my transparent=off;

Make sure there is a dynamic light near the model.. with a color and lightrange set, and my.light=on;

If you cant get it work this way.. i dont know how to help you.. except you can biuy the SPhere Engine which can do all this automatically for you.
Posted By: Thomas_Nitschke

Re: stumped - 12/02/05 12:47

[/advertisement]

No, seriously - I think the following:
Antwort auf:

bmap box = <box1.tga>;

material spec_bump_model //assaign all models this material in script
{
skin2 = box;
flags = tangent;
}



gives you problems because this way, you assign a second skin to the material, not the model that uses the material. As far as I'm concerned, the shader needs the model to have the skin, not the material. Thus this is what you do, basically:
1. - Open your Model
2. - Open the skin editor
3. - Import you basic model skin (has to be TGA with alpha)
4. - Add a new skin
(Edit -> Add new skin just in case this is confusing...)
5. - Click
Next Skin and import your normalmap
6. - Save and have a try


Hope that helps!
Posted By: zefor

Re: stumped - 12/02/05 19:23

I did that and models are still black. I downloaded the doom3 pack from au, models with normal maps, and they are also black. I must be doing something else wrong.
Posted By: zefor

Re: stumped - 12/02/05 19:54

Just bought sphere. Hope customer support is ready will I get a link to download in my email, or do you ship?
Posted By: zefor

Re: stumped - 12/03/05 05:06

Very black models(can make out texture though), Very bright terrain?? imported cheledont_0_mdl and he is black. works in demo though???
Posted By: Pappenheimer

Re: stumped - 12/03/05 10:32

Would like to say that is Matt's problem, but your problem isn't easy to analyse via internet.

Be sure to make not too much steps at once! One step after another! Each step documented in your post.

First steps has to be: Start a level of Sphere! Without modifications! With all the conditions fullfilled mentioned in the Readme!

Does this work? Is everything as it should be?

Then start the other level!

Does this work? Is everything as it should be?

Change the parameter which changes from bump to parallex. And restart the level! Control each change by starting the changed level to see wether it makes a difference and which difference it makes!

In that way, change the level's models step by step, and don't do the next step before your step has been successful...

Not sure wether you needed these advices, but your last post was too short to help a helper!
Posted By: Pappenheimer

Re: stumped - 12/03/05 10:58

Quote:

Very black models(can make out texture though), Very bright terrain?? imported cheledont_0_mdl and he is black. works in demo though???




Just tried it within Sphere: Did you apply Sp_Model AND check Flag7?
Posted By: zefor

Re: stumped - 12/03/05 13:41

Yes, Flag 7, i can now see my models, just no normal mapping.
Docs say:
"skin2=normalmap with the parallax heightmap in the alpha channel."
I know a specular/gloss map is just a grayscale image in the alpha channel of the texture, what is a parallax heightmap, How do I impliment it? I know from trial and error it is not a grayscale normalmap in the alpha channel of the normal map

Learned how to do parallax heightmap, but still cannot see bumpmapping.??
Posted By: Matt_Aufderheide

Re: stumped - 12/03/05 14:54

Flag7 is what you dont want, that will make sure there is no bumpmapping.

Question: is this an animated model? if so check flag8... if not check no flags.
Posted By: zefor

Re: stumped - 12/03/05 15:39

models go black again even cheledont. i have to small models in my level assigned Sp_Dynamic_Light. I am testing on an inside level now, made out of models.
Posted By: zefor

Re: stumped - 12/03/05 15:48

i turned flag 7 off of 1 of the rocks in your island demo and it turned black too. i could see a texture but very dark. Of course the cheledont looks bumpmapped and awsome in the indoor level???????

Ok I imported one of the outdoor rocks into your indoor level and it was bumpmapped, looked pretty good too. Imported one of my models into the same level and ........wow, it worked. I guess you cant have bumpmapping on an outdoor level huh? Anyway I am still having problems with my own test level. When I make a room out of a box model, do I want to "flip" the model inside out in the model program, or make wall, floor and ceiling out of seperate models?
btw, it was cool to see my models working
Posted By: zefor

Re: stumped - 12/03/05 16:37

I needed to use sp_light instead of sp_dynamic_light. what is the difference? sp_dynamic_light is not covered in the Sphere doc.
Posted By: Matt_Aufderheide

Re: stumped - 12/03/05 20:15

Sp_dynamic light is just a normal dynamic light, you need to use Sp_light for lighting effects.
Posted By: zefor

Re: stumped - 12/05/05 15:44

There is something in the wiki under "shader hints" and it tells how to impliment sunlight. For bumpmapping in outdoor levels, which .fx would I add these few lines to?
Posted By: miko

Re: stumped - 12/13/05 02:14

cool shaders
Posted By: zefor

Re: stumped - 12/15/05 14:30

I Finally got this Ultimate Shader Working!!!! For anyone having trouble with black models check NoFog in its properties! WOW wish I figured this one out earlier!!!
Posted By: AndyHellbach

Shader Problem - 12/22/05 11:35

I realize that im somewhat late to post here, but i've been working with GDS for 4months now, and im really stuck with the Shader for PS 2.0. Then again im
new to Shaders.

I have GDS 6.31.4 Com, i have the latest Omega Drivers for my ATI x800xt (wich supports PS2.0) installed, Direct X9.0c is also installed.

I worked trough all the 24 Pages of this thread to find out whats happening, but i cant fix my probelm.

The Script doesnt't give me any errors, but when i run my level, all i got
is lightning but no Bump Effect, not on Block and neither on models.
Am i missing a DLL File for rendering or something ??

I would really appriciate it, if someone could mail or upload a little Testlevel with 1 Block and 1 Model textured, so i could compare the settings.
None of the links provided on Page 1 to 24 works anymore, wich is normal after all this time.

Just in case my email is a.hellbach@bluewin.ch

Excuse my Grammar, english isn't my mother tongue.
Posted By: zefor

Re: Shader Problem - 12/23/05 09:53

Do you have a normalmap for entskin2 on your model? That is what gives it the bumpmap.
Posted By: AndyHellbach

Re: Shader Problem - 12/23/05 10:05

Yes i tried it several times, with diffrent models. What i need is a testlevel
to compare the settings, i really want to get to the root of the problem.
Posted By: Matt_Aufderheide

Re: Shader Problem - 12/23/05 13:20

Forget this shader.. just buy the SPhere engine, that has everything ready made for you.
Posted By: Matt_Coles

Re: Shader Problem - 12/24/05 03:49

@ Andy, download shader collection on acknex unlimited it has a working normal mapping opensource example
Posted By: indiGLOW

Re: Shader Problem - 12/30/05 19:14

I am having issues with shaders in black as well.... There seems to be a lot of this, I think I have something wrong with my GS bcz I can't see Dx9 mentioned anywhere in the settings and despite having a PS.2 card I can't get it to work

I have also used the code from one of the AUM's that displays your cards shader support and I get no information returned... So it seems to think there is no shader support on my card??

Maybe there's a ATI issue with the latest release??? TIA for any help
Posted By: zefor

Re: Shader Problem - 12/31/05 15:01

I am no expert, but I had a problem with everything being black as well, and figured out it was a fog issue. Example, if you go under map properties and change your fog1 from black to blue, then all your shader models will be blue. To fix this, I simply put a check in "no fog" in my models properties. Oh, I have an ati radeon 9600 all in wonder card. Hope this helps.
Posted By: Matt_Aufderheide

Re: Shader Problem - 12/31/05 17:07

you can't have fog with this shader, it could be modified to have fog however..
Posted By: Matt_Coles

Re: Shader Problem - 12/31/05 23:40

I have adjusted code to incorporate fog with this shader. pm if interested
Posted By: Matt_Coles

Re: Shader Problem - 01/03/06 21:29

You can find the normal mapping ps2.0 with 7 lights and Fog in a zip file here:

Normal Mapping With Fog

Enjoy,
Matt Coles
Posted By: Matt_Aufderheide

Re: Shader Problem - 01/04/06 00:41

The only problem with this shader is that it passes through the same color fog for each pass... Think about it for a second, if you have the same fog for 3 or 4 passes, each being additive blended, your fog color will be all funky, and not match the actual fog value...becasue it fogs each pass seperately, anbd adds that to last pass..

A good way to handle this problem is to have the fog as normal in the first pass, then in all subsequent passes, change the fog color to black, then becasue it is additive, it will just dim down the passes, instead of fogging them with a color.. this will then give correct fog colors throughout all the passes.

You can set the fog color in the passes (except for the first pass, you shouldnt need to change that) like this:
fogcolor={0.0,0.0,0.0,1.0}; // this will be black..
Posted By: Matt_Coles

Re: Shader Problem - 01/04/06 01:30

thanks, I'll change it round then
Posted By: Locutus_of_Borg

Re: Shader Problem - 03/23/06 15:18

is it somehow possible to use this shader with static lights?
because in commertial edition you can only use 7 dynamic lights or so, static would be better here.
© 2024 lite-C Forums