[resolved] how to make multi-pass material with shaders

Problems building or running the engine, queries about how to use features etc.
Post Reply
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

[resolved] how to make multi-pass material with shaders

Post by cyrfer »

I'm trying to make my materials use multiple passes, a pass for each light. I see tutorials for this all over the wiki. The problem is they don't work with shaders. I can't get the keywords that control how the passes are split and lighting is iterated to produce anything usable. The material is always washed out. If I use fixed-function materials, OGRE seems to split my pass as advertised. I would very much like some guidance.

I had the idea that I need to enable shadows to get the pass-splitting to work properly. Is this worth a shot?

I'm open to using the new RTShader system for shaders, but after spending hours debugging weird crashes on exit since upgrading from 1.7.3 to 1.9.0, I realized I should at least ask:
How does the RTShader system support multiple lights?
Last edited by cyrfer on Sat May 24, 2014 12:26 am, edited 1 time in total.
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: how to make multi-pass material with shaders

Post by cyrfer »

I just ran the RTShaderSystem examples in 1.9.0 and I'm pretty sure they are broken. I see vertex shading even when the selection says it is using per-pixel shading. Also, that example has a button to 'export material', but clicking it gives me an error that kicks me out of the demo.

Another example crashed when I un-clicked something called 'instance viewports'.
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: how to make multi-pass material with shaders

Post by cyrfer »

I think I've finally gotten to the bottom of why OGRE does not split my passes as advertised in the manual. In the function, SceneManager::updateRenderQueueSplitOptions(), the following code only has 'split' enabled when shadows are in use. I have not even introduced shadows as I was just trying to get shading working. Does it make sense to add a case for splitting passes when no shadows are being used?

Code: Select all

	if (isShadowTechniqueAdditive() && !isShadowTechniqueIntegrated()
		&& mCurrentViewport->getShadowsEnabled())
	{
		// Additive lighting, we need to split everything by illumination stage
		getRenderQueue()->setSplitPassesByLightingType(true);
	}
	else
	{
		getRenderQueue()->setSplitPassesByLightingType(false);
	}

	if (isShadowTechniqueInUse() && mCurrentViewport->getShadowsEnabled()
		&& !isShadowTechniqueIntegrated())
	{
		// Tell render queue to split off non-shadowable materials
		getRenderQueue()->setSplitNoShadowPasses(true);
	}
	else
	{
		getRenderQueue()->setSplitNoShadowPasses(false);
	}
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: how to make multi-pass material with shaders

Post by cyrfer »

I'm not sure what was my original issue. It seems multi-pass materials work very well. I can even use them without shadows enabled. I don't know why it was not working before.

This issue is solved.

In case anyone needs an example of a multi-pass material, which has a separate ambient pass and a pass 'per-light', here you go...

Code: Select all

material passPerLight
{
    receive_shadows on 

    technique
    {
        pass ambient
        {
            ambient 1.0 1.0 1.0 1.0
            emissive 0.0 0.0 0.0 1.0

            // mute dynamic lights in this pass
            diffuse 0.0 0.0 0.0 1.0
            specular 0.0 0.0 0.0 1.0 12.5

            lighting on
            transparent_sorting on

            iteration once
            illumination_stage ambient
            scene_blend one zero

			texture_unit Decal
			{
				texture charMSP.dds
				filtering linear linear linear
			}
			texture_unit Emissive
			{
				texture charRTemiss.dds
				filtering linear linear linear
			}

            vertex_program_ref phong_1UV_fog
            {
            }

            // TODO: need a cheaper pixel shader so I don't have to compute dynamic light values
            fragment_program_ref BP_fog_decal_emissive
            {
            }
        }

        pass per_light
        {
            // mute ambient addition in this pass
            ambient 0.0 0.0 0.0 1.0
            diffuse 1.0 1.0 1.0 1.0
            specular 0.99 0.99 0.99 1.0 12.5
            emissive 0.0 0.0 0.0 1.0

            lighting on
            transparent_sorting on

            iteration once_per_light
            illumination_stage per_light
            scene_blend add

			texture_unit Decal
			{
				texture charMSP.dds
				filtering linear linear linear
			}
			texture_unit Normal
			{
				texture charRTnormal.dds
				filtering linear linear linear
			}
			texture_unit Specular
			{
				texture charRTspec.dds
				filtering linear linear linear
			}

            vertex_program_ref phong_1UV_fog_tangent
            {
            }

            fragment_program_ref BP_fog_decal_normal_specular
            {
            }
        }
    }
}
Post Reply