예제 #1
0
        public void SetShaders(byte[] vertexShaderBytecode, byte[] pixelShaderBytecode)
        {
            // Dispose existing shaders
            DisposeShaders();


            // Create VertexShader
            _vertexShader = new VertexShader(parentDXDevice.Device, vertexShaderBytecode);


            // Create InputLayout
            var vertexLayoutDesc = InputElementFactory.GetInputElementsArray(InputLayoutType.Position | InputLayoutType.Normal | InputLayoutType.TextureCoordinate);

            _inputLayout = new InputLayout(parentDXDevice.Device, vertexShaderBytecode, vertexLayoutDesc);


            // Create Pixel shader
            _pixelShader = new PixelShader(parentDXDevice.Device, pixelShaderBytecode);


            // If we are using debug device we set DebugName - so we can see the correct name of shaders in Graphic debugging
            if (parentDXDevice.IsDebugDevice)
            {
                _vertexShader.DebugName = EffectName + "_VertexShader";
                _pixelShader.DebugName  = EffectName + "_PixelShader";
                _inputLayout.DebugName  = EffectName + "_InputLayout";
            }
        }
예제 #2
0
        protected virtual void Content()
        {
            var id = $"{_pageHeader.Replace(" ", string.Empty)}";
            var inputElementFactory = new InputElementFactory();
            var inputsHtml          = AddGenericTypeOption();

            inputsHtml += _taskParameters.GetType()
                          .GetProperties()
                          .Where(ShouldDisplayProperty)
                          .Select(x => inputElementFactory.GetInputElementWriter(x))
                          .Aggregate(new StringBuilder(), (sb, x) => sb.AppendLine(x.WriteElementAndLabel(_taskParameters)), sb => sb.ToString());

            var route = $"{TasksPage.UrlRoute}/{_taskParameters.Queue}/{_pageHeader.Replace(" ", string.Empty)}";

            Panel(id, _displayName, _displayDescription, _displayErrorDetails, inputsHtml, CreateButtons(route, "Enqueue", "enqueueing", id));

            WriteLiteral("\r\n<script src=\"");
            Write(Url.To($"/jsm"));
            WriteLiteral("\"></script>\r\n");
        }
        private void EnsureShaders(DXDevice dxDevice, bool usePerPointColor)
        {
            if (usePerPointColor)
            {
                if (_vertexShaderPerPointColorSharedResource == null)
                {
                    // InputLayoutType.Color3 will be supported in the next version of DXEngine. Then it will be possible to use:
                    var vertexLayoutDesc = InputElementFactory.GetInputElementsArray(InputLayoutType.Position | InputLayoutType.Normal | InputLayoutType.Color3);

                    _vertexShaderPerPointColorSharedResource = dxDevice.EffectsManager.GetVertexShader("ShadedPointCloudPerPointColor.vs",
                                                                                                       vertexLayoutDesc,
                                                                                                       out _inputLayoutPerPointColorSharedResource,
                                                                                                       throwExceptionIfNotFound: true);
                }
            }
            else
            {
                if (_vertexShaderSharedResource == null)
                {
                    var vertexLayoutDesc = InputElementFactory.GetInputElementsArray(InputLayoutType.Position | InputLayoutType.Normal);

                    _vertexShaderSharedResource = dxDevice.EffectsManager.GetVertexShader("ShadedPointCloud.vs",
                                                                                          vertexLayoutDesc,
                                                                                          out _inputLayoutSharedResource,
                                                                                          throwExceptionIfNotFound: true);
                }
            }

            if (_geometryShaderSharedResource == null)
            {
                _geometryShaderSharedResource = dxDevice.EffectsManager.GetGeometryShader("ShadedPointCloud.gs", throwExceptionIfNotFound: true);
            }

            if (_pixelShaderSharedResource == null)
            {
                _pixelShaderSharedResource = dxDevice.EffectsManager.GetPixelShader("ShadedPointCloud.ps", throwExceptionIfNotFound: true);
            }
        }
        /// <summary>
        /// Initializes this effect.
        /// </summary>
        /// <param name="dxDevice">parent DXDevice</param>
        protected override void OnInitializeResources(DXDevice dxDevice)
        {
            if (IsInitialized)
            {
                return; // Already initialized
            }
            parentDXDevice = dxDevice;



            // The recommended way to create shaders is to use GetShaders method on EffectsManager (or GetVertexShader, GetPixelShader or other methods - see below).
            // In order for EffectsManager to get the shader resources, we need to RegisterShaderResource before the shaders can be created.
            // In this case the code in CustomShaderMaterialSample.xaml.cs does that. The following code is used:
            //var directoryShaderBytecodeProvider = new DirectoryShaderBytecodeProvider(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Shaders"));
            //dxDevice.EffectsManager.RegisterShaderResource(directoryShaderBytecodeProvider);

            var vertexLayoutDesc = InputElementFactory.GetInputElementsArray(InputLayoutType.Position | InputLayoutType.Normal);

            dxDevice.EffectsManager.GetShaders(
                "MeshNormalShader.vs", "MeshNormalShader.ps", vertexLayoutDesc,
                out _vertexShaderSharedResource, out _pixelShaderSharedResource, out _inputLayoutSharedResource,
                throwExceptionIfShadersNotFound: true);


            // You could also use GetVertexShader and GetPixelShader methods:
            //_vertexShaderSharedResource = dxDevice.EffectsManager.GetVertexShader("MeshNormalShader.vs", vertexLayoutDesc, out _inputLayoutSharedResource, throwExceptionIfNotFound: true);
            //_pixelShaderSharedResource = dxDevice.EffectsManager.GetPixelShader("MeshNormalShader.ps", throwExceptionIfNotFound: true);


            // You could also use simple shader constructors to create the shaders:
            //// Create VertexShader
            //byte[] vertexShaderBytecode = System.IO.File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Shaders\\MeshNormalShader.vs"));
            //_vertexShader = new VertexShader(parentDXDevice.Device, vertexShaderBytecode);

            //// Create InputLayout
            //_inputLayout = new InputLayout(parentDXDevice.Device, vertexShaderBytecode, vertexLayoutDesc);

            //// Create Pixel shader
            //byte[] pixelShaderBytecode = System.IO.File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Shaders\\MeshNormalShader.ps"));
            //_pixelShader = new PixelShader(parentDXDevice.Device, pixelShaderBytecode);

            //// If we are using debug device we set DebugName - so we can see the correct name of shaders in Graphic debugging
            //if (parentDXDevice.IsDebugDevice)
            //{
            //    _vertexShader.DebugName = EffectName + "_VertexShader";
            //    _inputLayout.DebugName = EffectName + "_InputLayout";
            //    _pixelShader.DebugName = EffectName + "_PixelShader";
            //}


            _perFrameCameraConstantsBufferData = new PerFrameCameraConstantBuffer();
            _perFrameCameraConstantsBuffer     = parentDXDevice.CreateConstantBuffer(PerFrameCameraConstantBuffer.SizeInBytes, EffectName + "_perFrameCameraConstantsBuffer");

            _perFrameLightsConstantsBufferData = new PerFrameLightsConstantBuffer();
            _perFrameLightsConstantsBuffer     = parentDXDevice.CreateConstantBuffer(PerFrameLightsConstantBuffer.SizeInBytes, EffectName + "_perFrameLightsConstantsBuffer");

            _perObjectConstantsBufferData = new PerObjectConstantBuffer();
            _perObjectConstantsBuffer     = parentDXDevice.CreateConstantBuffer(PerObjectConstantBuffer.SizeInBytes, EffectName + "_perObjectConstantsBuffer");

            base.OnInitializeResources(dxDevice);
        }