protected override void ReceiveMessage(object message, object argument) { base.ReceiveMessage(message, argument); switch (message as string) { case RenderMessage: { Matrix4x4 world = new Matrix4x4(this.Owner.Get <TransformComponent>().Matrix); Matrix4x4 viewing = new Matrix4x4(Entity.Find("camera").Get <CameraComponent>().ViewingMatrix); Matrix4x4 projection = Entity.Find("projector").Get <ProjectorComponent>().ProjectionMatrix; GraphicsDeviceContext device = GraphicsDeviceContext.Instance; device.SetBlendState(NoBlend); device.SetRasterizerState(CullingOn); device.SetDepthStencilState(ZTestOn); device.SetVertexLayout(VertexLayout); device.SetPrimitiveTopology(GraphicsModel.Topology); device.SetVertexShader(VertexShader); device.SetPixelShader(PixelShader); device.SetVertexBuffer(GraphicsModel.VertexPositions, 0); device.SetIndexBuffer(GraphicsModel.VertexIndices); PixelShader.SetSamplerState(Wrap, 0); VertexShader.SetConstantBuffer(world * viewing * projection, 0); device.DrawIndexed(GraphicsModel.VertexIndices.Count); } break; default: break; } }
private void Render() { GraphicsDeviceContext device = GraphicsDeviceContext.Instance; device.SetBlendState(NoBlend); device.SetRasterizerState(CullingOff); device.SetDepthStencilState(ZTestOn); device.SetVertexLayout(VertexLayout); device.SetPrimitiveTopology(PrimitiveTopology.TriangleList); device.SetVertexShader(VertexShader); device.SetPixelShader(PixelShader); PixelShader.SetSamplerState(Wrap, 0); PixelShader.SetTexture(GraphicsModel.Texture, 0); { VertexShader.SetConstantBuffer(WVPMatrix, 0); PixelShader.SetConstantBuffer(WorldMatrix, 0); PixelShader.SetConstantBuffer(new Vector4(Entity.Find("light").Get <TransformComponent>().Forward, 0), 1); device.SetVertexBuffer(GraphicsModel.VertexPositions, 0); device.SetVertexBuffer(GraphicsModel.VertexNormals, 1); device.SetVertexBuffer(GraphicsModel.VertexTextureCoords, 2); device.SetIndexBuffer(GraphicsModel.VertexIndices); device.DrawIndexed(GraphicsModel.VertexIndices.Count); } }
void Render() { //viewing.Invert(); //viewing.Position = new Vector3(0, 0, 0); //viewing.Invert(); GraphicsDeviceContext device = GraphicsDeviceContext.Instance; device.SetBlendState(NoBlend); device.SetRasterizerState(CullingOff); device.SetDepthStencilState(ZTestOff); device.SetVertexLayout(VertexLayout); device.SetPrimitiveTopology(PrimitiveTopology.TriangleList); device.SetVertexShader(VertexShader); device.SetPixelShader(PixelShader); device.SetVertexBuffer(VertexBuffer, 0); device.SetIndexBuffer(IndexBuffer); PixelShader.SetSamplerState(Wrap, 0); PixelShader.SetTextureArray(Texture, 0); VertexShader.SetConstantBuffer(WVPMatrix, 0); device.DrawIndexed(IndexBuffer.Count); }
private void TranslucentRender() { GraphicsDeviceContext device = GraphicsDeviceContext.Instance; device.SetBlendState(Addition); device.SetRasterizerState(CullingOff); device.SetDepthStencilState(ZTestOnWriteOff); device.SetVertexBuffer(VertexPositionsBuffer, 0); device.SetVertexBuffer(VertexTexcoordsBuffer, 1); device.SetIndexBuffer(IndexBuffer); device.SetVertexLayout(VertexLayout); device.SetPrimitiveTopology(PrimitiveTopology.TriangleList); device.SetVertexShader(VertexShader); device.SetPixelShader(PixelShader); PixelShader.SetSamplerState(Wrap, 0); PixelShader.SetTexture(Texture, 0); if (this.Power > 0.9f) { var physics = this.Owner.Get <PhysicsComponent>(); var transform = this.Owner.Get <TransformComponent>(); var angular = new Vector4(physics.AngularVelocity, 0) * transform.Matrix.Inverse; { var offsetPosition = this.OffsetPosition; Matrix4x3 adjustment = new Matrix4x3(); adjustment.Identity(); adjustment.Translate(offsetPosition); adjustment.RotateX(clamp((-angular.X * 2 + angular.Z * 0.5f) * 5, -0.2f, 0.2f)); adjustment.Scale(normal(1.7f, 0.1f), normal(1.7f, 0.1f), normal(3.8f, 0.1f) * (this.Power - 0.9f) / 0.1f); VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0); device.DrawIndexed(IndexBuffer.Count); } if (this.OffsetPosition.X != 0) { var offsetPosition = this.OffsetPosition; offsetPosition.X *= -1; Matrix4x3 adjustment = new Matrix4x3(); adjustment.Identity(); adjustment.Translate(offsetPosition + new Vector3(0, 0, 0.5f)); adjustment.RotateX(clamp((-angular.X * 2 - angular.Z * 0.5f) * 5, -0.2f, 0.2f)); adjustment.Scale(normal(1.7f, 0.1f), normal(1.7f, 0.1f), normal(3.8f, 0.1f) * (this.Power - 0.9f) / 0.1f); VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0); device.DrawIndexed(IndexBuffer.Count); } } }
void Render() { GraphicsDeviceContext device = GraphicsDeviceContext.Instance; device.SetBlendState(this.Opacity == 0 ? NoBlend : AlphaBlend); device.SetRasterizerState(CullingOn); device.SetDepthStencilState(this.Opacity == 0 ? ZTestOn : ZTestOnWriteOff); device.SetVertexLayout(VertexLayout); device.SetPrimitiveTopology(PrimitiveTopology.TriangleList); device.SetVertexShader(VertexShader); device.SetPixelShader(PixelShader); PixelShader.SetSamplerState(Wrap, 0); PixelShader.SetTexture(Texture, 0); PixelShader.SetTexture(NormalMapTexture, 1); PixelShader.SetConstantBuffer(new Vector4(Entity.Find("camera").Get <TransformComponent>().Position, 1), 2); PixelShader.SetConstantBuffer(new Vector4(Entity.Find("light").Get <TransformComponent>().Forward, 0), 3); PixelShader.SetConstantBuffer(new Color(1, 1, 1, 1.0f - this.Opacity), 4); { VertexShader.SetConstantBuffer(WVPMatrix, 0); PixelShader.SetConstantBuffer(WorldMatrix, 0); PixelShader.SetConstantBuffer(WorldMatrix.Inverse, 1); device.SetVertexBuffer(this.Body.VertexPositions, 0); device.SetVertexBuffer(this.Body.VertexNormals, 1); device.SetVertexBuffer(this.Body.VertexTextureCoords, 2); device.SetVertexBuffer(this.Body.VertexTangents, 3); device.SetVertexBuffer(this.Body.VertexBinormals, 4); device.SetIndexBuffer(this.Body.VertexIndices); device.DrawIndexed(this.Body.VertexIndices.Count); } var angular = new Vector4(Physics.AngularVelocity, 0) * Transform.Matrix.Inverse; if (this.LeftCanard != null) { Matrix4x4 move = new Matrix4x4().Identity().Translate(this.CanardPos); Matrix4x4 rot = new Matrix4x4().Identity().RotateX(clamp(angular.X * 10, -0.3f, 0.3f)); Matrix4x4 adjustment = move.Inverse * rot * move; VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0); PixelShader.SetConstantBuffer(adjustment * WorldMatrix, 0); PixelShader.SetConstantBuffer((adjustment * WorldMatrix).Inverse, 1); device.SetVertexBuffer(this.LeftCanard.VertexPositions, 0); device.SetVertexBuffer(this.LeftCanard.VertexNormals, 1); device.SetVertexBuffer(this.LeftCanard.VertexTextureCoords, 2); device.SetVertexBuffer(this.LeftCanard.VertexTangents, 3); device.SetVertexBuffer(this.LeftCanard.VertexBinormals, 4); device.SetIndexBuffer(this.LeftCanard.VertexIndices); device.DrawIndexed(this.LeftCanard.VertexIndices.Count); } if (this.RightCanard != null) { Matrix4x4 move = new Matrix4x4().Identity().Translate(reverseX(this.CanardPos)); Matrix4x4 rot = new Matrix4x4().Identity().RotateX(clamp(angular.X * 10, -0.3f, 0.3f)); Matrix4x4 adjustment = move.Inverse * rot * move; VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0); PixelShader.SetConstantBuffer(adjustment * WorldMatrix, 0); PixelShader.SetConstantBuffer((adjustment * WorldMatrix).Inverse, 1); device.SetVertexBuffer(this.RightCanard.VertexPositions, 0); device.SetVertexBuffer(this.RightCanard.VertexNormals, 1); device.SetVertexBuffer(this.RightCanard.VertexTextureCoords, 2); device.SetVertexBuffer(this.RightCanard.VertexTangents, 3); device.SetVertexBuffer(this.RightCanard.VertexBinormals, 4); device.SetIndexBuffer(this.RightCanard.VertexIndices); device.DrawIndexed(this.RightCanard.VertexIndices.Count); } if (this.LeftElevator != null) { Matrix4x4 move = new Matrix4x4().Identity().Translate(this.ElevatorPos); Matrix4x4 rot = new Matrix4x4().Identity().RotateX(clamp((-angular.X * 2 + angular.Z * 0.5f) * 10, -0.3f, 0.3f)); Matrix4x4 adjustment = move.Inverse * rot * move; VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0); PixelShader.SetConstantBuffer(adjustment * WorldMatrix, 0); PixelShader.SetConstantBuffer((adjustment * WorldMatrix).Inverse, 1); device.SetVertexBuffer(this.LeftElevator.VertexPositions, 0); device.SetVertexBuffer(this.LeftElevator.VertexNormals, 1); device.SetVertexBuffer(this.LeftElevator.VertexTextureCoords, 2); device.SetVertexBuffer(this.LeftElevator.VertexTangents, 3); device.SetVertexBuffer(this.LeftElevator.VertexBinormals, 4); device.SetIndexBuffer(this.LeftElevator.VertexIndices); device.DrawIndexed(this.LeftElevator.VertexIndices.Count); } if (this.RightElevator != null) { Matrix4x4 move = new Matrix4x4().Identity().Translate(reverseX(this.ElevatorPos)); Matrix4x4 rot = new Matrix4x4().Identity().RotateX(clamp((-angular.X * 2 - angular.Z * 0.5f) * 10, -0.3f, 0.3f)); Matrix4x4 adjustment = move.Inverse * rot * move; VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0); PixelShader.SetConstantBuffer(adjustment * WorldMatrix, 0); PixelShader.SetConstantBuffer((adjustment * WorldMatrix).Inverse, 1); device.SetVertexBuffer(this.RightElevator.VertexPositions, 0); device.SetVertexBuffer(this.RightElevator.VertexNormals, 1); device.SetVertexBuffer(this.RightElevator.VertexTextureCoords, 2); device.SetVertexBuffer(this.RightElevator.VertexTangents, 3); device.SetVertexBuffer(this.RightElevator.VertexBinormals, 4); device.SetIndexBuffer(this.RightElevator.VertexIndices); device.DrawIndexed(this.RightElevator.VertexIndices.Count); } #region ミサイル更新 for (int i = 0; i < 8; i++) { if (this.Weapons[i].MissileEntity != null) { Entity e = this.Weapons[i].MissileEntity; e.Get <TransformComponent>().Matrix = Transform.Matrix; e.Get <TransformComponent>().Matrix.Translate(this.Weapons[i].WeaponPos); e.Get <PhysicsComponent>().Velocity = Physics.Velocity; e.Get <MissileComponent>().TargetEntity = (this.Owner.Has <AIComponent>()) ? this.Owner.Get <AIComponent>().TargetEntity : null; } } #endregion }