|
|
light position
#407238
09/10/12 04:51
09/10/12 04:51
|
Joined: Apr 2008
Posts: 245
GameScore
OP
Member
|
OP
Member
Joined: Apr 2008
Posts: 245
|
i used the specular shader from the workshop and as light sourec is the sun declared how can i declare my own light source which i can adjust by skills
// Calculate the ambient term:
float4 Ambient = AmbientIntensity * vecAmbient;
// Calculate the diffuse term:
InNormal = normalize(InNormal);
float4 Diffuse = DiffuseIntensity * SunColor * saturate(dot(-vecSunDir, InNormal));
// Fetch the pixel color from the color map:
float4 Color = tex2D(ColorMapSampler, InTex);
// Calculate the reflection vector:
float3 R = normalize(2 * dot(InNormal, -[b]vecSunDir[/b]) * InNormal + vecSunDir);
// Calculate the speculate component:
float Specular = pow(saturate(dot(R, normalize(InViewDir))), SpecularPower) * SpecularIntensity;
// Calculate final color:
return (Ambient + Diffuse + Specular) * Color;
}
Last edited by GameScore; 09/10/12 04:52.
|
|
|
Re: light position
[Re: GameScore]
#407275
09/10/12 17:27
09/10/12 17:27
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
I'm not exactly sure what you're up to.
The easiest way to use dynamic lights is tu just place dynamic lights in your lite-c script via the entities' lightrange and red green and blue parameters. You can then use vecLightPos and vecLightColor in your shader. Thats even the way the shaders of Gamestudio work.
In order to have a lightsource per material you can set the material's skills and then access these in the shader via the vecSkill1 .. vecSkill17 variables. It would work out very similarly for a per entity solution.
Given your code above you just had to replace vecSunDir with the variable you wanted to use instead. Don't forget to declare them in shader as well. Sorry if that is too obvious to you, I don't know you shader skill level... ;-)
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: light position
[Re: Uhrwerk]
#407277
09/10/12 18:32
09/10/12 18:32
|
Joined: Apr 2008
Posts: 245
GameScore
OP
Member
|
OP
Member
Joined: Apr 2008
Posts: 245
|
yeah your 2nd idea is what i wanna do, i was try to do but withou succes here u can see how i was try to do
float redskill = vecSkill1.x;
float greenskill = vecSkill1.y;
float blueskill = vecSkill1.z;
float alphaskill = vecSkill1.w;
float4 dynlight = {redskill, greenskill, blueskill, alphaskill};
float4 Diffuse = DiffuseIntensity * saturate(dot(-dynlight, InNormal));
// Fetch the pixel color from the color map:
float4 Color = tex2D(ColorMapSampler, InTex);
// Calculate the reflection vector:
float3 R = normalize(2 * dot(InNormal, -dynlight) * InNormal + dynlight);
but the result is not very nice
|
|
|
Re: light position
[Re: GameScore]
#407280
09/10/12 20:29
09/10/12 20:29
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Some thoughts:
Did you remember to use the float conversion with floatv?
As you use a texture lookup this is most likely a pixel shader. Hence InNormal is already in viewspace. Is that also true for vecSkill1? You have most likely set it in world space, didn't you?
You don't need the detour via redskill etc. and dynlight. You can use vecSkill1 directly as a vector afaik.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
|
|
|