Gamestudio Links
Zorro Links
Newest Posts
Help!
by VoroneTZ. 10/14/25 05:04
Zorro 2.70
by jcl. 10/13/25 09:01
ZorroGPT
by TipmyPip. 10/12/25 13:58
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 10/11/25 18:45
Reality Check results on my strategy
by dBc. 10/11/25 06:15
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
4 registered members (AndrewAMD, Nymphodora, Quad, 1 invisible), 7,621 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
joenxxx, Jota, krishna, DrissB, James168
19170 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Lightmap+Normalmap for Subsets [Re: Wicht] #183007
02/10/08 11:26
02/10/08 11:26
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Honestly, being reasonable, even if this shader isn't optimized: when will you ever need in a game a room or dungeon where you need such a lot of dynamic lights?

I think there's always a way to reduce the need of 4 dynamic lights to very few rooms.

Did anyone try to reduce the textures to 256x256 to compare the framerate to the current framerate?

EDIT: [To make a contribution, which isn't optimized in each detail seems to be quite risky! Only trouble! ]

Suggestion about optimizing, in case one uses a big dungeon with a lot of torchs and several gaps in the roof with sunlight:
Everything shadowmapped with ventilator's plugin, but when you come closer to a enlightened place switch the dynamic light to it to see the normalmapping.

It is a bit like done in the sphere plugin, with the important advantage that it doesn't disappear in the dark as soon the dynamic light switches off.

Last edited by Pappenheimer; 02/10/08 11:47.
Re: Lightmap+Normalmap for Subsets [Re: Pappenheimer] #183008
02/10/08 12:01
02/10/08 12:01
Joined: Nov 2004
Posts: 862
Australia
DavidLancaster Offline
User
DavidLancaster  Offline
User

Joined: Nov 2004
Posts: 862
Australia
All about managing it down the person implementing it, shader like this doesn't exist in this format already and the fact that you've gone out your way to provide it so easily to implement, thank you. I get 150 fps, 8600 card.

Re: Lightmap+Normalmap for Subsets [Re: DavidLancaster] #183009
02/10/08 12:54
02/10/08 12:54
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
Runs very smooth here with a stable 300 fps when running the exe
Specs : see signature.
Maybe an option for increasing the framerate is using predefined parameters like doFog or doTangent within the effect file to minimize the amount of instructions. Since you're using 3 VSs and 3 PSs due to the dynamic lights and thus logically 3 passes to render it out, this might work Eventually, I even think you don't need shader model 2 anymore because these predefined parameters were developed for decreasing instruction rate which leads into a lower shader model and a higher framerate
Anyway, great effort fogman !!

Cheers

Frazzle

Re: Lightmap+Normalmap for Subsets [Re: frazzle] #183010
02/12/08 04:57
02/12/08 04:57
Joined: Aug 2001
Posts: 2,320
Alberta, Canada
William Offline
Expert
William  Offline
Expert

Joined: Aug 2001
Posts: 2,320
Alberta, Canada
Thank you much for sharing this. Although fog doesn't work, so add this line in your last 2 pass's.

FogEnable=false;

The lightmap version works with my project, and I made an update to have the sun work with a non-shadow version:

Code:
 //Normalmapping with lightmapblending

#define SpecIntensity 22
#define SpecStrength 0.3

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

extern float4 vecSunDiffuse;
extern float4 vecFalloff;

extern float4 vecAmbient;
extern float4 vecDiffuse;
extern float4 vecLight;


texture entSkin1; //this is the color map
texture entSkin2; //this is the normal map
texture mtlSkin1; //this is the light 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;
};

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


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

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

float3 Sun : TEXCOORD2;
float Att1 : TEXCOORD3;

float3 Light2 : TEXCOORD4;
float Att2 : TEXCOORD5;

float Fog : FOG;
};


VS_OUTPUT0 VS_PASS0(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float2 texcoord1 : TEXCOORD1, 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.xy = texcoord0.xy;
Out.Tex.zw = texcoord1.xy;

float3 PosWorld = mul(Pos, matWorld);

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


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


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

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

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

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

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

return Out;
}

float4 PS_PASS0( VS_OUTPUT0 psInStruct ):COLOR
{
float4 color = tex2D(ColorMapSampler, psInStruct.Tex.xy); // fetch color map
float4 bumpNormal = 2 * (tex2D(BumpMapSampler, psInStruct.Tex.xy) - 0.5); // fetch bump map
float4 gloss = tex2D( BumpMapSampler, psInStruct.Tex.xy)*SpecStrength;
float4 Shadow = tex2D( LightMapSampler, psInStruct.Tex.zw);


//light1
float3 LightDir1 = normalize(psInStruct.Sun);
float3 ViewDir1 = normalize(psInStruct.View);
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)), SpecIntensity);
float4 Attenuation1 = saturate(dot(psInStruct.Att1, psInStruct.Att1));

float4 sunOut = (color*diff1 + spec1*gloss.w) * shadow1;

//light2
float3 LightDir2 = normalize(psInStruct.Light2);
float3 ViewDir2 = normalize(psInStruct.View);
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)), SpecIntensity);
float4 Attenuation2 = saturate(dot(psInStruct.Att2, psInStruct.Att2));

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

return (
((color * vecAmbient) + sunOut/2.2) +
((shadow2 * (color * diff2 + (spec2*gloss.w)) * (1 -Attenuation2))*vecLightColor[1])
);

}


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

float3 Light3 : TEXCOORD2;
float Att3 : TEXCOORD3;

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


VS_OUTPUT1 VS_PASS1(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float2 texcoord1 : TEXCOORD1, 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.xy = texcoord0.xy;
Out.Tex.zw = texcoord1.xy;

float3 PosWorld = mul(Pos, matWorld);

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

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

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


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

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

return Out;
}

float4 PS_PASS1( VS_OUTPUT1 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 )*SpecStrength;
float4 Shadow = tex2D( LightMapSampler, psInStruct.Tex.zw);

//light3
float3 LightDir3 = normalize(psInStruct.Light3);
float3 ViewDir3 = normalize(psInStruct.View);
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)), SpecIntensity);
float4 Attenuation3 = saturate(dot(psInStruct.Att3, psInStruct.Att3));

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

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



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

float3 Light5 : TEXCOORD2;
float Att5 : TEXCOORD3;

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


VS_OUTPUT2 VS_PASS2(float4 Pos : POSITION, float2 texcoord0 : TEXCOORD0, float2 texcoord1 : TEXCOORD1, 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.xy = texcoord0.xy;
Out.Tex.zw = texcoord1.xy;

float3 PosWorld = mul(Pos, matWorld);

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

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

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

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

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

return Out;
}

float4 PS_PASS2( VS_OUTPUT2 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 )*SpecStrength;
float4 Shadow = tex2D( LightMapSampler, psInStruct.Tex.zw);

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

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

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

);
}


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

// 2.0
technique lod0
{
pass P0
{
alphablendenable=false;
srcblend=zero;

zwriteenable=true;

// 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;
FogEnable=false;

// 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;
FogEnable=false;

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




The only problem is that the second light doesn't appear to show when created(the light after the sun). And when you create a third light or fourth light, the blending is wrong with them over the geometry. Basically just the specularity looks to light up with these lights, but there not smoothly lit over the geometry. I was wondering if I put the sun in wrong?


Check out Silas. www.kartsilas.com

Hear my band Finding Fire - www.myspace.com/findingfire

Daily dev updates - http://kartsilas.blogspot.com/
Page 2 of 2 1 2

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | 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