2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader

Posted By: Why_Do_I_Die

2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/06/08 11:50

Hello everyone , for one of my current projects , I modified the shader guitarxxx had posted on the contributions , the 3 light shader , I changed it to be a 2 dynamic light shader (no sun) , and a 1 dynamic light shader(no sun). I mainly did this for speed reasons , the shader runs much faster with just 2 lights and only one pass, and even faster with just one light, so I'd thought I'd share here , maybe someone can find it usefull as well.
In the rar there are the scripts you need , all you need to do is copy them to your project folder , and include normalMapping.wdl in your main script , and give your entities the action nMapping1L for 1 light and nMapping2L for using 2 lights.
Heres the link:
http://www.bloodychainsaw.com/normalmap/NormalMapping.rar
Here are some images

2 Lights




1 Light








Posted By: jigalypuff

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/06/08 17:55

thanks for this man, it works great.
Is it possible to have more than one texture map
+ normal maps per model? and if so could you let me know how to add the needed code?
Posted By: lostclimate

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/06/08 18:54

granted i know it is just a demo to test the normal map, but you should fix the spec map on the walls.
Posted By: Why_Do_I_Die

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/06/08 20:20

jigalypuff , I have no idea , i'm not really a shader programmer , I just tried making sense of the code from the forum and edited it till it worked with 2 lights , then it was easy to make it just 1. I know it supports model with difuse texture , plus normal map texture containing specular map in it's alpha channel.

About fixing the spec on the walls , well it was quick demo , and the super glossy reflective walls show very clearly how the effect is working. Of course , for real game you just edit the spec map to the shininess you want , I've tried on other models and the results you get are really nice.
Posted By: jigalypuff

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/06/08 22:42

Erm how many lights can you add in a level? if i add more than 3 everything goes black frown
Posted By: lostclimate

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/06/08 22:51

@jigallypuff

Thats the point of this one, its title clearly says "2 LIGHTS NORMAL MAPPING"

perhaps you should also read the post before you reply.
Posted By: Why_Do_I_Die

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/07/08 02:57

jigalypuff, you can have as many lights as you want in the level , if you are using the 2 lights shader , then you can only have 2 lights active at one time , i.e. , 2 lights have their lightrange > 0, if you are using the one light shader , then you can only have 1 light on at a time , but in the level , you can place as many as you want. The whole idea of having a 2 light shader with 1 pass and a 1 light shader is for speed. The only reason I modified the shader was that other shaders with only had 1 light only used the sun as dynamic light , which to me makes them completely useless. Here is a very simple code you can use to place as many lights as you want in the level and the 2 closest lights to the player will be the ones activated.
Code:
action dynamicLight		//	Attach to entity or entities that are going to be your ligth sources
{
	my.invisible = on;
	my.passable = on;
	my.light = on;
	my.cast = on;		// Cast shadows
	my.red = 255;		// Light red color
	my.green = 255;		// Light green color
	my.blue = 255;		// Light blue color
	my.lightrange = 0;		// Light brightness
	while(!player){wait(1);}
	while(me!=null)
	{
		if(vec_dist(my.x,player.x) < 200)  //// How close the light should be to the player before it activates.
		{
			my.lightrange = 200;  //// Light brightness
		}
		else
		{
			my.lightrange = 0;
		}
		wait(1);
	}
}


The code I posted above will handle the lights on it's own , just position the lights in a way that let's the level flow with them. This code is not good for 2 story buildings , because of how vec_dist works , but modifying it to work with 2 or more story buildings should be pretty easy.
The script will work with the 1 or 2 light shader.

edit: The script is not perfect , and doesn't really calculate the closes to the player , rather than just activates itself if it is close enough to the player , then the engine will use the 2 lights it sees first and ignore extra ones if more than 2 lights are in range at once. However , by cleverly placing the lights , i.e. not putting 5 lights next to each other , but rather in places you want lit , like 1 in a room , another in a hall , another in the next room , ect... , this script should handle the lights pretty good.
I will prolly make a more precise script later on to really handle lights properly, activating only the ones closest to the player , and handling 2 or more story levels , but that will prolly be later on when I get more into the game , I'm still in testing stage of things.
Posted By: xXxGuitar511

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/07/08 05:56

@Jigalypuff) You can use as many diffuse+normal maps on a model as you want. it's in the manual.

You have to use them in sequence. Ex)

Skin1) Diffuse01
Skin2) Normal01
Skin3) Diffuse02
Skin4) Normal02
Skin5) Diffuse03
Skin6) Normal03
etc...
Posted By: jigalypuff

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/07/08 08:10

@lost climate, if i understood shaders then perhaps i`d have understood the one light only thing smile

Why do i do thanks that works great
xxxdisiple cheers man i`ll add the extra textures to the .fx file and see how i go.
Cheers to all.
Posted By: Reigel_Seven

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/08/08 20:09

Somehow I was able to combine Grafton's Projection Flashlight shader with this one. Right now it's only the flashlight + 1 room light, but I'll add more lights later on. I'll post the code later tonight (I'm at work).

I say "somehow" because I know pretty much NOTHING about how shaders work, but with some "advanced" cut-and-pasting I was able to figure it out. Thanks to the OP for this! grin
Posted By: Why_Do_I_Die

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/10/08 04:51

"but with some "advanced" cut-and-pasting" , I see we share the same technique, LOL.
Posted By: jigalypuff

Re: 2 Lights Normal Mapping Shader and 1 Light Normal Mapping Shader - 12/12/08 09:29

is there a way to apply transparency to a texture file useing this shader? like entskin3 and 4 being translucent so it`ll look like glass?
© 2024 lite-C Forums