Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (Grant, AndrewAMD), 911 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Dynamic lights problem #169301
11/24/07 22:59
11/24/07 22:59
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline OP
Expert
mpdeveloper_B  Offline OP
Expert

Joined: Feb 2006
Posts: 2,185
First of all i'm using a6 com, so i can't use more than 8 dynamic lights, now on to the problem.

ok, the problem is in the pixel shader, you can see that a for loop has been added to go through the numbers from 0-8, but i'm not sure how to use for loops, so i may have this wrong...

What i'm trying to accomplish is getting all 8 dynamic lights to move across the model using diffuse lighting as well as specular lighting, the diffuse lighting needs to be colored by the dynamic light, and the specular lighting needs to "shine" from the direction of the light....but i don't know how to accomplish this, if you need the whole shader i'll post it.

Code:

float4 SpecularCubePS( in float2 InTex : TEXCOORD0,
in float3 InTexCube : TEXCOORD1,
in float3 InNormal : TEXCOORD2,
in float4 InViewDir : TEXCOORD3) : COLOR
{
InNormal = normalize(InNormal);
//add a bucle im not sure if is number+=1 or number++
int number;
for (number = 0; number<=8; number++)
{
number += 1;
float4 Ambient = vecLight;

float4 Diffuse = saturate(dot(vecLightColor[number], 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;
float Specular = saturate(dot(R, InViewDir));
return (Ambient + Diffuse + Specular) * Color;
} //end for
}




- aka Manslayer101
Re: Dynamic lights problem [Re: mpdeveloper_B] #169302
11/24/07 23:37
11/24/07 23:37
Joined: Mar 2007
Posts: 99
Germany
zSteam Offline
Junior Member
zSteam  Offline
Junior Member

Joined: Mar 2007
Posts: 99
Germany
hi look into the 3dgs manual => search for vecLightPos or vecLightColor.
you need a vertexshader to calculate the lights.


=> www.alrik-online.de
A7 Commercial
Re: Dynamic lights problem [Re: zSteam] #169303
11/24/07 23:50
11/24/07 23:50
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline OP
Expert
mpdeveloper_B  Offline OP
Expert

Joined: Feb 2006
Posts: 2,185
i am using both of them, they are defined using an array of 8 for 8 dynamic lights:

float4 vecLightColor[8];
float4 vecLightPos[8];

they are also positioned in the pixel shader above, here is the vertex shader i'm using:

Code:

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,
out float Fog_out : FOG)
{
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);

//Fog
Fog_out = 1 - (distance(OutViewDir, vecViewPos) - vecFog.x) * (vecFog.z);
}



the pixel shader is in the first post, as well as the problem.


- aka Manslayer101
Re: Dynamic lights problem [Re: mpdeveloper_B] #169304
11/25/07 00:10
11/25/07 00:10
Joined: Mar 2007
Posts: 99
Germany
zSteam Offline
Junior Member
zSteam  Offline
Junior Member

Joined: Mar 2007
Posts: 99
Germany
try this basic structure

Code:

float4x4 matWorldViewProj;
float4x4 matWorld;

float4 vecLightPos[8]; // preset this with light positions (xyz) and ranges (w)
float4 vecLightColor[8]; // preset this with light colors

// return the dynamic light on the surface
float4 DoPointLight(float3 P, float3 N, int i)
{
// calculate the light ray pointing from the light to the surface
float3 D = (float3)vecLightPos[i]-P;

// calculate the angle between surface and light ray
float NdotL = dot(N,normalize(D));

// modulate the light by the surface angle
float4 Color = vecLightColor[i] * NdotL;

// calculate the light attenuation factor
float fac = 0.f;

if (NdotL >= 0.f && vecLightPos[i].w > 0.f)
{
// get the distance factor
float LD = length(D)/vecLightPos[i].w;

// linear Lighting
if (LD < 1.f)
fac = 1.f - LD;
}
return Color * fac;
}

struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 texCoord0: TEXCOORD0;
float3 texCoord1: TEXCOORD1;
float Fog : FOG;
float4 Color : COLOR0;
};

VS_OUTPUT VertexShader(float4 inPos : POSITION, float2 intexCoord0 : TEXCOORD1, float3 inNormal : NORMAL)
{
VS_OUTPUT Out = (VS_OUTPUT) 0;

Out.Pos = mul(inPos, matWorldViewProj);

......

float3 N = normalize(inNormal);
float3 P = mul(inPos,matWorld);

//Out.Fog = doFog_2(inPos);
Out.Color = float4(0.f,0.f,0.f,0.f);

for (int i=0; i<6; i++)
{
Out.Color += DoPointLight(P,N,i);
}
return Out;
}

........

struct PS_INPUT
{
float2 texcoord0: TEXCOORD0;
float4 texcoord1: TEXCOORD1;
float4 Color : COLOR0;
};

float4 PixelShader(PS_INPUT In) : COLOR0
{
float4 base = tex2D(ColorMapSampler, In.texcoord0);

.............

return (base+.5f) + (In.Color*base);
}




=> www.alrik-online.de
A7 Commercial
Re: Dynamic lights problem [Re: zSteam] #169305
11/25/07 00:16
11/25/07 00:16
Joined: May 2005
Posts: 2,713
Lübeck
Slin Offline
Expert
Slin  Offline
Expert

Joined: May 2005
Posts: 2,713
Lübeck
Code:

for (number = 0; number<=8; number++)
{
number += 1;
float4 Ambient = vecLight;

float4 Diffuse = saturate(dot(vecLightColor[number], 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;
float Specular = saturate(dot(R, InViewDir));
return (Ambient + Diffuse + Specular) * Color;
} //end for



number++ is the same as number += 1.

Get rid of the "number += 1;" line, take the return out of the loop as well as the variable declarisons. Don´t overwrite the variables but combine them.

Re: Dynamic lights problem [Re: Slin] #169306
11/25/07 00:18
11/25/07 00:18
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline OP
Expert
mpdeveloper_B  Offline OP
Expert

Joined: Feb 2006
Posts: 2,185
ok, so put all the floats outside of the function as well as the integer definition and make it a void? as well as removing the number += 1, is this what you mean?


- aka Manslayer101

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