public override void Render(Renderable renderable, CompositingContext context) { var entity = renderable.Entity; var transform = entity.Transform; var model = renderable.Model; var material = model.Materials[0]; var camera = context.Camera; shader.Apply(model.InputLayout); // Update general data. { vsData1.world = transform.Composite; vsData1.view = camera.View; vsData1.proj = camera.Projection; vsData1.camera = camera.Position; //vsData1.proj = world * view * proj; device.UpdateData(bufferVs1, vsData1); } // Update light data. { var lights = context.ClosestLights(transform.Origin); var light = lights[0]; var lightPosition = light.Entity.Transform.Origin; var direction = transform.Origin - lightPosition; psData1.direction = direction.Normal(); psData1.color = light.Color; psData1.lightVector = psData1.direction; psData1.position = lightPosition; device.UpdateData(bufferPs1, psData1); } device.NativeDeviceContext.VertexShader.SetConstantBuffer(0, bufferVs1); device.NativeDeviceContext.PixelShader.SetConstantBuffer(0, bufferPs1); device.NativeDeviceContext.PixelShader.SetConstantBuffer(1, bufferPs2); device.NativeDeviceContext.PixelShader.SetShaderResource(0, material.Albedo.NativeResourceView); device.NativeDeviceContext.PixelShader.SetShaderResource(1, material.Normal.NativeResourceView); device.NativeDeviceContext.PixelShader.SetShaderResource(2, material.Height?.NativeResourceView); // height device.NativeDeviceContext.PixelShader.SetShaderResource(3, material.Roughness?.NativeResourceView); device.NativeDeviceContext.PixelShader.SetShaderResource(4, material.Specular?.NativeResourceView); device.NativeDeviceContext.PixelShader.SetShaderResource(5, material.Alpha?.NativeResourceView); // alpha device.NativeDeviceContext.PixelShader.SetShaderResource(6, material.Occlusion?.NativeResourceView); // ao device.NativeDeviceContext.PixelShader.SetShaderResource(7, skybox.NativeResourceView); // ao model.Draw(shader); }
public void Draw(Scene scene, float dt) { var context = new CompositingContext(); context.Time += dt; context.DeltaTime = dt; // Cascade all transforms. var transforms = scene.GetComponents <Transform>(); foreach (var transform in transforms) { if (transform.Parent == null) { transform.ComputeTransforms(); } } // Look for camera. var cameras = scene.GetComponents <Camera>(); Requires.That(cameras.Count == 1); context.Camera = cameras[0]; context.Camera.Update(); // Update // Gather all lights. var lights = scene.GetComponents <Light>(); context.Lights = lights; // Iterate through each entity which can be rendered. var renderables = scene.GetComponents <Renderable>(); foreach (var renderable in renderables) { var renderer = renderable.Renderer; renderer.Render(renderable, context); } // Render them. }
public override void Render(Renderable renderable, CompositingContext context) { base.Render(renderable, context); var entity = renderable.Entity; var transform = entity.Transform; var model = renderable.Model; var camera = context.Camera; shader.Apply(model.InputLayout); // Update general data. { vsData1.view = camera.View; vsData1.proj = camera.Projection; vsData1.bias = Vector3.One; device.UpdateData(bufferVs1, vsData1); } device.NativeDeviceContext.VertexShader.SetConstantBuffer(0, bufferVs1); device.NativeDeviceContext.PixelShader.SetShaderResource(0, skybox.NativeResourceView); // ao model.Draw(shader); }
public virtual void Render(Renderable renderable, CompositingContext context) { }