possible to add proper spotlight support to this shader?

Posted By: pegamode

possible to add proper spotlight support to this shader? - 06/02/12 11:42

Hey there,

I'm using the normal mapping shader with specular map support from the wiki:

Normalmapping Shader (wiki)

This shader is only added to our characters.

In our game there are a few cases where player uses a flashlight.

Now the problem:

Though the shader reacts on the light of the spotlight it seems it doesn't know that it's spotlight. It behaves like the spotlight would be a "normal" dynamic light.

Is it possible to modify the shader so that it recognizes spotlights properly?

I'd like to avoid adding a special spotlight shader like the one from AUM 71.

Regards,
Pegamode.
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/05/12 09:58

Really no one with an answer for that issue?

Is it possible to differ between normal and spotlights within the shader at all?
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/07/12 12:34

Ok. I know now that I can differ within the shader using:

vecLightDir[0].w <= 0

I'd like calculate in the vertex shader if the vertex in currently in the spotlight cone.

Can someone help me with that?

I think first I have to calculate the angle between the light ray and the vertex, right?
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/08/12 18:23

Well... the shader you posted looks pretty complicated.
I'm sorry but I don't understand enough of it to do the changes to make It work with spotlights.

But I'm working on my own lighting shader (Which looks imo much better than the engine standart-lighting) for about a week.

At the moment it supports
sunlight, normal maps, up to 7 lights (including the sun), diffuse lighting, specular lighting and a kind of fog.

I'm now about to work on the spotlight-part (diffuse already works, but I've go problems with specular reflections)

So... If you want to I'll share it with you if its finished.


Kartoffel smile
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/08/12 18:31

Hi Kartoffel,

that would be great.

For our project it is important that the shader supports the specular map as separate texture skin:

texture entSkin1; // color map
texture entSkin2; // normal map
texture entSkin3; // specular map

Does your shader supports this or can it be modified to work like this?

Regards,
Pegamode.
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/08/12 18:39

It doesn't support a specular map, yet. But this modification shouldn't take more than 10 minutes.

Should the Specular map support RGB or is it just used as a kind of alpha-value for the specular light?
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/08/12 18:47

It is just used for the specular light, but as our color map has its own alpha channel we can't use this for a specular map.
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/08/12 19:56

OK, I made a first version of it now. I still have to look what can be made better and more efficient
and maybe some adittional features (if you're still missing something) - but not today.

here's the code.

Have a look at the first 45 lines.

At the moment the SunColor is used as AmbientColor and FogColor.
The Spotlight arc is static for all lights (but it's adjustable).


And please say if you can find any bugs.

EDIT: Another thing:
The shader uses PixelShader 3.0, It doesn't work with lower versions
keep in mind that people need at least a DirectX 9.0c graphics card to use it.

Well... - even my grandma's PC has got a DX9.0c card... but you might add this to the
minimum system requirements if you're working on something commercial.
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/08/12 20:56

Thanks so much.

I'll check it out tomorrow and will give you feedback.
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/09/12 06:24

Hey Kartoffel,

looks great so far.

But there's one strange thing. I wrote a little test program with just a spotlight that rotates 360 degrees, a model and a cam. Once I rotate my model (pan) the lightning gets strange. It depends on what side of the model is currently facing to the cam. One side is lighted double as bright as the other side while the character models back is almost not lighted at all.

Regards,
Pegamode.
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/09/12 06:43

could you upload your test program?
I'm not exactly sure what's wrong.

EDIT: OK I've got this problem, too. I'll see what I can do
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/09/12 07:05

Ok. Great that you can reproduce the problem.
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/09/12 09:48

I updated It
Normalmapping gets now applied correctly.

Download
Posted By: MasterQ32

Re: possible to add proper spotlight support to this shader? - 06/09/12 10:12

Great shader!
It looks really awesome!
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/09/12 10:20

Thank you very much smile

I've got another question
You wrote that you use the shader only for your characters.
Doesn't it look weird if you use a different lighting system for your level? (@ pegamode)
Posted By: painkiller

Re: possible to add proper spotlight support to this shader? - 06/09/12 11:48

good job Kartoffel! Does it also support blocks with their lightmaps?
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/09/12 12:03

@painkiller I'm sorry I don't exactly know what you mean.
Do you mean the static shadows of the level blocks which are placed in WED?
Posted By: painkiller

Re: possible to add proper spotlight support to this shader? - 06/09/12 12:26

Originally Posted By: Kartoffel
@painkiller I'm sorry I don't exactly know what you mean.
Do you mean the static shadows of the level blocks which are placed in WED?


yeah I mean exactly that
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/09/12 13:08

Well I'm not using level-blocks in WED. I'm only using models for my whole levels. (some models have static-lightmaps)

I didn't test it, but I'm pretty sure just setting the LevelBlock's material to the lighting-shader won't work.
I've never written a shader for level blocks, but I think they work different.

If you want to use LevelBlocks you have to use the standart lighting.
The default engine lighting for level blocks shouldn't be that bad.
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/09/12 13:30

Great. Thanks Kartoffel. I'll check it out once I'm back home.

I use the shader for our Meteor Mess 3D project. Actually we don't need any shaders for our environment models. We use a few shaders for flames and water effects.
Posted By: painkiller

Re: possible to add proper spotlight support to this shader? - 06/09/12 14:37

Originally Posted By: Kartoffel
Well I'm not using level-blocks in WED. I'm only using models for my whole levels. (some models have static-lightmaps)

I didn't test it, but I'm pretty sure just setting the LevelBlock's material to the lighting-shader won't work.
I've never written a shader for level blocks, but I think they work different.

If you want to use LevelBlocks you have to use the standart lighting.
The default engine lighting for level blocks shouldn't be that bad.


by looking at specBump.fx it seems that blocks have their normal map on entSkin3 instead of entSkin2. Maybe creating a variant for blocks where the color map alpha is used for specular and entSkin3 is used for normal would work properly

edit: I could get it working in blocks by commenting the define on line 13 (#define SPECULAR_ESKIN3) and in line 77 (inside NormalMapSampler) changing Texture = <entSkin2>; by Texture = <entSkin3>;

Now if the shader could use color map alpha for specular it would be perfect
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/09/12 15:31

change line 163 to
Code:
float4 EffectMask = Color.a;


If you now uncomment #define SPECULAR_ESKIN3 (should be @line13)
the alpha-channel of the color map is used as Specular-intensity

give it a try!
Posted By: painkiller

Re: possible to add proper spotlight support to this shader? - 06/09/12 15:52

works perfectly! thank you very much!
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/09/12 15:55

The shader looks great in my test program.

Unfortunately in MM3D the character gets very dark when adding the shader to it.

Maybe I have to play around with the intensity values a bit? In MM3D we the sunlight is set to 0,0,0 maybe that's the reason.
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/09/12 15:55

Thats nice!

Could you upload the modified .fx-file?
Then I'll delete everything which isn't used anymore.
(And I can use it, too grin )
Posted By: painkiller

Re: possible to add proper spotlight support to this shader? - 06/09/12 16:04

Originally Posted By: Kartoffel
Thats nice!

Could you upload the modified .fx-file?
Then I'll delete everything which isn't used anymore.
(And I can use it, too grin )


Here it is a demo based on spot.c form samples folder. There are two variations of the original .fx, one which uses alpha as specular, and another one which I also modified for blocks ( just changing entSkin2 by entSkin3 in the NormalMapSampler ). In the scene there are two blobs, one is a model and the other one is a block.

Download link: http://www.mediafire.com/?3wbdk4cwyex9pnj
Posted By: MasterQ32

Re: possible to add proper spotlight support to this shader? - 06/09/12 16:56

hey!
i found a bug:
you set Color.a = fAlpha, but you never set fAlpha
i fixed it with adding fAlpha = Color.a in the line after setting Color to the current texture pixel
Posted By: pegamode

Re: possible to add proper spotlight support to this shader? - 06/09/12 18:25

@Master032: Can you give us the line where to add the line?
Posted By: Kartoffel

Re: possible to add proper spotlight support to this shader? - 06/09/12 18:38

Color.a = fAlpha; applies the Entity.alpha to the output color
with this you can make the entity transparent when decreasing the .alpha value of the entity

This line isn't wrong...

(Colormap alpha isn't supported, yet)

Quote:
you set Color.a = fAlpha, but you never set fAlpha

fAlpha is passed by the engine to the shader. It contains the entity.alpha value with the range [0-1]
© 2024 lite-C Forums