private void TranslucentRender() { GraphicsDeviceContext device = GraphicsDeviceContext.Instance; device.SetBlendState(Addition); device.SetRasterizerState(CullingOff); device.SetDepthStencilState(ZTestOnWriteOff); device.SetVertexLayout(VertexLayout); device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); device.SetVertexShader(VertexShader); device.SetPixelShader(PixelShader); device.SetVertexBuffer(VertexPositions, 0); device.SetVertexBuffer(VertexTextureCoords, 1); PixelShader.SetTexture(Texture, 0); InstanceWVPs.Lock(Accessibility.DynamicWriteOnly); InstanceAlphas.Lock(Accessibility.DynamicWriteOnly); for (int i = 0; i < InstanceCount; i++) { var instance = Instances[i]; InstanceWVPs.Write(i, instance.Matrix * ViewingMatrix * ProjectionMatrix); float alpha = 0.15f * instance.Time; InstanceAlphas.Write(i, alpha); } InstanceAlphas.Unlock(); InstanceWVPs.Unlock(); device.SetInstanceBuffer(InstanceAlphas, 2); device.SetInstanceBuffer(InstanceWVPs, 3); device.DrawInstanced(4, InstanceCount); }
private void TranslucentRender() { GraphicsDeviceContext device = GraphicsDeviceContext.Instance; device.SetBlendState(AlphaBlend); device.SetRasterizerState(CullingOff); device.SetDepthStencilState(ZTestOnWriteOff); device.SetVertexLayout(VertexLayout); device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); device.SetVertexShader(VertexShader); device.SetPixelShader(PixelShader); device.SetVertexBuffer(VertexPositions, 0); device.SetVertexBuffer(VertexTextureCoords, 1); PixelShader.SetSamplerState(Wrap, 0); PixelShader.SetTexture(Texture, 0); InstanceAlphas.Lock(Accessibility.DynamicWriteOnly); InstanceWVPs.Lock(Accessibility.DynamicWriteOnly); int k = 0; foreach (var instance in Instances) { Vector3 position = instance.Position; float x = instance.Time; float scale = clamp(-3 * sin(x) * log(x), 0, 1) * 15 + 10; float alpha = clamp(sin(square(1.2f - x)), 0, 1) * 0.5f; var world = new Matrix4x3().Identity(); world.Translate(position * ViewingMatrix); world.Scale(scale); InstanceWVPs.Write(k, world * ProjectionMatrix); InstanceAlphas.Write(k, alpha); k++; } InstanceAlphas.Unlock(); InstanceWVPs.Unlock(); device.SetInstanceBuffer(InstanceAlphas, 2); device.SetInstanceBuffer(InstanceWVPs, 3); device.DrawInstanced(4, Instances.Count); }
void TransparentRender() { GraphicsDevice device = GraphicsDevice.Instance; device.SetBlendState(AlphaBlend); device.SetRasterizerState(CullingOff); device.SetDepthStencilState(ZTestOnWriteOff); device.SetVertexLayout(VertexLayout); device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); device.SetVertexShader(VertexShader); device.SetPixelShader(PixelShader); device.SetVertexBuffer(VertexPositions, 0); device.SetVertexBuffer(VertexTextureCoords, 1); PixelShader.SetSamplerState(Wrap, 0); PixelShader.SetTexture(Texture, 0); InstanceWVPs.Lock(Accessibility.DynamicWriteOnly); var eye = Entity.Find("camera").Get <TransformComponent>().Position; for (int i = 0; i < Instances.Length; i++) { var instance = Instances[i]; Vector3 position = instance.Position; float scale = instance.Scale; var world = new Matrix4x3().Identity(); world.Translate(position * ViewingMatrix); world.Scale(scale); InstanceWVPs.Write(i, world * ProjectionMatrix); } InstanceWVPs.Unlock(); device.SetInstanceBuffer(InstanceWVPs, 2); device.DrawInstanced(4, Instances.Length); }
private void TranslucentRender() { GraphicsDeviceContext device = GraphicsDeviceContext.Instance; device.SetBlendState(Addition); device.SetRasterizerState(CullingOff); device.SetDepthStencilState(ZTestOnWriteOff); device.SetVertexLayout(VertexLayout); device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip); device.SetVertexShader(VertexShader); device.SetPixelShader(PixelShader); device.SetVertexBuffer(VertexPositions, 0); device.SetVertexBuffer(VertexTextureCoords, 1); PixelShader.SetSamplerState(Wrap, 0); PixelShader.SetTexture(Texture, 0); InstanceColors.Lock(Accessibility.DynamicWriteOnly); InstanceWVPs.Lock(Accessibility.DynamicWriteOnly); var viewing = Entity.Find("camera").Get <CameraComponent>().ViewingMatrix; var projection = Entity.Find("projector").Get <ProjectorComponent>().ProjectionMatrix; var eye = Entity.Find("camera").Get <TransformComponent>().Position; int k = 0; Vector3 position2 = Nodes.First.Value.Position; foreach (var node in Nodes) { Vector3 position1 = node.Position; if (k > 0) { Vector3 vz = position2 - position1; vz.Normalize(); Vector3 vy = Vector3.Outer(vz, position1 - eye); vy.Normalize(); Vector3 vx = Vector3.Outer(vy, vz); Matrix4x3 matrix = new Matrix4x3().Identity(); matrix.M11 = vx.X; matrix.M12 = vx.Y; matrix.M13 = vx.Z; matrix.M21 = vy.X; matrix.M22 = vy.Y; matrix.M23 = vy.Z; matrix.M31 = vz.X; matrix.M32 = vz.Y; matrix.M33 = vz.Z; var world = new Matrix4x3().Identity(); world.Translate(position1); world.Transform(matrix); world.Scale(1, 2, (position1 - position2).Magnitude); InstanceWVPs.Write(k, world * viewing * projection); //float alpha = clamp(exp(-square(node.Time - 0.5f) / 0.075f), 0, 1) * 0.75f; float alpha = clamp(sin((1 - node.Time) * PI) - 0.05f, 0, 1) * (1 - node.Time); //float alpha = 1.0f - node.Time; InstanceColors.Write(k, new Color(alpha, alpha, alpha)); } k++; position2 = position1; } InstanceColors.Unlock(); InstanceWVPs.Unlock(); device.SetInstanceBuffer(InstanceColors, 2); device.SetInstanceBuffer(InstanceWVPs, 3); device.DrawInstanced(4, Nodes.Count - 1); }