Official Community Forums
 
HomeHome  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log in  The Wiki  Website  github Project  

Share | 
 

 Shadow Material SOLVED

View previous topic View next topic Go down 
AuthorMessage
Guest
Guest



PostSubject: Shadow Material SOLVED   Fri 5 Oct - 0:38

Issue 1
We were mucking around with coloring the shadows
as part of a weather system... e.g. bluish for bright sunny day.

There are other ways to do it but when trying to set param_named ShadowColor float4 0 0 0 1
in sampleworld\Materials\MVSMShadows.material to color the shadows we discovered that ShadowColor is ignored. I can set the shadow color directly in MVSMShadows.cg just fine with
Code:
ShadowColor *= float4(0.0,0.0,0.6,1.0);

Issue 2
This led to copying/modding custom shadow_caster, shadow_receiver vert / frag shaders, .material and .program.

The first 3 work as expected in one pass in our material and pull in our custom shadow shaders
shadow_caster_vertex_program_ref
shadow_caster_fragment_program_ref
shadow_receiver_vertex_program_ref


The shadow receiver frag shader declaration however does not pull in our shader. Regardless of what we do.
shadow_receiver_fragment_program_ref

Have tried splitting caster and receivers into separate passes, receiver frag only in second pass and
a gazillion other combos. Using WorldEditor for this and checking WorldEditor.log and others.

Worked with shaders before and getting the results I expect for everything but
the frag prog ref shadow_receiver_fragment_program_ref Just won't substitute our shader! Sad

A partial example of our material

Code:
material ourTexture_png
{
       
 technique
  {
      pass Test1
      {   
           
//WORKING: The caster vert and frag ref, and the receiver vert ref work as expected
shadow_caster_vertex_program_ref Auro/customShadowCasterVP
            {
                 param_named_auto ModelViewProjection worldviewproj_matrix
              param_named_auto AmbientLight ambient_light_colour
            }
     

//Our caster frag shader is successfully substituted during the shadow pass   
shadow_caster_fragment_program_ref Auro/customShadowCasterFP
            {
              param_named DepthOffset float 0.001           
            }

 //Our receiver vert shader seems to be used as we can mod and see the results
 shadow_receiver_vertex_program_ref Auro/customShadowReceiverVP
            {
              param_named_auto ModelViewProjection worldviewproj_matrix
             param_named_auto Model world_matrix
              param_named_auto TextureViewProjection texture_viewproj_matrix
              param_named_auto FadeSettings shadow_fade_params
            }
//end Working


//NOT WORKING
//Receiver frag prog will thow errors in WorldEditor.log on load if we deliberately insert errors in our .cg shader :D
//but even without errors it is still  ***  Not pulled in ***  i.e. MVSMShadowReceiverFP is still the one used.
shadow_receiver_fragment_program_ref Auro/customShadowReceiverFP
            {
            param_named ShadowColor float4 0 0 0 1
           param_named TexelOffset float2 0 0
            }           

//**************  Texture  *******************

 texture_unit
        {
            texture ourTexture.png
        }


//end    pass test1
  }
//end  technique
}

//end Material
}



Have checked the old forums/wiki/google and found issues but no solutions.

(EDIT) Even poked around in the client code MaterialSerializer.cs around line 1425 at ParseShadowReceiverFragmentProgramRef to see if there were comments.




As always Thanks in advance! Very Happy

Cheers



Last edited by Koron on Sun 4 Nov - 5:33; edited 1 time in total
Back to top Go down
Agamemnon
Experienced Newbie
Experienced Newbie
avatar

Posts : 28
Join date : 2012-08-26
Location : Marietta, Georgia

PostSubject: Re: Shadow Material SOLVED   Sat 6 Oct - 4:48

For number one and two on our Hi-Res LOD shaders we used this:

// Vertex program reference
vertex_program_ref Examples/CompoundVS_Skinned
{
param_named_auto FogSettings fog_params
param_named_auto WorldMatrix3x4Array[0] world_matrix_array_3x4
param_named_auto ViewProj viewproj_matrix
param_named_auto WorldMatrix world_matrix
param_named_auto LightPosition[0] light_position_object_space 0
param_named_auto LightPosition[1] light_position_object_space 1
param_named_auto LightAttenuation[0] light_attenuation 0
param_named_auto LightAttenuation[1] light_attenuation 1
param_named_auto EyePosition camera_position_object_space
}
shadow_caster_vertex_program_ref CompoundVS4_Shadow_Skinned
{
}
shadow_receiver_vertex_program_ref CompoundVS4_ShadowReceiver_Skinned
{
}
fragment_program_ref Examples/CompoundPS_20_NS
{
param_named LMe float4 0 0 0 1
param_named_auto LMa ambient_light_colour
param_named_auto LMd[0] light_diffuse_colour 0
param_named_auto LMd[1] light_diffuse_colour 1
param_named_auto LMs[0] light_specular_colour 0
param_named_auto LMs[1] light_specular_colour 1
param_named shininess float 10


Back to top Go down
Agamemnon
Experienced Newbie
Experienced Newbie
avatar

Posts : 28
Join date : 2012-08-26
Location : Marietta, Georgia

PostSubject: Re: Shadow Material SOLVED   Sat 6 Oct - 5:01

This is a better shot with the lighting and all of the shaders and textures and LOD's on. The other one was a much earlier version.



Back to top Go down
Guest
Guest



PostSubject: Shadow Shaders   Sat 6 Oct - 6:54

Thanks for the response Agamemnon Smile

We can get the shadow caster shaders to work in the material. It's just our receiver frag shader
that "shadow_receiver_fragment_program_ref" won't pull in.

We can change how the shadows are written to the shadow map just fine.

From what I've read so far in the wiki and over at the Ogre and Axiom forums I should
just be able to have our receiver frag cg shader substituted by putting "shadow_receiver_fragment_program_ref" in the material.

Not that it's not working right, just not getting used at all,
the "fragment_program_ref MVSMShadowReceiverFP" in the MVSMShadowReceiver material is used no matter what.

Been poking around in the source code for the WorldEditor and Client and can see
where "MVSMShadowReceiver" is set/hardcoded as the shadow receiver material and also where
"shadow_receiver_fragment_program_ref" is set/used etc.

MaterialSerializer.cs
Code:

[MaterialAttributeParser("shadow_receiver_fragment_program_ref", MaterialScriptSection.Pass)]
      protected static bool ParseShadowReceiverFragmentProgramRef(string parameters, MaterialScriptContext context)


Some links for custom shadows
http://www.multiversemmo.com/wiki/Calling_Vertex_and_Fragment_Programs_in_a_Pass#param_indexed_auto
http://www.cse.unr.edu/~sushil/models/381/material/scripts/Examples-Advanced.material
http://www.ogre3d.org/docs/manual/manual_23.html

Just have some more work to do that's all. Very Happy

I am probably just not understanding the order of the material swapping going on in the reg/lighting/shadow passes. study

Your pics didn't come through btw Sad

Thx again
Back to top Go down
Guest
Guest



PostSubject: Shadow Receiver   Tue 9 Oct - 22:44

Shadows Update

Haven't had much time to work on shadows lately. Sad

Perhaps the problem is that the shadow caster and/or receiver materials are
hardcoded in 3 different places in the client code!

Probably why, at least in our materials, "shadow_receiver_fragment_program_ref" has no effect...

Can't complain though since 99% of the work is done for us . cheers


Cheers



Back to top Go down
Guest
Guest



PostSubject: DeriveShadowReceiverPass   Thu 1 Nov - 16:46

Update

Have finally cornered this issue in
Axiom\Engine\Core\SceneManager.cs @ DeriveShadowReceiverPass(...) around line 1816

It seems that the custom shadow receiver frag program isn't being considered unless additive shadows are true.
Code:
if (IsShadowTechniqueAdditive)

Can now get the following material file attribute to substitute my receiver shadow frag prog
Code:
 "shadow_receiver_fragment_program_ref"

Trying to decide the best spot to put ( along with prg load etc)
Code:
pass.SetShadowReceiverFragmentProgram(pass.ShadowReceiverFragmentProgramName)

Now all I have to do is get my version of "ShadowReceiverFP" perfect Very Happy


As always any help appreciated Very Happy

Cheers


Last edited by Koron on Sun 4 Nov - 12:02; edited 1 time in total
Back to top Go down
Guest
Guest



PostSubject: Shadows   Sun 4 Nov - 4:15

We have our alpha shadow caster and receiver working! cheers


Alpha Shadow Caster




Alpha Shadow Receiver


Overview
This is just an overview of what we did to get alpha shadows working. We still have a little
work to do on our shaders as well as perhaps adding in some kind of lightmapping or low rez
shadow pass for the terrain , maybe Very Happy

Client
To get the client to use our shadow receiver fragment program for modulative shadows
we had to stick the following in \Axiom\Engine\Core\SceneManager.cs ->>> DeriveShadowReceiverPass()
immediately before "if (IsShadowTechniqueAdditive)"
Code:

 if (pass.ShadowReceiverFragmentProgramName != "")
                {
                    keepTUCount = 1;
                    http://retPass.LightingEnabled = true;
                    http://retPass.Ambient = pass.Ambient;
                    http://retPass.Diffuse = pass.Diffuse;
                    http://retPass.Specular = pass.Specular;
                    http://retPass.Shininess = pass.Shininess;
                    http://retPass.SetRunNTimesPerLight(pass.RunOncePerLight,
                    //                            pass.PassIterationCount,
                    //                            pass.LightsPerIteration,
                    //                            pass.RunOnlyForOneLightType,
                    //                            pass.OnlyLightType);
                    int origPassTUCount = pass.NumTextureUnitStages;
                    for (int t = 0; t < origPassTUCount; ++t)
                    {
                        int targetIndex = t + 1;
                        TextureUnitState tex = (retPass.NumTextureUnitStages <= targetIndex ?
                                                retPass.CreateTextureUnitState() :
                                                retPass.GetTextureUnitState(targetIndex));
                        pass.GetTextureUnitState(t).CopyTo(tex);
                    }
                    keepTUCount = origPassTUCount + 1;
                   

pass.SetShadowReceiverFragmentProgram(pass.ShadowReceiverFragmentProgramName);


                    // Have to merge the shadow receiver vertex program in 
                    retPass.SetFragmentProgram(pass.ShadowReceiverFragmentProgramName);
                    GpuProgram prg = retPass.FragmentProgram;

                    // Load this program if not done already
                    if (!prg.IsLoaded)
                        prg.Load();
                    // Copy params
                    retPass.FragmentProgramParameters = pass.ShadowReceiverFragmentProgramParameters;
                    // Did we bind a shadow vertex program?
                    if (pass.HasVertexProgram && !retPass.HasVertexProgram)
                    {
                        // We didn't bind a receiver-specific program, so bind the original
                        retPass.SetVertexProgram(pass.VertexProgramName);
                        prg = retPass.VertexProgram;
                        // Load this program if required
                        if (!prg.IsLoaded)
                            prg.Load();
                        // Copy params
                        retPass.VertexProgramParameters = pass.VertexProgramParameters;
                    }
                }//end  if (pass.ShadowReceiverFragmentProgramName != "")
                else
                {                 
                    // Reset any merged fragment programs from last time
                    if (retPass == shadowTextureCustomReceiverPass)
                    {
                        // reset fp?
                        if (retPass.FragmentProgramName != shadowTextureCustomReceiverFragmentProgram)
                        {
                            retPass.SetFragmentProgram(shadowTextureCustomReceiverFragmentProgram);
                            if (retPass.HasFragmentProgram)
                                retPass.FragmentProgramParameters = shadowTextureCustomReceiverFPParams;
                        }
                    }
                    else
                        // Standard shadow receiver pass, reset to no fp
                        retPass.SetFragmentProgram("");
                }

Leaf Material
The custom shadow caster and receiver shaders are substituted for the default Multiverse shadow pass shaders in the material.

Code:
material leaf4_png
{
 
  technique
  {
      pass test1
      {   
     
//SHADOW CASTER
shadow_caster_vertex_program_ref Auro/AlphaShadowCasterVP
            {
                 param_named_auto ModelViewProjection worldviewproj_matrix
             param_named_auto AmbientLight ambient_light_colour
            }
     

 
shadow_caster_fragment_program_ref Auro/AlphaShadowCasterFP
            {
              param_named DepthOffset float 0.001
            }
 //end working shadow caster
 
//SHADOW RECEIVER

shadow_receiver_vertex_program_ref Auro/AlphaShadowReceiverVP
            {
           
                param_named_auto ModelViewProjection worldviewproj_matrix
      param_named_auto Model world_matrix
      param_named_auto TextureViewProjection texture_viewproj_matrix
                param_named_auto FadeSettings shadow_fade_params
            }
           
    //*** SOLVED ****        OLD  Issue: Our custom shadow receiver frag prog was never substituted    *** SOLVED ***       
shadow_receiver_fragment_program_ref Auro/AlphaShadowReceiverFP
            {
                    param_named ShadowColor float4 0 0 0 1
               param_named TexelOffset float2 0 0
           }   
    
//end shadow receiver

 
  texture_unit
        {
         //alpha_rejection determines what is drawn to the diffuse texture 
                alpha_rejection greater_equal 128
    
            //tex_coord_set 0
              texture leaf4.png
                   
            //colour_op modulate 
       
        //end texture_unit
        }

//end    pass test1
//end leaf technique
    }
//end leaf material
}

  }

Shadow Shaders
We are still working on our shaders but to exclude the alpha you are just using clip in the fragment programs for the caster and receiver.
Code:
 float4 diffTxt = tex2D(ourDiffTexture, In.texcoords);   
    clip(diffTxt.a - 0.3);



Some links for custom shadow shaders and materials
See the wiki topic Using_Vertex_and_Fragment_Programs_in_a_Pass
http://www.ogre3d.org/tikiwiki/Custom+Shadow+Mapping
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=69714


Very Happy
Cheers
Back to top Go down
Sponsored content




PostSubject: Re: Shadow Material SOLVED   

Back to top Go down
 
Shadow Material SOLVED
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» League: Blighted Shadow Storyline
» shadow priest without meditation
» Blighted Shadow
» "My Sacrifice: My Shadow" (Eothan)
» Material value for the pieces

Permissions in this forum:You cannot reply to topics in this forum
 :: Development :: Bugs and Issues-
Jump to: