Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 1 invisible), 583 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 3
Page 15 of 24 1 2 13 14 15 16 17 23 24
perpixel ps2 - 4 lights! [Re: Drew] #36913
12/17/04 07:51
12/17/04 07:51
Joined: Jul 2003
Posts: 893
Melbourne, Australia
Matt_Coles Offline

User
Matt_Coles  Offline

User

Joined: Jul 2003
Posts: 893
Melbourne, Australia
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

Re: perpixel ps2 - 4 lights! [Re: Matt_Coles] #36914
12/17/04 08:45
12/17/04 08:45
Joined: Jul 2002
Posts: 5,181
Austria
Blattsalat Offline
Senior Expert
Blattsalat  Offline
Senior Expert

Joined: Jul 2002
Posts: 5,181
Austria
I am kind of impressed right now... very impressed by the quality.

need to test it asap.


Models, Textures and Levels at:
http://www.blattsalat.com/
portfolio:
http://showcase.blattsalat.com/
Re: perpixel ps2 - 4 lights! [Re: Blattsalat] #36915
12/17/04 08:48
12/17/04 08:48
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
Drew Offline
Serious User
Drew  Offline
Serious User

Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
AWESOME!!!!! (screams like little kid)
I was getting a little tired of 2 lights...not complaining though!!
thanks! (especially for 2.0 support)


Drew Medina
Game Developer (Artist)
Personal & professional website
Deviant Art
My Blogspot
Re: perpixel ps2 - 4 lights! [Re: Drew] #36916
12/17/04 08:58
12/17/04 08:58
Joined: Jul 2003
Posts: 893
Melbourne, Australia
Matt_Coles Offline

User
Matt_Coles  Offline

User

Joined: Jul 2003
Posts: 893
Melbourne, Australia
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

Re: perpixel ps2 - 4 lights! [Re: Matt_Coles] #36917
12/17/04 09:04
12/17/04 09:04
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
Drew Offline
Serious User
Drew  Offline
Serious User

Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
maybe I can plug it into my other demo, but no promises..no time right now... 8 lights, or even 7...Drool

Re: perpixel ps2 - 4 lights! [Re: Drew] #36918
12/17/04 14:30
12/17/04 14:30
Joined: Jul 2003
Posts: 893
Melbourne, Australia
Matt_Coles Offline

User
Matt_Coles  Offline

User

Joined: Jul 2003
Posts: 893
Melbourne, Australia
It should be able to plug straight into the other demo
Is the code working well for everybody?

Matt Coles

perpixel ps2 - 7 lights!!!! [Re: Matt_Coles] #36919
12/17/04 16:53
12/17/04 16:53
Joined: Jul 2003
Posts: 893
Melbourne, Australia
Matt_Coles Offline

User
Matt_Coles  Offline

User

Joined: Jul 2003
Posts: 893
Melbourne, Australia
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

Re: perpixel ps2 - 7 lights!!!! [Re: Matt_Coles] #36920
12/17/04 19:43
12/17/04 19:43
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
Drew Offline
Serious User
Drew  Offline
Serious User

Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
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...




Drew Medina
Game Developer (Artist)
Personal & professional website
Deviant Art
My Blogspot
Re: perpixel ps2 - 7 lights!!!! [Re: Drew] #36921
12/18/04 08:45
12/18/04 08:45
Joined: Jul 2003
Posts: 893
Melbourne, Australia
Matt_Coles Offline

User
Matt_Coles  Offline

User

Joined: Jul 2003
Posts: 893
Melbourne, Australia
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

Re: perpixel ps2 - 7 lights!!!! [Re: Matt_Coles] #36922
12/18/04 08:49
12/18/04 08:49
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
Drew Offline
Serious User
Drew  Offline
Serious User

Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
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)


Drew Medina
Game Developer (Artist)
Personal & professional website
Deviant Art
My Blogspot
Page 15 of 24 1 2 13 14 15 16 17 23 24

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1