codo
16-04-2009 15:30:37
I need to implement texture based shadows in ma app. The problem is: I can't make it work in Mogre I can easily run Ogre sample code ('shadow example').
I tried to convert Mogre sample app called 'SkeletalAnimation' to display shadows (for some reason I can't find shadow sample app for Mogre). There are no shadows at all, no matter what I do.
Here is the code:
What am I doing wrong? I use default media directory from Mogre 1.4.8 installation. Log is showing no severe errors, only stuff like:
I changed the shader to draw shaded pixels in red. Result is attached along with this post (everything is in shadow). Any ideas?
I tried to convert Mogre sample app called 'SkeletalAnimation' to display shadows (for some reason I can't find shadow sample app for Mogre). There are no shadows at all, no matter what I do.
Here is the code:
using System;
using System.Collections.Generic;
using Mogre;
namespace Mogre.Demo.SkeletalAnimation
{
class Skeletal : Demo.ExampleApplication.Example
{
// protected SceneManager sceneMgr;
const int NUM_ROBOTS = 10;
const int ROW_COUNT = 10;
AnimationState[] _animState = new AnimationState[NUM_ROBOTS];
float[] _animationSpeed = new float[NUM_ROBOTS];
public override void CreateFrameListener()
{
base.CreateFrameListener();
root.FrameStarted += new FrameListener.FrameStartedHandler(Skeletal_FrameStarted);
}
bool Skeletal_FrameStarted(FrameEvent evt)
{
for (int i = 0; i < NUM_ROBOTS; ++i)
{
_animState[i].AddTime(evt.timeSinceLastFrame * _animationSpeed[i]);
}
return true;
}
public override void CreateScene()
{
// Setup animation default
Animation.DefaultInterpolationMode = Animation.InterpolationMode.IM_LINEAR;
Animation.DefaultRotationInterpolationMode = Animation.RotationInterpolationMode.RIM_LINEAR;
// Set ambient light
Entity ent = null;
int row = 0;
int column = 0;
Random rnd = new Random();
for (int i = 0; i < NUM_ROBOTS; ++i, ++column)
{
if (column > ROW_COUNT)
{
++row;
column = 0;
}
ent = sceneMgr.CreateEntity("robot" + i, "robot.mesh");
ent.CastShadows = true;
ent.SetMaterialName("Ogre/DepthShadowmap/Receiver/RockWall");
sceneMgr.RootSceneNode.CreateChildSceneNode(
new Vector3(-(row * 100), 0, (column * 50))).AttachObject(ent);
_animState[i] = ent.GetAnimationState("Walk");
_animState[i].Enabled = true;
_animationSpeed[i] = (float)(rnd.NextDouble() + 0.5);
}
// Give it a little ambience with lights
Light l = null;
l = sceneMgr.CreateLight("BlueLight");
l.Type = Mogre.Light.LightTypes.LT_DIRECTIONAL;
l.Direction = new Vector3(-0.2f,-1,1);
l.SetPosition(50, 200, -100);
l.SetDiffuseColour(0.5f, 0.5f, 1.0f);
l.CastShadows = true;
l = sceneMgr.CreateLight("GreenLight");
l.SetPosition(0, 0, -100);
l.SetDiffuseColour(0.5f, 1.0f, 0.5f);
l.CastShadows = true;
// Position the camera
camera.SetPosition(100, 50, 100);
camera.LookAt(-50, 50, 0);
// Report whether hardware skinning is enabled or not
Technique te = ent.GetSubEntity(0).GetMaterial().GetBestTechnique();
Pass p = te.GetPass(0);
if (p.HasVertexProgram && p.GetVertexProgram().IsSkeletalAnimationIncluded)
{
mDebugText = "Hardware skinning is enabled";
}
else
{
mDebugText = "Software skinning is enabled";
}
sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f);
sceneMgr.SetShadowCameraSetup(new ShadowCameraSetupPtr(new DefaultShadowCameraSetup()));
sceneMgr.SetShadowTexturePixelFormat(PixelFormat.PF_FLOAT32_R);
sceneMgr.SetShadowTextureCasterMaterial("Ogre/DepthShadowmap/Caster/Float");
sceneMgr.SetShadowTextureReceiverMaterial("Ogre/DepthShadowmap/Receiver/Float");
sceneMgr.ShadowTextureSelfShadow = (true);
sceneMgr.SetShadowTextureSettings(1024, 2);
sceneMgr.SetShadowTexturePixelFormat(PixelFormat.PF_FLOAT32_R);
sceneMgr.ShadowColour = (new ColourValue(0.5f, 0.5f, 0.5f));
sceneMgr.ShadowTechnique = (ShadowTechnique.SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
Mogre.Plane mPlane = new Mogre.Plane(Vector3.UNIT_Y, new Vector3(0,0,0));
MeshManager.Singleton.CreatePlane("Myplane"+this.GetHashCode(),
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, mPlane, 10000,10000,50,50,true,1,5,5,Vector3.UNIT_Z);
Entity pPlaneEnt = sceneMgr.CreateEntity( "plane"+this.GetHashCode(), "Myplane"+this.GetHashCode() );
pPlaneEnt.SetMaterialName("Ogre/DepthShadowmap/Receiver/RockWall");
pPlaneEnt.CastShadows = false;
sceneMgr.RootSceneNode.AttachObject(pPlaneEnt);
}
}
}
What am I doing wrong? I use default media directory from Mogre 1.4.8 installation. Log is showing no severe errors, only stuff like:
16:33:23: WARNING: Texture instance 'Ogre/ShadowTexture0' was defined as manually loaded, but no manual loader was provided. This Resource will be lost if it has to be reloaded.
16:33:23: WARNING: Texture instance 'Ogre/ShadowTexture1' was defined as manually loaded, but no manual loader was provided. This Resource will be lost if it has to be reloaded.
16:33:23: Creating viewport on target 'rtt/2274528', rendering from camera 'Ogre/ShadowTexture0Cam', relative dimensions L: 0.00 T: 0.00 W: 1.00 H: 1.00 ZOrder: 0
16:33:23: Creating viewport on target 'rtt/72627104', rendering from camera 'Ogre/ShadowTexture1Cam', relative dimensions L: 0.00 T: 0.00 W: 1.00 H: 1.00 ZOrder: 0
I changed the shader to draw shaded pixels in red. Result is attached along with this post (everything is in shadow). Any ideas?