public WireframeShapeRenderer(RenderContext rc, RgbaFloat color) { _textureData = new RawTextureDataArray <RgbaFloat>(new RgbaFloat[] { color }, 1, 1, RgbaFloat.SizeInBytes, PixelFormat.R32_G32_B32_A32_Float); _worldProvider = new DynamicDataProvider <Matrix4x4>(Matrix4x4.Identity); _inverseTransposeWorldProvider = new DependantDataProvider <Matrix4x4>(_worldProvider, Utilities.CalculateInverseTranspose); _perObjectProviders = new ConstantBufferDataProvider[] { _worldProvider, _inverseTransposeWorldProvider }; InitializeContextObjects(rc); }
public TeapotRenderer(RenderContext rc) { _worldProvider = new DynamicDataProvider <Matrix4x4>(); _inverseTransposeWorldProvider = new DependantDataProvider <Matrix4x4>(_worldProvider, CalculateInverseTranspose); _perObjectProviders = new ConstantBufferDataProvider[] { _worldProvider, _inverseTransposeWorldProvider }; _centeredBounds = BoundingSphere.CreateFromPoints(LoadTeapotMesh().Vertices); InitializeContextObjects(rc); }
public MeshRenderer(RefOrImmediate <MeshData> meshData, RefOrImmediate <TextureData> texture) { _worldProvider = new DynamicDataProvider <Matrix4x4>(); _inverseTransposeWorldProvider = new DependantDataProvider <Matrix4x4>(_worldProvider, CalculateInverseTranspose); _tintInfoProvider = new DynamicDataProvider <TintInfo>(); _materialInfo = new DynamicDataProvider <MaterialInfo>(new MaterialInfo(1.0f)); _perObjectProviders = new ConstantBufferDataProvider[] { _worldProvider, _inverseTransposeWorldProvider, _tintInfoProvider }; _transparentPerObjectProviders = new ConstantBufferDataProvider[] { _worldProvider, _inverseTransposeWorldProvider, _tintInfoProvider, _materialInfo }; Mesh = meshData; Texture = texture; }
public unsafe void ChangeRenderContext(AssetDatabase ad, RenderContext rc) { var factory = rc.ResourceFactory; _vb = factory.CreateVertexBuffer(s_vertices.Length * VertexPosition.SizeInBytes, false); _vb.SetVertexData(s_vertices, new VertexDescriptor(VertexPosition.SizeInBytes, 1, IntPtr.Zero)); _ib = factory.CreateIndexBuffer(s_indices.Length * sizeof(int), false); _ib.SetIndices(s_indices); Shader vs = factory.CreateShader(ShaderStages.Vertex, ShaderHelper.LoadShaderCode("skybox-vertex", ShaderStages.Vertex, rc.ResourceFactory)); Shader fs = factory.CreateShader(ShaderStages.Fragment, ShaderHelper.LoadShaderCode("skybox-frag", ShaderStages.Fragment, rc.ResourceFactory)); VertexInputLayout inputLayout = factory.CreateInputLayout( new VertexInputDescription( 12, new VertexInputElement("position", VertexSemanticType.Position, VertexElementFormat.Float3))); ShaderSet shaderSet = factory.CreateShaderSet(inputLayout, vs, fs); ShaderResourceBindingSlots constantSlots = factory.CreateShaderResourceBindingSlots( shaderSet, new ShaderResourceDescription("ProjectionMatrixBuffer", ShaderConstantType.Matrix4x4), new ShaderResourceDescription("ViewMatrixBuffer", ShaderConstantType.Matrix4x4), new ShaderResourceDescription("Skybox", ShaderResourceType.Texture), new ShaderResourceDescription("Skybox", ShaderResourceType.Sampler)); _material = new Material(shaderSet, constantSlots); _viewMatrixBuffer = factory.CreateConstantBuffer(ShaderConstantType.Matrix4x4); fixed(Rgba32 *frontPin = &_front.ISImage.DangerousGetPinnableReferenceToPixelBuffer()) fixed(Rgba32 * backPin = &_back.ISImage.DangerousGetPinnableReferenceToPixelBuffer()) fixed(Rgba32 * leftPin = &_left.ISImage.DangerousGetPinnableReferenceToPixelBuffer()) fixed(Rgba32 * rightPin = &_right.ISImage.DangerousGetPinnableReferenceToPixelBuffer()) fixed(Rgba32 * topPin = &_top.ISImage.DangerousGetPinnableReferenceToPixelBuffer()) fixed(Rgba32 * bottomPin = &_bottom.ISImage.DangerousGetPinnableReferenceToPixelBuffer()) { var cubemapTexture = factory.CreateCubemapTexture( (IntPtr)frontPin, (IntPtr)backPin, (IntPtr)leftPin, (IntPtr)rightPin, (IntPtr)topPin, (IntPtr)bottomPin, _front.Width, _front.Height, _front.PixelSizeInBytes, _front.Format); _cubemapBinding = factory.CreateShaderTextureBinding(cubemapTexture); } _rasterizerState = factory.CreateRasterizerState(FaceCullingMode.None, TriangleFillMode.Solid, false, false); _viewProvider = new DependantDataProvider <Matrix4x4>(SharedDataProviders.GetProvider <Matrix4x4>("ViewMatrix"), Utilities.ConvertToMatrix3x3); }
public WireframeShapeRenderer(AssetDatabase ad, RenderContext rc, RgbaFloat color) { _materialAsset = ad.LoadAsset <MaterialAsset>("MaterialAsset/ShadowCaster_MtlTemplate.json"); _textureData = new RawTextureDataArray <RgbaFloat>(new RgbaFloat[] { color }, 1, 1, RgbaFloat.SizeInBytes, PixelFormat.R32_G32_B32_A32_Float); _worldProvider = new DynamicDataProvider <Matrix4x4>(Matrix4x4.Identity); _inverseTransposeWorldProvider = new DependantDataProvider <Matrix4x4>(_worldProvider, Utilities.CalculateInverseTranspose); var materialProvider = new DynamicDataProvider <ForwardRendering.MtlMaterialProperties>(new ForwardRendering.MtlMaterialProperties(new Vector3(4, 5, 6), 7)); _perObjectProviders = new ConstantBufferDataProvider[] { _worldProvider, _inverseTransposeWorldProvider, materialProvider }; InitializeContextObjects(ad, rc); }
public MtlShadowCaster( RenderContext rc, AssetDatabase ad, VertexPositionNormalTexture[] vertices, int[] indices, MaterialAsset regularPassMaterial, TextureData overrideTexture = null) { _vertices = vertices; _indices = indices; _shadowPassMaterialAsset = ad.LoadAsset <MaterialAsset>("MaterialAsset/ShadowCaster_ShadowMap.json"); _regularPassMaterialAsset = regularPassMaterial; _overrideTextureData = overrideTexture; _inverseTransposeWorldProvider = new DependantDataProvider <Matrix4x4>(_worldProvider, Utilities.CalculateInverseTranspose); _perObjectProviders = new ConstantBufferDataProvider[] { _worldProvider, _inverseTransposeWorldProvider, _mtlPropertiesProvider }; _centeredBounds = BoundingSphere.CreateFromPoints(vertices); InitializeContextObjects(ad, rc); }
public TexturedMeshRenderer(AssetDatabase ad, RenderContext context, VertexPositionNormalTexture[] vertices, int[] indices, TextureData texture) { _worldProvider = new DynamicDataProvider <Matrix4x4>(); _inverseTransposeWorldProvider = new DependantDataProvider <Matrix4x4>(_worldProvider, CalculateInverseTranspose); _perObjectProviders = new ConstantBufferDataProvider[] { _worldProvider, _inverseTransposeWorldProvider }; _vertices = vertices; _indices = indices; _texture = texture; _centeredBounds = BoundingSphere.CreateFromPoints(vertices); if (context != _currentContext) { if (_currentContext == null) { InitializeContextObjects(context); } else { ChangeRenderContext(ad, context); } } }