public void Render(RenderTarget target, Camera camera, Scene scene) { Light globalLight = scene.mLights[0]; mShader.mLightSpaceMatrix = globalLight.mShadow.mViewMatrix * globalLight.mShadow.mProjectionMatrix; mShader.Apply(); // Now render our actor in batched mode foreach (var actorBatch in scene.mActorBatches) { var meshData = actorBatch.mMesh.mMeshData; mGraphicsDevice.SetVertexBuffer(actorBatch.mMesh.VertexBuffer); mGraphicsDevice.Indices = (actorBatch.mMesh.IndexBuffer); foreach (var actor in actorBatch.mActors) { mShader.ApplyModelMatrix(actor.mModelMatrix); mGraphicsDevice.DrawIndexedPrimitives(meshData.mPrimitiveType, 0, 0, meshData.mPrimitiveCount); } } }
private void Render(RenderTarget target, Camera camera, Scene scene, ShadowShader shader, bool skinnedRendering) { var light = scene.mSky.Light; shader.mLightSpaceMatrix = light.mShadow.mViewMatrix * light.mShadow.mProjectionMatrix; shader.Apply(); // Now render our actor in batched mode foreach (var actorBatch in scene.mActorBatches) { var meshData = actorBatch.mMesh.mMeshData; // When using the unskinned shader we don't want to render skinned meshes if (meshData.mIsSkinned && !skinnedRendering) { continue; } // When using the skinned shader we don't want to render unskinned meshes if (!meshData.mIsSkinned && skinnedRendering) { continue; } mGraphicsDevice.SetVertexBuffer(actorBatch.mMesh.VertexBuffer); mGraphicsDevice.Indices = actorBatch.mMesh.IndexBuffer; // When we render shadows we dont care about materials so we // can just iterate of the number of actors instead of using // another loop to consider all the materials foreach (var actor in actorBatch.mActors) { if (!actor.mCastShadow) { continue; } shader.ApplyModelMatrix(actor.ModelMatrix); if (skinnedRendering) { shader.ApplyBoneTransformations(actor.mAnimator.mTransformations); } mGraphicsDevice.DrawIndexedPrimitives(meshData.mPrimitiveType, 0, 0, meshData.mTotalNumPrimitives); } } }