Self Shadowing of Terrain onto units
I am working on self shadowing my terrain, and have a static map of the self shadowing locations. Now how could one darken the units on the terrain that are in the hills shadow? Thanks
Figure out where the units are in relation to your lightmap. Find the lightmap x and y coords for the unit, and shadow them.
heres an interesting thought, use the heightmap combined with a self shadowing bumpmap algorithm to determine a "maximum shadowed height" for every vertex on the heightmap, a unit could sample determine its 4 (or i suppose more) terrain vertices that affect it, grab all of those heights, average them, and compare it to the units height. (or even "better" do individual comparisons for EVERY position, ie sample at terrain vertex 1, compare with height of unit over terrain vertex 1 and so on)
of course this isnt per pixel, its only per unit, but without shadow mapping, or stencil shadows, you really cant be
hope that helps
-Dan
of course this isnt per pixel, its only per unit, but without shadow mapping, or stencil shadows, you really cant be
hope that helps
-Dan
since i am at my office right now... i dont have the time to register. will do that in the evening :) till then, my name is Taha and here is a quick reply
the problem with Ademan555's approach is that it will slow down, if there are lots of units on the screen at once... it is "do-able" and certainly not very difficult, but it is not scalable.
an excellent approach is present in the December 2005 DirectX SDK sample. the idea is novel and scalable to hundreds or thousands of units on screen. it does not involve any realtime computation.
the trick is this. since you have a terrain, i presume you have a quad or oct tree. now in your quad or oct tree structure, add a value for shadow colour for each cell. when you are constructing the quad/oct tree, fill in this value with the colour of the shadow, by referring to your light map.
during the game, you simply determine the cell in which the unit is standing in (which you should already be doing). once the cell has been determined, get the colour of the cell. pass this colour to your pixel shader and take this into account, when lightning your unit... and presto! you are done :)
the problem with Ademan555's approach is that it will slow down, if there are lots of units on the screen at once... it is "do-able" and certainly not very difficult, but it is not scalable.
an excellent approach is present in the December 2005 DirectX SDK sample. the idea is novel and scalable to hundreds or thousands of units on screen. it does not involve any realtime computation.
the trick is this. since you have a terrain, i presume you have a quad or oct tree. now in your quad or oct tree structure, add a value for shadow colour for each cell. when you are constructing the quad/oct tree, fill in this value with the colour of the shadow, by referring to your light map.
during the game, you simply determine the cell in which the unit is standing in (which you should already be doing). once the cell has been determined, get the colour of the cell. pass this colour to your pixel shader and take this into account, when lightning your unit... and presto! you are done :)
did you consider shadowmaps already?
you would need a orthogonal projection to the center of your visible scene from the light's direction
render a z pass for the terrain and use this for shadowing
you would need a orthogonal projection to the center of your visible scene from the light's direction
render a z pass for the terrain and use this for shadowing
Quote:Original post by Basiror
did you consider shadowmaps already?
you would need a orthogonal projection to the center of your visible scene from the light's direction
render a z pass for the terrain and use this for shadowing
I am using shadowmaps as of now but when I render my terrain the whole shadowmap is fairly dark. So I only render my units when I do my shadowmap pass to get my units shadows, and am using a static lightmap with my self shadowing to get my terrain to self shadow... So far all have had great ideas, but not sure how to get my shadowmapping to do what I want to do... Thanks
Well, if i remember right you had been using arb fp/vp, but you had problems with user clip planes, so you (i guess) switched to fixed function. Are you sure it wasnt a driver issue? It may be worthwhile to go back to arb fp/vp (especially since iirc your shadowmapping (if you had implemented it back then) was working the way you wanted)
cheers
-Dan
cheers
-Dan
Quote:Original post by Ademan555
Well, if i remember right you had been using arb fp/vp, but you had problems with user clip planes, so you (i guess) switched to fixed function. Are you sure it wasnt a driver issue? It may be worthwhile to go back to arb fp/vp (especially since iirc your shadowmapping (if you had implemented it back then) was working the way you wanted)
cheers
-Dan
Wow someone remembered what I was using a long time ago. :) No I ported my code from VP/FP to GLSL awhile ago. I am doing Shadowmapping in GLSL now. The clipplane issue is still here on Nvidia cards, but not ATI. The messed up thing is it renders fine on both cards, but the image that is stored in my textures from the clipplanes is wrong... Odd.
anyways, if we could take a look at your shader source then, we may be able to help you with your "too dark" shadow maps
cheers
-Dan
cheers
-Dan
vec4 shadowColor = vec4(shadow2DProj(shadowmap, projCoord).r + kTransparency);
that's the code to access the shadowmap.
varying vec4 projCoord; vec4 realPos = gl_ModelViewMatrix * gl_Vertex; projCoord = gl_TextureMatrix[0] * realPos;
that should be it... Then modulate shadowColor by the gl_FragColor
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement