Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,251 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
adding dynamic lights #149600
08/21/07 23:37
08/21/07 23:37
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline OP
Expert
mpdeveloper_B  Offline OP
Expert

Joined: Feb 2006
Posts: 2,185
i'm trying to add dynamic lights to a static light shader, i want to include support for all 8 lights, but how do i do it? i started working on being able to move through each light, but i don't know how to set it to use all of the lights around you:

Code:

float4 SpecularIntensity = {2.0f, 2.0f, 2.0f, 2.0f};

// Application fed data:
float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matWorldInv;

float4 vecAmbient;
float4 vecLightPos[8];
float4 vecLight[8];
float vecLightColor[8];
float3 vecViewDir;
float3 vecViewPos;

texture entSkin1;
texture entSkin2;

samplerCUBE CubeMapSampler = sampler_state
{
Texture=<entSkin2>;
};
sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
AddressU = Clamp;
AddressV = Clamp;
};

void SpecularCubeVS(in float4 InPos : POSITION,
in float3 InNormal : NORMAL,
in float2 InTex : TEXCOORD0,

out float4 OutPos : POSITION,
out float2 OutTex : TEXCOORD0,
out float3 OutTexCube : TEXCOORD1,
out float3 OutNormal: TEXCOORD2,
out float3 OutViewDir: TEXCOORD3)
{
OutPos = mul(InPos, matWorldViewProj);

OutNormal = normalize(mul(InNormal,matWorld));

OutViewDir = mul(InPos, matWorld);

OutTex = InTex;

float3 V = normalize(vecViewDir);
float3 N = normalize(mul(InNormal, matWorld));
OutTexCube = reflect(V,N);
}

float number;

float4 SpecularCubePS( in float2 InTex : TEXCOORD0,
in float3 InTexCube : TEXCOORD1,
in float3 InNormal : TEXCOORD2,
in float4 InViewDir : TEXCOORD3) : COLOR
{
number = 1;
InNormal = normalize(InNormal);
float4 Ambient = vecLight[number];

float4 Diffuse = saturate(dot(vecLightColor[1], InNormal));

float4 texColor = tex2D(ColorMapSampler, InTex);
float4 cubeColor = texCUBE(CubeMapSampler, InTexCube);
float4 Color = lerp(texColor, cubeColor, 1 - texColor.a);

float3 R = normalize(2 * dot(InNormal, vecLightColor[number] + SpecularIntensity) * InNormal - SpecularIntensity);

InViewDir = vecLightPos[number] + SpecularIntensity *vecLight[number];

float Specular = saturate(dot(R, InViewDir));
return (Ambient + Diffuse + Specular) * Color;
}

technique SpecularCubeTechnique
{
pass P0
{
AlphaBlendEnable = False;
ZWriteEnable = True;
VertexShader = compile vs_2_0 SpecularCubeVS();
PixelShader = compile ps_2_0 SpecularCubePS();
}
}



as you can see i can set it to 1 light, but no more...i can set the number of the light it uses, but that's all...


- aka Manslayer101
Re: adding dynamic lights [Re: mpdeveloper_B] #149601
08/23/07 17:54
08/23/07 17:54
Joined: Aug 2007
Posts: 17
S
sCKan Offline
Newbie
sCKan  Offline
Newbie
S

Joined: Aug 2007
Posts: 17
it only works with 1 light because float number has a value of 1
i think that you need a bucle :

for (number=1; number<=8; number+=1) {}


try thiis :


float number;

float4 SpecularCubePS( in float2 InTex : TEXCOORD0,
in float3 InTexCube : TEXCOORD1,
in float3 InNormal : TEXCOORD2,
in float4 InViewDir : TEXCOORD3) : COLOR
{
number = 1;
InNormal = normalize(InNormal);

//add a bucle im not sure if is number+=1 or number++
for (number=1; number<=8; number++) {

float4 Ambient = vecLight[number];

float4 Diffuse = saturate(dot(vecLightColor[1], InNormal));

float4 texColor = tex2D(ColorMapSampler, InTex);
float4 cubeColor = texCUBE(CubeMapSampler, InTexCube);
float4 Color = lerp(texColor, cubeColor, 1 - texColor.a);

float3 R = normalize(2 * dot(InNormal, vecLightColor[number] + SpecularIntensity) * InNormal - SpecularIntensity);

InViewDir = vecLightPos[number] + SpecularIntensity *vecLight[number];

} //end for

float Specular = saturate(dot(R, InViewDir));
return (Ambient + Diffuse + Specular) * Color;
}


Web Master

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