Stencil shadows + Per pixel lighting in shader

Started by
14 comments, last by Vilem Otte 14 years, 4 months ago
OK thanks a lot ! No I have a lot of implementing ahead ;)
Advertisement
Well hello again, I hope you guys will stop by this topic once again...

So as you pointed out, I've turned on fragment shader on the lighting phase, with stencil buffer testing, and seemed OK. Shader was applied only on non-shadowed areas.

But when I tried to turn on vertex shader as well, it did not work. Nothing was applied on non shadowed areas, and there were strange artifacts popping out when I was moving camera.

Is there anything special to do with vertex shader so it will work with stencil testing?

I was trying to apply very simple shaders first:
vertex shader:
void main(	float4 position : POSITION,					float2 texCoord : TEXCOORD0,										out float2 otexCoord : TEXCOORD0,										out float4 oPosition : POSITION,                    uniform float4x4 modelViewProj){  oPosition = mul(modelViewProj, position);    otexCoord = texCoord;}


fragment shader:
void main(	float4 color  : COLOR,				    float2 texCoord  : TEXCOORD0,										uniform sampler2D Texture: TEXUNIT0,											out float4 oColor     : COLOR)					{   	oColor = tex2D(Texture,texCoord);		}


well, what now ? :-(


[Edited by - thomas3711 on December 3, 2009 8:49:18 AM]
Do you use the exact same vertex shader in all passes?
Because of precision issues oPosition = mul(modelViewProj, position) might not match the fixed function transform, or if you change the matrix somehow. If you draw two passes, it is important to use the exact same transform each time.
I'm not familiar with the particular shader type you use, is it CG?
In GLSL there's gl_Position = ftransform() which will do exactly the same transform as the fixed function, in case you use the fixed function for the first pass.
Yes the shader is Cg and I did not realize that here can be differencies between precision of fixed pipeline and vertex shader. I thought that the vertex shader does exactly the same.

Nevertheless it seems to be working now...I won't be making any sudden conclusions...but again thanks a lot!
hmm now my effects, particle systems and glows behave very strange. When the camera is still everything is OK, but when I move camera they seem to move slower then rest of the scene, which looks strange when you try to look around.

Probably the issue with precision (fixed pipeline vs. vertex shader) ... but using the same vertex shader for effects, particle systems and glows did not solve the problem. Iam in dead end. Something is very wrong with my engine.

I must do the shadows differently. Is there a way to pass stencil shadow into fragment shader as a texture ? Or as anything else? I need this information in shader.
Just be sure to turn off everything you turned on (including shaders, etc.) - this is able make really hard nightmares. (haven't you forgot to turn off stencil testing?)

Also make sure your timing is working and be sure that timing on your particles is same as timing for your camera.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

This topic is closed to new replies.

Advertisement