|
Change Light direction in Material event...?
#453400
07/24/15 13:55
07/24/15 13:55
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
OP
Expert
|
OP
Expert
Joined: Jul 2002
Posts: 3,208
Germany
|
Hello!
I'm about to do a dirty hack for my game. Let's agree that this is terrible and I shouldn't be doing this. Also, let's do it.
In my game, many entities are models that are actually flat (like sprites)! This causes dynamic lighting to look "wrong", since they're shaded like models. This means that if I move "in front of" a lightsource, the model turns "dark", which makes sense, but is not what I want.
I figured - well, it means that in the calculation of the dotProduct, I'd need to replace the y-coordinate calculation with something like -abs(LightDir.y * Normal.y).
But the thing is - the entity uses mtl_model. Changing that now would be a pain. And even if it weren't, I still don't have a shader ready with Fog, Lighting and all that jazz. Is there one readily available? (I am aware that it shouldn't be too hard to do it, but I'm kinda cautious with turning this into a shader).
So my other idea was: Why not simply change the vecLightPos-information that DoLight (in default.fx) is using? But I can't. I cannot change those values in the material event.
What can I do to render the (flat) model as a Sprite, as far as lighting is concerned?
Perhaps this post will get me points for originality at least.
Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
|
|
|
Re: Change Light direction in Material event...?
[Re: Error014]
#453404
07/24/15 18:25
07/24/15 18:25
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, I usually completelly remove the goraud lighting on character sprites. I do a mix of a floor shadowmap as ambient color plus simple distance lighting. When the sprite is over a block the vecAmbient vector does the job as ambient color, but over terrains or models it is needed to set the sprites UNLIT and LIGHT flags and set its color vector to the objects shadowmap color. I do all this stuff on the trace to the ground.
float4 PS (
float4 tex : TEXCOORD0,
float4 worldPos : TEXCOORD1 ) : COLOR0
{
float4 textureColor = tex2D ( ColorSampler, tex.xy );
float4 color = vecAmbient * vecLight;
float fDepth = distance ( vecViewPos.xyz, worldPos.xyz );
for ( int i=0; i<iLights; i++ )
{
float Distance = distance ( vecLightPos[i].xyz, worldPos.xyz );
float Radiance = saturate ( ( vecLightPos[i].w - Distance ) / vecLightPos[i].w );
color.rgb += vecLightColor[i].rgb * Radiance;
}
color.rgb = saturate ( color.rgb );
color.rgb *= textureColor.rgb;
float Fog = saturate ( ( fDepth - vecFog.x ) * vecFog.z );
color.rgb = lerp ( color.rgb, vecFogColor, Fog );
color.a = min ( vecLight.w, textureColor.a );
return color;
}
var height = c_trace ( &my->x, &vPos, IGNORE_ME | IGNORE_MODELS | IGNORE_SPRITES | SCAN_TEXTURE );
vec_set ( &my->blue, COLOR_WHITE );
if ( HIT_TARGET )
{
if ( you ) // if you exits, is the terrain
{
if ( you->lightmap )
{
BMAP *bmpSkin1 = ent_getskin ( you, 1 );
var scale = bmap_width(you->lightmap) / bmap_width(bmpSkin1);
var format = bmap_lock ( you->lightmap, 0 );
var cX = hit.u1 * scale;
var cY = hit.v1 * scale;
var pixel = pixel_for_bmap ( you->lightmap, cX, cY );
COLOR col;
pixel_to_vec ( &col, NULL, format, pixel );
vec_set ( &my->blue, &col );
set ( my, LIGHT | UNLIT );
bmap_unlock ( you->lightmap );
}
}
else // hit a block
{
reset ( my, LIGHT | UNLIT );
}
}
Other way I can imagine but never did is building a normalmap that describes opposite normals to the face on the borders of the sprite, so when a light is in the sprites back some of the pixels of the border of the sprite are lighted regarding to the light direction. It could look pretty cool. Hope it helps. Salud!
|
|
|
Re: Change Light direction in Material event...?
[Re: txesmi]
#453487
07/28/15 21:03
07/28/15 21:03
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
OP
Expert
|
OP
Expert
Joined: Jul 2002
Posts: 3,208
Germany
|
Thank you!
It wasn't quite completely what I was looking for, but that was due to my kinda vaguely formulated post. No worries, though! The Shader-snippet you posted actually helped me a lot to write a shader that does what I need it to.
Thanks again, and all the best!
Perhaps this post will get me points for originality at least.
Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
|
|
|
|