Depth Shadow Mapping Material Question

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
nickygs
Gnoblar
Posts: 15
Joined: Wed Jul 20, 2016 7:55 pm

Depth Shadow Mapping Material Question

Post by nickygs »

I have used this http://www.ogre3d.org/tikiwiki/Depth+Shadow+Mapping to implement depth shadow maps in Basic tutorial 2.
I have a couple of questions.

Once I set this

Code: Select all

	mSceneMgr->setShadowTextureCasterMaterial("Ogre/DepthShadowmap/Caster/Float");
If I create an entity will I have to set it to have this same material ("Ogre/DepthShadowmap/Caster/Float")? when I do, the entity is blank white i.e. like it can't find the material. In this post http://www.ogre3d.org/forums/viewtopic. ... ng#p442550 Kenshido says
You don't need to set caster material to entities - it's common for all with *->setCastShadows(true).
so I am guessing not, could someone verify? Using either approach I have not seen any self shadowing yet.

This is the receiver code I am using (slightly altered from the cookbook)

Code: Select all

// Basic materials which support shadows as a seperate scheme
material Ogre/DepthShadowmap/BasicTemplateMaterial
{
    // This technique supports dynamic shadows
    technique
    {
        // Base ambient pass
        pass Ambient
        {
            // base colours, not needed for rendering, but as information
            // to lighting pass categorisation routine
            ambient 1 1 1
            diffuse 0 0 0 
            specular 0 0 0 0 
            // Really basic vertex program
            vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTexture
            {
            }
        }
        // Now do the lighting pass
        // NB we don't do decal texture here because this is repeated per light
        pass Lighting
        {
            // base colours, not needed for rendering, but as information
            // to lighting pass categorisation routine
            ambient 0 0 0 
 
            // do this for each light
            iteration once_per_light
 
            scene_blend add
 
            // Vertex program reference
            vertex_program_ref Ogre/DepthShadowmap/ReceiverVP
            {
            }
 
            // Fragment program
            fragment_program_ref Ogre/DepthShadowmap/ReceiverFP
            {
            }
 
            texture_unit
            {
                content_type shadow
                tex_address_mode clamp
                filtering none
            }
        }
 
        // Decal pass
        pass Decal
        {
            // base colours, not needed for rendering, but as information
            // to lighting pass categorisation routine
            lighting off
            // Really basic vertex program
            vertex_program_ref Ogre/BasicVertexPrograms/AmbientOneTexture
            {
                param_named ambient float4 1 1 1 1
            }
            scene_blend modulate
 
            texture_unit
            {
                texture_alias MainTexture
				//commented out because texture was not stretching with object
                //tex_address_mode clamp
            }
        }
    }
}
How I have used the receiver template so far

Code: Select all

import * from "DepthShadowmap.material"
material MyMaterial : Ogre/DepthShadowmap/BasicTemplateMaterial
{
    set_texture_alias MainTexture rockwall.tga
}
I am importing scenes where materials are auto created. In order for these scenes to use depth shadow mapping the materials must inherit from the receiver material. How would one go about this? The http://www.ogre3d.org/forums/viewtopic. ... ng#p409286 post asks a similar question.

Material generated by 3ds max scene export

Code: Select all

material "buddhadefault"
{
	technique buddhadefault_technique
	{
		pass buddhadefault_standard
		{
			ambient 0.588 0.588 0.588 1
			diffuse 0.588 0.588 0.588 1
			specular 0 0 0 0 25.5
			emissive 0 0 0 1
		}
	}
}
Another material generated by 3ds max scene export

Code: Select all

material "sponzaleaf"
{
	technique sponzaleaf_technique
	{
		pass sponzaleaf_standard
		{
			ambient 1 1 1 1
			diffuse 1 1 1 1
			specular 0 0 0 0 25.5
			emissive 0 0 0 1

			scene_blend alpha_blend
			depth_write off
			vertex_program_ref sponzavsLightGENNORM0
			{
			}
			fragment_program_ref sponzafpLightGENDIFF0NORM0
			{
				param_named normalMul float 0.02
			}

			texture_unit sponzaleaf_Diffuse#0
			{
				texture sponzasponza_thorn_diff.png
				tex_coord_set 0
				colour_op modulate
			}

			texture_unit sponzaleaf_Unknown#1
			{
				texture sponzasponza_thorn_mask.png
				tex_coord_set 0
				colour_op modulate
			}

			texture_unit sponzaleaf_Normal#2
			{
				texture sponzasponza_thorn_bump.png
				tex_coord_set 0
				colour_op modulate
			}
		}
	}
	technique sponzaleaf_basic_technique
	{
	scheme basic_mat
		pass sponzaleaf_standard
		{
			ambient 1 1 1 1
			diffuse 1 1 1 1
			specular 0 0 0 0 25.5
			emissive 0 0 0 1

			scene_blend alpha_blend
			depth_write off

			texture_unit sponzaleaf_Diffuse#3
			{
				texture sponzasponza_thorn_diff.png
				tex_coord_set 0
				colour_op modulate
			}

			texture_unit sponzaleaf_Unknown#4
			{
				texture sponzasponza_thorn_mask.png
				tex_coord_set 0
				colour_op modulate
			}
		}
	}
}
As a side note, I am using Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED since it is more efficient than Ogre::SHADOWTYPE_STENCIL_ADDITIVE. In fact the latter cannot even be applied to my imported scenes as the amount of vertices is too high (above the assertion vertice limit for this technique).
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: Depth Shadow Mapping Material Question

Post by tod »

Depth shadow mapping is a texture shadow technique, so any SHADOWTYPE_STENCIL_whatever will not work with it. Texture shadows means that the shadow is generated using a texture. The shadow material is used to generate that texture, so it isn't something that depends on how your entities are drawn (except they that they need to look at the shadow map when drawn).
So, step one, the shadow texture is generated for each light that can cast shadows. The scene is rendered with the camera set at the light position and direction using the shadow material. You will get a texture containing the depth on pixels from the point of view of the light.
Step too, your entities are rendered. The entity material does all the usual color, normal, specular, whatever stuff to determine the color of a pixel then the shadow texture is analyzed to determine if that pixel is in the shadow, and if yes some shadow contribution is added.

The materials generated were useless to me, some time ago when I actually did stuff with ogre. I manually made my materials, and ignored the generated one. Things may have changed, but I doubt it.
Post Reply