Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Quad, Ayumi, AndrewAMD), 1,092 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Spotlight vs. Dynamic light #412018
11/21/12 23:02
11/21/12 23:02
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I know how to add simple dynamic point light support into the shader, but how do I add spotlight support?? Here is the Per Pixel Lighting (supporting 4 lights and the sun) from Slins collection, and spotlight doesn't work with it..
Code:
MATERIAL* OS_O_PerPixelLighting_ps20_mat =
{
	effect =
	"
		//Variables
		float4x4 matWorld;
		float4x4 matWorldViewProj;
		
		float4 vecFog;
		float4 vecTime;
		float4 vecColor;
		float4 vecViewDir;
		float4 vecViewPos;
		float4 vecSunDir;
		float4 vecSunColor;
		float4 vecLight;
		float4 vecLightPos[8];
		float4 vecLightColor[8];
		float fAlpha;
		
		
		//Textures
		texture entSkin1;
		
		
		//Sampler
		sampler colorMap = sampler_state
		{
			Texture = (entSkin1);
			AddressU = Wrap;
			AddressV = Wrap;
			
			MagFilter = Linear;
			MinFilter = Linear;
			MipFilter = Linear;
		};
		
		//Structs
		struct VS_TO_PS // Output to the pixelshader
		{
			float4 Pos	: POSITION;
			float  Fog	: FOG;
			
			float2 Tex0	: TEXCOORD0;
			float3 WPos	: TEXCOORD1;
			float3 Norm	: TEXCOORD2;
		};
		
		
		//Vertexshader
		VS_TO_PS VS_v0(	float4 inPos		: POSITION,
								float3 inNormal	: NORMAL,
								float2 inTex0		: TEXCOORD0	)
		{
			VS_TO_PS Out;
			
			//Do transformations
			Out.Pos = mul(inPos,matWorldViewProj);
			
			//Pass the Texcoords
			Out.Tex0 = inTex0;
			
			//Vertexposition in worldspace
			Out.WPos = mul(inPos,matWorld);
			
			//Vertexnormal
			Out.Norm = normalize(mul(inNormal,matWorld));
			
			//Fog
			Out.Fog = 1 - (distance(Out.WPos,vecViewPos)-vecFog.x) * vecFog.z;
			
			return Out;
		}
		
		
		//Pixelshader
		float4 PS_p0( VS_TO_PS In ) : COLOR
		{
			float3 LightDir;
			float3 Diffuse = vecLight.rgb+0.5+saturate(dot(-vecSunDir,In.Norm))*vecSunColor;
			float attenuation = 0;
			
			for(int i = 0; i < 4; i++)
			{
				LightDir = vecLightPos[i]-In.WPos;
				attenuation = saturate(1.0f - length(LightDir/vecLightPos[i].w));
				Diffuse += saturate(dot(normalize(LightDir),In.Norm))*vecLightColor[i]*attenuation;
			}
			
			float4 Color = tex2D(colorMap,In.Tex0);
			Color.rgb *= Diffuse;
			
			Color.a = step(0.5,Color.a);
			
			return Color;
		}
		
		
		//////////////////////////////////////////////////////////////////
		technique Lighting
		{
			pass one
			{
				AlphaTestEnable = True;
				zWriteEnable = true;
				
				VertexShader = compile vs_1_1 VS_v0();
				PixelShader = compile ps_2_0 PS_p0();
			}
		}
		
		technique fallback { pass one { } }
	";
}


If I assign this shader to terrain (just to see how it works) I get nothing, but if I debug via F11, I can see the spotlight.. WTF? Where can I read about spotlight stuff??
Here are the screens to show the problem:
Quote:
Without debugging:

With debugging:

And as you can see, model isn't affected by light anyway.. only terrain, what could cause this?


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Spotlight vs. Dynamic light [Re: 3run] #412021
11/21/12 23:28
11/21/12 23:28
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
I can create an example for you but right now it's too late, sorry.
I'll have a look tomorrow wink


POTATO-MAN saves the day! - Random
Re: Spotlight vs. Dynamic light [Re: Kartoffel] #412025
11/21/12 23:40
11/21/12 23:40
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
No need to hurry my friend laugh I'll wait for it, thank you for your time.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Spotlight vs. Dynamic light [Re: 3run] #412093
11/22/12 16:20
11/22/12 16:20
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Okay, I added simple spotlight support to the shader wink
The only drawbacks are a static spotlight arc and that it now needs ps and vs 3.0; I hope thats ok smirk

I also changed the ambient lighting. It's now controlled by entity.ambient.

download


POTATO-MAN saves the day! - Random
Re: Spotlight vs. Dynamic light [Re: Kartoffel] #412097
11/22/12 16:39
11/22/12 16:39
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
It's perfect man! laugh Thank you very much, Random also needed this for his horror project, so you got already two projects with credit of your name wink


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Spotlight vs. Dynamic light [Re: 3run] #412100
11/22/12 16:55
11/22/12 16:55
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Great to hear that smile

Actually it are only 5 simple lines of code, but when I was adding spotlight
support to my own object shader it took me a long time to get it working smirk

Anyway, I'm glad that you like it laugh

Last edited by Kartoffel; 11/22/12 17:00.

POTATO-MAN saves the day! - Random
Re: Spotlight vs. Dynamic light [Re: Kartoffel] #412118
11/22/12 21:42
11/22/12 21:42
Joined: Feb 2010
Posts: 886
Random Offline
User
Random  Offline
User

Joined: Feb 2010
Posts: 886
Potato-man saves the day!
You defiantly have my credits ^^



Re: Spotlight vs. Dynamic light [Re: Random] #412120
11/22/12 21:54
11/22/12 21:54
Joined: Feb 2010
Posts: 886
Random Offline
User
Random  Offline
User

Joined: Feb 2010
Posts: 886
Is there a way to make everything alot darker??



Re: Spotlight vs. Dynamic light [Re: Random] #412130
11/23/12 09:35
11/23/12 09:35
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
I think you can do it in many ways but one way (and not the best) is to multiply the diffuse term with a number bellow 1 (I'm not a shader expert tongue ).

Code:
Color.rgb *= Diffuse * 0.02;



I think it is best to have that in a variable that can be changed easily.

Last edited by 3dgs_snake; 11/23/12 09:38.
Re: Spotlight vs. Dynamic light [Re: 3dgs_snake] #412149
11/23/12 13:19
11/23/12 13:19
Joined: Feb 2010
Posts: 886
Random Offline
User
Random  Offline
User

Joined: Feb 2010
Posts: 886
Well, now the shader doesn`t support lights at all...



Page 1 of 2 1 2

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