public override void Render(Device device, SlimDX.Matrix viewMatrix) { var globals = new VertexShaderGlobals(); globals.WorldViewProj = viewMatrix; globals.World = SlimDX.Matrix.Identity; this._VertexShaderConstantBuffer1.Update(globals); device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList); device.VertexShader.Set(this._ShaderLoader.VertexShader); device.VertexShader.SetConstantBuffer(this._VertexShaderConstantBuffer1.Buffer, 1); var globalConsts = new PixelShaderGlobalConstants(); globalConsts.Globals = new ShaderNatives.float4[15]; globalConsts.Globals[0] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[1] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[2] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[3] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[4] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[5] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[6] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[7] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[8] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[9] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[10] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[11] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[12] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[13] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[14] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); this._PixelShaderConstantBuffer0.Update(globalConsts); var instanceConsts = new PixelShaderInstanceConstants(); instanceConsts.InstanceConstants = new ShaderNatives.float4[3]; instanceConsts.InstanceConstants[0] = new ShaderNatives.float4(0.0f, 1.0f, 1.0f, 1.0f); instanceConsts.InstanceConstants[1] = new ShaderNatives.float4(1.0f, 1.0f, 0.0f, 0.8f); this._PixelShaderConstantBuffer1.Update(instanceConsts); var materialConsts = new PixelShaderMaterialConstants(); materialConsts.MaterialConstants = new ShaderNatives.float4[3]; for (int i = 0; i < 3; i++) { materialConsts.MaterialConstants[i] = new ShaderNatives.float4(1.0f, 1.0f, 0.0f, 1.0f); } this._PixelShaderConstantBuffer2.Update(materialConsts); var bs = new PixelShaderBooleans(); bs.Bools = new ShaderNatives.bool4[4]; bs.Bools[3].X = true; bs.Bools[3].Y = true; bs.Bools[3].Z = false; this._PixelShaderConstantBuffer4.Update(bs); device.PixelShader.Set(this._ShaderLoader.PixelShader); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer0.Buffer, 0); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer1.Buffer, 1); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer2.Buffer, 2); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer4.Buffer, 4); this._MaterialLoader.SetShaderResource(device); device.InputAssembler.SetInputLayout(this._ShaderLoader.InputLayout); device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this._VertexData0Buffer, 48, 0)); device.InputAssembler.SetIndexBuffer(this._IndexBuffer, DXGI.Format.R16_UInt, 0); var bsd = new BlendStateDescription() { IsAlphaToCoverageEnabled = true, SourceAlphaBlend = BlendOption.One, DestinationAlphaBlend = BlendOption.Zero, AlphaBlendOperation = BlendOperation.Add, SourceBlend = BlendOption.SourceAlpha, DestinationBlend = BlendOption.Zero, BlendOperation = BlendOperation.Add, }; bsd.SetBlendEnable(0, true); bsd.SetWriteMask(0, ColorWriteMaskFlags.All); device.OutputMerger.BlendState = BlendState.FromDescription(device, bsd); device.DrawIndexed(this.Block.Faces.Count, 0, 0); }
public override void Render(Device device, SlimDX.Matrix viewMatrix) { foreach (var batch in this.Block.SkinBatches) { var globals = new VertexShaderGlobals(); globals.MatrixPalette = new ShaderNatives.float3x4[18]; int paletteIndex = 0; foreach (var boneIndex in batch.BoneIndices) { if (boneIndex != -1) { globals.MatrixPalette[paletteIndex] = SlimDX.Matrix.Identity; //.Data[TestIndex % 18]; } paletteIndex++; } globals.World = SlimDX.Matrix.Identity; globals.WorldViewProj = viewMatrix; this._VertexShaderConstantBuffer1.Update(globals); device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList); device.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(this._VertexData1Buffer, 20, 0)); device.VertexShader.Set(this._ShaderLoader.VertexShader); //device.VertexShader.SetConstantBuffer(this.ConstantBuffer, 0); //device.VertexShader.SetConstantBuffer(this.ConstantBuffer1.Buffer, 0); device.VertexShader.SetConstantBuffer(this._VertexShaderConstantBuffer1.Buffer, 1); //device.VertexShader.SetConstantBuffer(this.ConstantBuffer, 3); //device.VertexShader.SetConstantBuffer(this.ConstantBuffer, 4); var globalConsts = new PixelShaderGlobalConstants(); globalConsts.Globals = new ShaderNatives.float4[15]; globalConsts.LightPositions = new ShaderNatives.float4[65]; for (int i = 0; i < 65; i++) { globalConsts.LightPositions[i] = new ShaderNatives.float4(0.0f, 0.0f, 100.0f, 0.0f); } globalConsts.LightColors = new ShaderNatives.float4[65]; for (int i = 0; i < 65; i++) { globalConsts.LightColors[i] = new ShaderNatives.float4(1.0f, 0.0f, 0.0f, 1.0f); } //globalConsts.Globals[TestIndex % 15] = new ShaderNatives.float4(0.0f, 0.0f, 100.0f, 0.0f); //globalConsts.Globals[0] = new ShaderNatives.float4(11.0f, 1.0f, 1.0f, 1.0f); //globalConsts.Globals[1] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); //globalConsts.Globals[2] = new ShaderNatives.float4(0.0f, 1.0f, 0.0f, 1.0f); globalConsts.Globals[3] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[4] = new ShaderNatives.float4(0.0f, 25.0f, -25.0f, 0.0f); //globalConsts.Globals[1] = new ShaderNatives.float4(0.0f, 2.0f, 0.0f, 1.0f); //globalConsts.Globals[5] = new ShaderNatives.float4(0.0f, 0.0f, 25.0f, 0.0f); //globalConsts.Globals[7] = new ShaderNatives.float4(1.0f, 0.0f, 0.0f, 1.0f); //globalConsts.Globals[8] = new ShaderNatives.float4(1.0f, 0.0f, 0.0f, 1.0f); globalConsts.Globals[9] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[10] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); //globalConsts.Globals[11] = new ShaderNatives.float4(-1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[12] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); //globalConsts.Globals[14] = new ShaderNatives.float4(0.0f, 0.0f, 1.0f, 1.0f); //globalConsts.Globals[3] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); this._PixelShaderConstantBuffer0.Update(globalConsts); var instanceConsts = new PixelShaderInstanceConstants(); instanceConsts.InstanceConstants = new ShaderNatives.float4[6]; for (int i = 0; i < 6; i++) { instanceConsts.InstanceConstants[i] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); } instanceConsts.InstanceConstants[1] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); this._PixelShaderConstantBuffer1.Update(instanceConsts); var materialConsts = new PixelShaderMaterialConstants(); materialConsts.MaterialConstants = new ShaderNatives.float4[1]; for (int i = 0; i < 1; i++) { materialConsts.MaterialConstants[i] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); } this._PixelShaderConstantBuffer2.Update(materialConsts); var bs = new PixelShaderBooleans(); bs.Bools = new ShaderNatives.bool4[4]; bs.Bools[3].X = true; bs.Bools[3].Y = false; bs.Bools[3].Z = false; bs.AlphaRef = 0.0f; this._PixelShaderConstantBuffer4.Update(bs); device.PixelShader.Set(this._ShaderLoader.PixelShader); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer0.Buffer, 0); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer1.Buffer, 1); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer2.Buffer, 2); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer4.Buffer, 4); this._MaterialLoader.SetShaderResource(device); device.InputAssembler.SetInputLayout(this._ShaderLoader.InputLayout); if (this.Block.HasBigVertices == false) { device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this._VertexData0Buffer, 20, 0)); } else { device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this._VertexData0Buffer, 28, 0)); } device.InputAssembler.SetIndexBuffer(this._IndexBuffer, DXGI.Format.R16_UInt, 0); device.DrawIndexed(batch.FaceCount, batch.FaceIndex, 0); } }
public override void Render(Device device, SlimDX.Matrix viewMatrix) { var globals = new VertexShaderGlobals(); globals.World = SlimDX.Matrix.Identity; globals.WorldViewProj = viewMatrix; this._VertexShaderConstantBuffer1.Update(globals); device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList); device.VertexShader.Set(this._ShaderLoader.VertexShader); device.VertexShader.SetConstantBuffer(this._VertexShaderConstantBuffer1.Buffer, 1); var globalConsts = new PixelShaderGlobalConstants(); globalConsts.Globals = new ShaderNatives.float4[15]; globalConsts.LightPositions = new ShaderNatives.float4[65]; for (int i = 0; i < 65; i++) { globalConsts.LightPositions[i] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); } globalConsts.LightColors = new ShaderNatives.float4[65]; for (int i = 0; i < 65; i++) { globalConsts.LightColors[i] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); } //globalConsts.Globals[TestIndex % 15] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); //TestIndex++; globalConsts.Globals[0] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[1] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[2] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[3] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[4] = new ShaderNatives.float4(0.0f, 25.0f, -25.0f, 0.0f); globalConsts.Globals[5] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[6] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[7] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[8] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[9] = new ShaderNatives.float4(1.0f, 1.0f, 1.0f, 1.0f); globalConsts.Globals[10] = new ShaderNatives.float4(1, 1.0f, 1.0f, 1.0f); globalConsts.Globals[11] = new ShaderNatives.float4(1.0f, 1, 1.0f, 1.0f); globalConsts.Globals[12] = new ShaderNatives.float4(1.0f, 1.0f, 1, 1.0f); globalConsts.Globals[13] = new ShaderNatives.float4(111, 1.0f, 1.0f, 1.0f); globalConsts.Globals[14] = new ShaderNatives.float4(1.0f, 111, 1.0f, 1.0f); this._PixelShaderConstantBuffer0.Update(globalConsts); var instanceConsts = new PixelShaderInstanceConstants(); instanceConsts.InstanceConstants = new ShaderNatives.float4[8]; instanceConsts.InstanceConstants[0] = new ShaderNatives.float4(0.0f, 1.0f, 1.0f, 1.0f); instanceConsts.InstanceConstants[1] = new ShaderNatives.float4(1.0f, 1.0f, 0.0f, 1.0f); instanceConsts.InstanceConstants[2] = new ShaderNatives.float4(0.0f, 1.0f, 1.0f, 1.0f); instanceConsts.InstanceConstants[3] = new ShaderNatives.float4(1.0f, 0.0f, 1.0f, 1.0f); instanceConsts.InstanceConstants[4] = new ShaderNatives.float4(1.0f, 1.0f, 0.0f, 1.0f); instanceConsts.InstanceConstants[5] = new ShaderNatives.float4(0.0f, 0.0f, 1.0f, 1.0f); instanceConsts.InstanceConstants[6] = new ShaderNatives.float4(0.0f, 1.0f, 0.0f, 0.0f); instanceConsts.InstanceConstants[7] = new ShaderNatives.float4(1.0f, 0.0f, 0.0f, 0.0f); this._PixelShaderConstantBuffer1.Update(instanceConsts); var materialConsts = new PixelShaderMaterialConstants(); materialConsts.MaterialConstants = new ShaderNatives.float4[3]; for (int i = 0; i < 3; i++) { materialConsts.MaterialConstants[i] = new ShaderNatives.float4(1.0f, 1.0f, 0.0f, 1.0f); } this._PixelShaderConstantBuffer2.Update(materialConsts); var bs = new PixelShaderBooleans(); bs.Bools = new ShaderNatives.bool4[4]; bs.Bools[3].X = false; bs.Bools[3].Y = false; bs.Bools[3].Z = false; bs.AlphaRef = 0.0f; this._PixelShaderConstantBuffer4.Update(bs); device.PixelShader.Set(this._ShaderLoader.PixelShader); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer0.Buffer, 0); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer1.Buffer, 1); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer2.Buffer, 2); device.PixelShader.SetConstantBuffer(this._PixelShaderConstantBuffer4.Buffer, 4); this._MaterialLoader.SetShaderResource(device); device.InputAssembler.SetInputLayout(this._ShaderLoader.InputLayout); device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this._VertexData0Buffer, 24, 0)); device.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(this._VertexData1Buffer, 28, 0)); device.InputAssembler.SetIndexBuffer(this._IndexBuffer, DXGI.Format.R16_UInt, 0); device.DrawIndexed(this.Block.Faces.Count, 0, 0); }