Gamestudio Links
Zorro Links
Newest Posts
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
Data from CSV not parsed correctly
by jcl. 04/20/24 08:32
Zorro FIX plugin - Experimental
by jcl. 04/20/24 08:30
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (7th_zorro, 1 invisible), 581 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
Expert
Error014  Offline 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 Offline
Serious User
txesmi  Offline
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.

Code:
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;
	}



Code:
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 Offline OP
Expert
Error014  Offline 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!
Re: Change Light direction in Material event...? [Re: Error014] #453496
07/29/15 11:14
07/29/15 11:14
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Glad to help laugh

Re: Change Light direction in Material event...? [Re: txesmi] #453505
07/29/15 20:11
07/29/15 20:11
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
it could be also solved by manipulation the vertex normals, once on entity creation.
e.g. for sprite grass I set the vertical (0,0,1), but it is better to lerp them between default normal and vertical normal, thus you get some lighting, but very softly. for me it is better as this solution is cheap and does not break the lighting of the entire scene.


Free world editor for 3D Gamestudio: MapBuilder Editor

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