public override void Set(Effect effect, RenderContext context, Matrix transform) { EffectRegistry.Params[effect][EffectRegistry.WORLD_PARAM_NAME].SetValue(transform); EffectRegistry.Params[effect][EffectRegistry.WORLDVIEWPROJ_PARAM_NAME].SetValue(transform * context.VisibilityFrustum.Matrix); EffectRegistry.Params[effect][EffectRegistry.WORLDINVTRANSPOSE_PARAM_NAME].SetValue(Matrix.Transpose(Matrix.Invert(transform))); EffectRegistry.Params[effect][EffectRegistry.EYEPOSITION_PARAM_NAME].SetValue(context.EyePosition); }
public SceneGraphRoot(SceneResources sceneResources) { mRenderContext = new RenderContext(sceneResources); mDynamicRoot = new SceneNode(); mStaticTreeRoot = null; mSkyboxRoot = new SceneNode(); mTraversalData = new TraversalContext(); }
public override void Set(Effect effect, RenderContext context, Matrix transform) { Actor hdrLightActor = GameResources.ActorManager.GetActorById(context.SceneResources.HDRLightActorId); HDRLightComponent hdr = hdrLightActor.GetComponent<HDRLightComponent>(ActorComponent.ComponentType.Light); EffectRegistry.Params[effect][EffectRegistry.IRRADIANCEMAP_PARAM_NAME].SetValue(hdr.IrradianceMap); EffectRegistry.Params[effect][EffectRegistry.ALPHA_TEST_DIRECTION_PARAM_NAME].SetValue(mIsOpaqueMode ? 1.0f : -1.0f); EffectRegistry.Params[effect][EffectRegistry.SECONDS_TIMER_VALUE_PARAM_NAME].SetValue(mTimer()); }
public override void Draw(RenderContext context, EffectApplication material, Matrix transform) { material.SetEffectParams(context, transform); for (int p = 0; p < material.Effect.CurrentTechnique.Passes.Count; ++p) { material.Effect.CurrentTechnique.Passes[p].Apply(); if (mParticleData.FirstActiveParticleIndex < mParticleData.FirstFreeParticleIndex) { // If the active particles are all in one consecutive range, we can draw them all in a single call. if (SharedResources.GraphicsDeviceReady) { SharedResources.Game.GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, mParticleData.FirstActiveParticleIndex * 4, (mParticleData.FirstFreeParticleIndex - mParticleData.FirstActiveParticleIndex) * 4, mParticleData.FirstActiveParticleIndex * 6, (mParticleData.FirstFreeParticleIndex - mParticleData.FirstActiveParticleIndex) * 2); } } else { // If the active particle range wraps past the end of the queue back to the start, we must split them over two draw calls. if (SharedResources.GraphicsDeviceReady) { SharedResources.Game.GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, mParticleData.FirstActiveParticleIndex * 4, (mParticleData.MaxParticles - mParticleData.FirstActiveParticleIndex) * 4, mParticleData.FirstActiveParticleIndex * 6, (mParticleData.MaxParticles - mParticleData.FirstActiveParticleIndex) * 2); } if (mParticleData.FirstFreeParticleIndex > 0 && SharedResources.GraphicsDeviceReady) { SharedResources.Game.GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, mParticleData.FirstFreeParticleIndex * 4, 0, mParticleData.FirstFreeParticleIndex * 2); } } } mIncrementDrawCounter(); }
public override void Set(Effect effect, RenderContext context, Matrix transform) { EffectRegistry.Params[effect][EffectRegistry.WORLDVIEWPROJ_PARAM_NAME].SetValue(transform * context.VisibilityFrustum.Matrix); }
public override void Set(Effect effect, RenderContext context, Matrix transform) { EffectRegistry.Params[effect][EffectRegistry.WORLDVIEWPROJ_PARAM_NAME].SetValue( Matrix.CreateTranslation(context.EyePosition) * context.VisibilityFrustum.Matrix); }
public override void Set(Effect effect, RenderContext context, Matrix transform) { if (AnimationComponent != null) { EffectRegistry.Params[effect][EffectRegistry.POSEDBONES_PARAM_NAME].SetValue(AnimationComponent.GetCurrentPose()); EffectRegistry.Params[effect][EffectRegistry.WEIGHTS_PER_VERT_PARAM_NAME].SetValue(AnimationComponent.Animations.WeightsPerVert); } else { EffectRegistry.Params[effect][EffectRegistry.POSEDBONES_PARAM_NAME].SetValue(AnimationComponent.BindPose); EffectRegistry.Params[effect][EffectRegistry.WEIGHTS_PER_VERT_PARAM_NAME].SetValue(4); } }
public override void Set(Effect effect, RenderContext context, Matrix transform) { EffectRegistry.Params[effect][EffectRegistry.SHADOWTRANSFORM_PARAM_NAME].SetValue(transform * context.SceneResources.ShadowTransform); EffectRegistry.Params[effect][EffectRegistry.SHADOWMAP_PARAM_NAME].SetValue(context.SceneResources.ShadowMap); }
public abstract void Set(Effect effect, RenderContext context, Matrix transform);
public override void Set(Effect effect, RenderContext context, Matrix transform) { Actor hdrLightActor = GameResources.ActorManager.GetActorById(context.SceneResources.HDRLightActorId); HDRLightComponent hdr = hdrLightActor.GetComponent<HDRLightComponent>(ActorComponent.ComponentType.Light); EffectRegistry.Params[effect][EffectRegistry.IRRADIANCEMAP_PARAM_NAME].SetValue(hdr.IrradianceMap); EffectRegistry.Params[effect][EffectRegistry.SPECPREFILTER_PARAM_NAME].SetValue(hdr.SpecPrefilter); EffectRegistry.Params[effect][EffectRegistry.NUMSPECLEVELS_PARAM_NAME].SetValue(hdr.NumSpecLevels); EffectRegistry.Params[effect][EffectRegistry.SPECEXPFACTOR_PARAM_NAME].SetValue(hdr.SpecExponentFactor); EffectRegistry.Params[effect][EffectRegistry.AMBIENTLIGHT_PARAM_NAME].SetValue(hdr.AmbientLight); }
public override void Set(Effect effect, RenderContext context, Matrix transform) { EffectRegistry.Params[effect][EffectRegistry.FRINGEMAP_PARAM_NAME].SetValue(context.SceneResources.FringeMap); }
public override void Set(Effect effect, RenderContext context, Matrix transform) { Actor fogActor = GameResources.ActorManager.GetActorById(context.SceneResources.FogActorId); FogComponent fog = fogActor.GetComponent<FogComponent>(ActorComponent.ComponentType.Fog); EffectRegistry.Params[effect][EffectRegistry.FOGCOLOR_PARAM_NAME].SetValue(fog.Color.ToVector3()); EffectRegistry.Params[effect][EffectRegistry.FOGSTART_PARAM_NAME].SetValue(fog.Start); EffectRegistry.Params[effect][EffectRegistry.FOGEND_PARAM_NAME].SetValue(fog.End); }
public override void Set(Effect effect, RenderContext context, Matrix transform) { EffectRegistry.Params[effect][EffectRegistry.ENVIROMAP_PARAM_NAME].SetValue(context.SceneResources.EnvironmentMap); }
public void ExecuteRenderQueue(RenderContext renderContext) { if (mRenderEntries.Count == 0) return; mRenderEntries.Sort(mEntryComparer); // Prime the previousEntry variable: RenderEntry previousEntry = mRenderEntries[0]; GraphicsDevice gd = SharedResources.Game.GraphicsDevice; gd.BlendState = previousEntry.Material.BlendState; gd.DepthStencilState = previousEntry.Material.DepthStencilState; gd.RasterizerState = previousEntry.Material.RasterizerState; gd.SetVertexBuffer(previousEntry.DrawNode.VertexBuffer); gd.Indices = previousEntry.DrawNode.IndexBuffer; for (int i = 0; i < mRenderEntries.Count; ++i) { if (previousEntry.Material.BlendState != mRenderEntries[i].Material.BlendState) gd.BlendState = mRenderEntries[i].Material.BlendState; if (previousEntry.Material.DepthStencilState != mRenderEntries[i].Material.DepthStencilState) gd.DepthStencilState = mRenderEntries[i].Material.DepthStencilState; if (previousEntry.Material.RasterizerState != mRenderEntries[i].Material.RasterizerState) gd.RasterizerState = mRenderEntries[i].Material.RasterizerState; if (previousEntry.DrawNode.VertexBuffer != mRenderEntries[i].DrawNode.VertexBuffer) gd.SetVertexBuffer(mRenderEntries[i].DrawNode.VertexBuffer); if (previousEntry.DrawNode.IndexBuffer != mRenderEntries[i].DrawNode.IndexBuffer) gd.Indices = mRenderEntries[i].DrawNode.IndexBuffer; mRenderEntries[i].DrawNode.Draw(renderContext, mRenderEntries[i].Material, mRenderEntries[i].Transform); previousEntry = mRenderEntries[i]; } mRenderEntries.Clear(); SharedResources.GraphicsDeviceReady = !SharedResources.GraphicsDeviceResetting; }
public void SetEffectParams(RenderContext context, Matrix transform) { foreach (KeyValuePair<ParamSetter.Category, ParamSetter> kvp in ParamSetters) { kvp.Value.Set(Effect, context, transform); } }
public override void Set(Effect effect, RenderContext context, Matrix transform) { const int NUM_LIGHTS = 1; DirLight[] dirLight = new DirLight[NUM_LIGHTS]; dirLight[0] = new DirLight(); Actor caster = GameResources.ActorManager.GetActorById(context.SceneResources.ShadowCasterActorId); TransformComponent casterTransform = caster.GetComponent<TransformComponent>(ActorComponent.ComponentType.Transform); dirLight[0].Direction = Vector3.Transform(Vector3.Forward, casterTransform.Orientation); dirLight[0].Ambient = Vector4.Zero; dirLight[0].Diffuse = new Vector4(0.65f, 0.65f, 0.6f, 1.0f); dirLight[0].Specular = new Vector4(0.05f, 0.05f, 0.05f, 1.0f); dirLight[0].Energy = 1.0f; EffectRegistry.Params[effect][EffectRegistry.NUMLIGHTS_PARAM_NAME].SetValue(NUM_LIGHTS); for (int i = 0; i < NUM_LIGHTS; i++) { EffectRegistry.Params[effect][EffectRegistry.DIRLIGHT_STRUCT_NAME + EffectRegistry.AMBIENT_PARAM_NAME + i.ToString()].SetValue(dirLight[i].Ambient); EffectRegistry.Params[effect][EffectRegistry.DIRLIGHT_STRUCT_NAME + EffectRegistry.DIFFUSE_PARAM_NAME + i.ToString()].SetValue(dirLight[i].Diffuse); EffectRegistry.Params[effect][EffectRegistry.DIRLIGHT_STRUCT_NAME + EffectRegistry.SPECULAR_PARAM_NAME + i.ToString()].SetValue(dirLight[i].Specular); EffectRegistry.Params[effect][EffectRegistry.DIRLIGHT_STRUCT_NAME + EffectRegistry.DIRECTION_PARAM_NAME + i.ToString()].SetValue(dirLight[i].Direction); EffectRegistry.Params[effect][EffectRegistry.DIRLIGHT_STRUCT_NAME + EffectRegistry.ENERGY_PARAM_NAME + i.ToString()].SetValue(dirLight[i].Energy); } }
public virtual void Draw(RenderContext context, EffectApplication material, Matrix transform) { material.SetEffectParams(context, transform); for (int p = 0; p < material.Effect.CurrentTechnique.Passes.Count; ++p) { material.Effect.CurrentTechnique.Passes[p].Apply(); if (SharedResources.GraphicsDeviceReady) SharedResources.Game.GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, mVertexOffset, 0, mNumVertices, mStartIndex, mPrimitiveCount); } }
public override void Set(Effect effect, RenderContext context, Matrix transform) { EffectRegistry.Params[effect][EffectRegistry.VIEWPROJ_PARAM_NAME].SetValue(context.VisibilityFrustum.Matrix); // We need to compute the M11 member of the projection matrix, which is -n / r, where n, r is the z, x coords of // the right edge of the frustum's near plane in camera space. float cosTheta = Vector3.Dot(context.VisibilityFrustum.Near.Normal, context.VisibilityFrustum.Right.Normal); float projXScale = 1.0f / (float)(Math.Tan(MathHelper.PiOver2 - Math.Acos(cosTheta))); EffectRegistry.Params[effect][EffectRegistry.PROJ_XSCALE_PARAM_NAME].SetValue(projXScale); Vector2 vpScale = new Vector2(0.5f / SharedResources.Game.GraphicsDevice.Viewport.AspectRatio, -0.5f); EffectRegistry.Params[effect][EffectRegistry.VIEWPORT_SCALE_PARAM_NAME].SetValue(vpScale); EffectRegistry.Params[effect][EffectRegistry.SECONDS_TIMER_VALUE_PARAM_NAME].SetValue(mTimer()); }