|
2 registered members (Grant, AndrewAMD),
911
guests, and 9
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Dynamic lights problem
#169301
11/24/07 22:59
11/24/07 22:59
|
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B
OP
Expert
|
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: zSteam]
#169303
11/24/07 23:50
11/24/07 23:50
|
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B
OP
Expert
|
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
Junior Member
|
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); }
|
|
|
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
Expert
|
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
OP
Expert
|
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
|
|
|
|