예제 #1
0
        public override void DrawScene()
        {
            base.DrawScene();
            ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.LightSteelBlue);
            ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

            ImmediateContext.InputAssembler.InputLayout       = _inputLayout;
            ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            for (int i = 0; i < _tech.Description.PassCount; i++)
            {
                ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_landVB, VertexPC.Stride, 0));
                ImmediateContext.InputAssembler.SetIndexBuffer(_landIB, Format.R32_UInt, 0);

                _fxWVP.SetMatrix(_gridWorld * _view * _proj);
                var pass = _tech.GetPassByIndex(i);
                pass.Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(_gridIndexCount, 0, 0);

                ImmediateContext.Rasterizer.State = _wireframeRS;
                ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_wavesVB, VertexPC.Stride, 0));
                ImmediateContext.InputAssembler.SetIndexBuffer(_wavesIB, Format.R32_UInt, 0);

                _fxWVP.SetMatrix(_wavesWorld * _view * _proj);
                pass.Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(3 * _waves.TriangleCount, 0, 0);

                ImmediateContext.Rasterizer.State = null;
            }
            SwapChain.Present(0, PresentFlags.None);
        }
예제 #2
0
파일: Program.cs 프로젝트: mrommel/dx11
        public override void DrawScene()
        {
            base.DrawScene();

            ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.LightSteelBlue);
            ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

            ImmediateContext.InputAssembler.InputLayout       = _inputLayout;
            ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            var viewProj = _view * _proj;
            var array    = Util.GetArray(_dirLight);

            _fxDirLight.SetRawValue(new DataStream(array, false, false), array.Length);
            array = Util.GetArray(_pointLight);
            _fxPointLight.SetRawValue(new DataStream(array, false, false), array.Length);
            array = Util.GetArray(_spotLight);
            _fxSpotLight.SetRawValue(new DataStream(array, false, false), array.Length);

            _fxEyePosW.Set(_eyePosW);

            for (int i = 0; i < _tech.Description.PassCount; i++)
            {
                ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_landVB, VertexPN.Stride, 0));
                ImmediateContext.InputAssembler.SetIndexBuffer(_landIB, Format.R32_UInt, 0);

                _fxWVP.SetMatrix(_landWorld * viewProj);
                var invTranspose = Matrix.Invert(Matrix.Transpose(_landWorld));
                _fxWIT.SetMatrix(invTranspose);
                _fxWorld.SetMatrix(_landWorld);
                array = Util.GetArray(_landMaterial);
                _fxMaterial.SetRawValue(new DataStream(array, false, false), array.Length);

                var pass = _tech.GetPassByIndex(i);
                pass.Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(_landIndexCount, 0, 0);

                ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_waveVB, VertexPN.Stride, 0));
                ImmediateContext.InputAssembler.SetIndexBuffer(_waveIB, Format.R32_UInt, 0);

                _fxWVP.SetMatrix(_wavesWorld * viewProj);
                invTranspose = Matrix.Invert(Matrix.Transpose(_wavesWorld));
                _fxWIT.SetMatrix(invTranspose);
                _fxWorld.SetMatrix(_wavesWorld);
                array = Util.GetArray(_wavesMaterial);
                _fxMaterial.SetRawValue(new DataStream(array, false, false), array.Length);
                pass.Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(3 * _waves.TriangleCount, 0, 0);
            }

            SwapChain.Present(0, PresentFlags.None);
        }
예제 #3
0
파일: BasicEffect.cs 프로젝트: kkdevs/sb3u
 public void SetWorldViewProjTex(Matrix matrix)
 {
     if (_worldViewProjTex != null)
     {
         _worldViewProjTex.SetMatrix(matrix);
     }
 }
예제 #4
0
        private void SetRenderParameters()
        {
            _shaderEffectPass = _shaderEffect.GetTechniqueByIndex((int)RenderParameters.ShaderMode).GetPassByIndex(0);

            // Update Camera
            _world.SetMatrix(RenderParameters.Camera.World());
            _worldViewProjection.SetMatrix(RenderParameters.Camera.WorldViewProjection());

            // Set Texture
            _textureMap.SetResource(_textureView);
            _enableTexture.Set(RenderParameters.Textured);

            // Set Tesselation
            _tessFactor.Set(RenderParameters.TessellationFactor);

            // Set Lighting
            _phongParameters.Set(RenderParameters.Lighting.PhongParameters.AsVector());
            _lightColor.Set(RenderParameters.Lighting.Lights[0].Color);
            _lightDirection.Set(RenderParameters.Lighting.Lights[0].Direction);
            _light2Color.Set(RenderParameters.Lighting.Lights[1].Color);
            _light2Direction.Set(RenderParameters.Lighting.Lights[1].Direction);
            _ambientLightColor.Set(RenderParameters.Lighting.AmbientLightColor);
            _cameraPosition.Set(RenderParameters.Camera.Eye);

            // Set Options
            _flatShading.Set(RenderParameters.FlatShading);
            _enableNormals.Set(RenderParameters.DisplayNormals);

            // Valences and Prefixes for ACC
            _valencePrefixResource.SetResource(_valencePrefixView);
        }
        /// <summary>
        /// Render all lines added this frame
        /// </summary>
        public void Render(LineManager3DLines nLines, ICamera cam)
        {
            nLines.UpdateVertexBuffer(device);
            // Need to build vertex buffer?


            // Render lines if we got any lines to render
            if (nLines.NumOfPrimitives > 0)
            {
                try
                {
                    device.ImmediateContext.InputAssembler.InputLayout       = layout;
                    device.ImmediateContext.InputAssembler.PrimitiveTopology =
                        PrimitiveTopology.LineList;
                    device.ImmediateContext.InputAssembler.SetVertexBuffers(0,
                                                                            new VertexBufferBinding
                                                                                (nLines.VertexBuffer,
                                                                                vertexStride, 0));

                    worldViewProjParam.SetMatrix(cam.ViewProjection);

                    pass.Apply(device.ImmediateContext);
                    device.ImmediateContext.Draw(nLines.NumOfPrimitives * 2, 0);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
예제 #6
0
        public void Render()
        {
            if (_particleSystem == null)
            {
                return;
            }
            if (_playing == false)
            {
                return;
            }
            if (_particleSystem.MaxParticles > _bufferSize)
            {
                _bufferSize = _particleSystem.MaxParticles + 500;
                DebugLog.Log("Buffer too small. Increasing size...", "Particle Emitter");
                CreateBuffer();
            }

            _textureVar.SetResource(_textureResourceView);
            _viewInvVar.SetMatrix(_context.Camera.ViewInverseMatrix);
            _viewProjVar.SetMatrix(_context.Camera.ViewProjectionMatrix);

            _context.Device.InputAssembler.InputLayout       = _inputLayout;
            _context.Device.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
            _context.Device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vertexBuffer, _vertexStride, 0));

            for (int i = 0; i < _technique.Description.PassCount; ++i)
            {
                _technique.GetPassByIndex(i).Apply();
                _context.Device.OutputMerger.BlendState = _blendStates[(int)_particleSystem.BlendMode];
                _context.Device.Draw(_particleCount, 0);
            }
        }
예제 #7
0
        public override void DrawScene()
        {
            ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.SteelBlue);
            ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1, 0);

            ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            ImmediateContext.InputAssembler.InputLayout       = inputLayout;

            var array = Util.GetArray(dirLights);

            fxDirLights.SetRawValue(new DataStream(array, false, false), array.Length);

            fxEyePosW.Set(eyePosW);

            for (int i = 0; i < effectTechnique.Description.PassCount; i++)
            {
                for (int j = 0; j < shapes.Count; j++)
                {
                    ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(shapes[j].VertexBuffer, Basic32.Stride, 0));
                    ImmediateContext.InputAssembler.SetIndexBuffer(shapes[j].IndexBuffer, Format.R32_UInt, 0);

                    fxW.SetMatrix(shapes[j].ShapeWorld);
                    fxWIT.SetMatrix(MathF.InverseTranspose(shapes[j].ShapeWorld));
                    array = Util.GetArray(((ShapeWithTextureBase)shapes[j]).ShapeMaterial);
                    fxMaterial.SetRawValue(new DataStream(array, false, false), array.Length);
                    fxDiffuseMap.SetResource(((ShapeWithTextureBase)shapes[j]).ShapeTexture);
                    fxWVP.SetMatrix(shapes[j].ShapeWorld * view * projection);
                    fxTT.SetMatrix(Matrix.Identity);

                    effectTechnique.GetPassByIndex(i).Apply(ImmediateContext);
                    ImmediateContext.DrawIndexed(shapes[j].IndexCount, 0, 0);
                }
            }
            SwapChain.Present(0, PresentFlags.None);
        }
예제 #8
0
파일: BasicEffect.cs 프로젝트: kkdevs/sb3u
 public void SetShadowTransform(Matrix matrix)
 {
     if (_shadowTransform != null)
     {
         _shadowTransform.SetMatrix(matrix);
     }
 }
예제 #9
0
 public void Prepare(Matrix view, Matrix projection)
 {
     // Update WorldViewProjection variable
     _dxDevice.InputAssembler.SetInputLayout(_inputLayout);
     _viewVariable.SetMatrix(view);
     _projectionVariable.SetMatrix(projection);
 }
예제 #10
0
        private void RenderNode(SceneGraph Node, Camera Camera, SlimDX.Matrix ProjMatrix, int indexOffset, int vertexOffset, out int indicesConsumed, out int verticesConsumed)
        {
            var ic = indexOffset;
            var vc = vertexOffset;

            if (Node.Renderable != null)
            {
                WorldViewProj = Node.WorldTransform * Camera.GetViewMatrix() * ProjMatrix;
                CPO_WorldViewProj.SetMatrix(WorldViewProj);

                int nIndices = Node.Renderable.GetIndexList(EffectName()).Length;
                int nVerts   = Node.Renderable.GetVertexList(EffectName()).Length;

                // TODO KAM: This is horribly inefficient, change this!
                ImmediateContext.DrawIndexed(nIndices, indexOffset, vertexOffset);

                ic += nIndices;
                vc += nVerts;
            }

            foreach (var Child in Node.Children)
            {
                int cic, cvc;
                RenderNode(Child.Value, Camera, ProjMatrix, indexOffset + ic, vertexOffset + vc, out cic, out cvc);
                ic += cic;
                vc += cvc;
            }

            indicesConsumed  = ic;
            verticesConsumed = vc;
        }
        public void Render(DxCamera camera)
        {
            if (_vertexBuffer == null || _vertexCount == 0)
            {
                return;
            }

            _worldVar.SetMatrix(Matrix.Scaling(Scale, -Scale, Scale));
            _eyePosWVar.Set(camera.Eye);
            _viewProjVar.SetMatrix(camera.View * camera.Projection);
            _fillColorVar.Set(_fillColor);

            _resVar.Set(new Vector2(_xRes, _yRes));
            _focalLengthDepthVar.Set(_focalLengthDepth);
            _focalLengthImageVar.Set(_focalLengthImage);
            _depthToRgbVar.SetMatrix(_depthToRgb);

            _depthMapVar.SetResource(_depthMapBufferRV);
            _imageMapVar.SetResource(_imageTextureRV);

            _dxDevice.InputAssembler.SetInputLayout(_inputLayout);
            _dxDevice.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.PointList);
            _dxDevice.InputAssembler.SetVertexBuffers(0,
                                                      new VertexBufferBinding(_vertexBuffer, PointVertex.SizeOf, 0));

            for (int p = 0; p < _renderTech.Description.PassCount; p++)
            {
                _renderTech.GetPassByIndex(p).Apply();
                _dxDevice.Draw(_vertexCount, 0);
            }
        }
예제 #12
0
        public override void DrawScene()
        {
            base.DrawScene();
            ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.LightSteelBlue);
            ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

            ImmediateContext.InputAssembler.InputLayout       = _inputLayout;
            ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            ImmediateContext.Rasterizer.State = _wireframeRS;

            ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vb, VertexPC.Stride, 0));
            ImmediateContext.InputAssembler.SetIndexBuffer(_ib, Format.R32_UInt, 0);

            var viewProj = _view * _proj;

            var techDesc = _tech.Description;

            for (int p = 0; p < techDesc.PassCount; p++)
            {
                _fxWVP.SetMatrix(_gridWorld * viewProj);
                _tech.GetPassByIndex(p).Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(_gridIndexCount, _gridIndexOffset, _gridVertexOffset);

                _fxWVP.SetMatrix(_boxWorld * viewProj);
                _tech.GetPassByIndex(p).Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(_boxIndexCount, _boxIndexOffset, _boxVertexOffset);

                _fxWVP.SetMatrix(_centerSphere * viewProj);
                _tech.GetPassByIndex(p).Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(_sphereIndexCount, _sphereIndexOffset, _sphereVertexOffset);

                foreach (var matrix in _cylWorld)
                {
                    _fxWVP.SetMatrix(matrix * viewProj);
                    _tech.GetPassByIndex(p).Apply(ImmediateContext);
                    ImmediateContext.DrawIndexed(_cylinderIndexCount, _cylinderIndexOffset, _cylinderVertexOffset);
                }
                foreach (var matrix in _sphereWorld)
                {
                    _fxWVP.SetMatrix(matrix * viewProj);
                    _tech.GetPassByIndex(p).Apply(ImmediateContext);
                    ImmediateContext.DrawIndexed(_sphereIndexCount, _sphereIndexOffset, _sphereVertexOffset);
                }
            }
            SwapChain.Present(0, PresentFlags.None);
        }
예제 #13
0
 public static void ApplyUnitTransform(EffectMatrixVariable variable, LayerSettings settings, ObjectLayerSettings obj)
 {
     if (obj.Geometry != null)
     {
         if (obj.Geometry.HasBoundingBox)
         {
             Vector3 scale = obj.Geometry.BoundingBox.Maximum - obj.Geometry.BoundingBox.Minimum;
             scale.X = scale.X != 0.0f ? 1.0f / scale.X : 1.0f;
             scale.Y = scale.Y != 0.0f ? 1.0f / scale.Y : 1.0f;
             scale.Z = scale.Z != 0.0f ? 1.0f / scale.Z : 1.0f;
             Matrix m = Matrix.Scaling(scale);
             variable.SetMatrix(m);
             return;
         }
     }
     variable.SetMatrix(Matrix.Identity);
 }
예제 #14
0
        void SetSceneConstants()
        {
            FreeLook freelook    = Demo.FreeLook;
            Vector3  up          = MathHelper.Convert(freelook.Up);
            Vector3  eye         = MathHelper.Convert(freelook.Eye);
            Vector4  eyePosition = new Vector4(eye, 1);

            sceneConstants.View = Matrix.LookAtLH(eye, MathHelper.Convert(freelook.Target), up);
            Matrix.PerspectiveFovLH(FieldOfView, AspectRatio, _nearPlane, FarPlane, out sceneConstants.Projection);
            Matrix.Invert(ref sceneConstants.View, out sceneConstants.ViewInverse);

            Texture2DDescription depthBuffer = lightDepthTexture.Description;
            Vector3 lightPosition            = sunLightDirection * -60;
            Matrix  lightView = Matrix.LookAtLH(lightPosition, Vector3.Zero, up);
            //Matrix lightProjection = Matrix.OrthoLH(depthBuffer.Width / 8.0f, depthBuffer.Height / 8.0f, _nearPlane, FarPlane);
            Matrix lightProjection = Matrix.PerspectiveFovLH(FieldOfView, (float)depthBuffer.Width / (float)depthBuffer.Height, _nearPlane, FarPlane);

            sceneConstants.LightViewProjection = lightView * lightProjection;

            DataStream data;

            _immediateContext.MapSubresource(sceneConstantsBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out data);
            Marshal.StructureToPtr(sceneConstants, data.DataPointer, false);
            _immediateContext.UnmapSubresource(sceneConstantsBuffer, 0);
            data.Dispose();

            sunLightDirectionVar.Set(new Vector4(sunLightDirection, 1));

            Matrix overlayMatrix = Matrix.Scaling(info.Width / _width, info.Height / _height, 1.0f);

            overlayMatrix *= Matrix.Translation(-(_width - info.Width) / _width, (_height - info.Height) / _height, 0.0f);
            overlayViewProjectionVar.SetMatrix(overlayMatrix);


            lightProjectionVar.SetMatrixTranspose(ref sceneConstants.Projection);
            lightViewVar.SetMatrixTranspose(ref sceneConstants.View);
            lightViewInverseVar.SetMatrix(ref sceneConstants.ViewInverse);
            lightViewportWidthVar.Set(_width);
            lightViewportHeightVar.Set(_height);
            lightEyePositionVar.Set(ref eyePosition);

            float   tanHalfFovY    = (float)Math.Tan(FieldOfView * 0.5f);
            float   tanHalfFovX    = tanHalfFovY * AspectRatio;
            float   projectionA    = FarPlane / (FarPlane - _nearPlane);
            float   projectionB    = -projectionA * _nearPlane;
            Vector4 viewParameters = new Vector4(tanHalfFovX, tanHalfFovY, projectionA, projectionB);

            lightViewParametersVar.Set(ref viewParameters);


            viewportWidthVar.Set(_width);
            viewportHeightVar.Set(_height);
            viewParametersVar.Set(ref viewParameters);
        }
예제 #15
0
        protected override void OnRender(RenderContext renderContext)
        {
            this.bHasInstances.Set(this.hasInstances);
            // --- set constant paramerers
            var worldMatrix = this.modelMatrix * renderContext.worldMatrix;

            this.EffectTransforms.mWorld.SetMatrix(ref worldMatrix);

            // --- check shadowmaps
            this.hasShadowMap = this.renderHost.IsShadowMapEnabled;
            this.effectMaterial.bHasShadowMapVariable.Set(this.hasShadowMap);
            this.effectMaterial.AttachMaterial(geometryInternal as MeshGeometry3D);
            // --- set context
            renderContext.DeviceContext.InputAssembler.InputLayout       = this.vertexLayout;
            renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            renderContext.DeviceContext.InputAssembler.SetIndexBuffer(this.IndexBuffer.Buffer, Format.R32_UInt, 0);

            // --- set rasterstate
            renderContext.DeviceContext.Rasterizer.State = this.RasterState;
            renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0));
            hasBonesVar.Set(hasBoneParameter && hasBoneMatrices);

            if (hasBoneMatrices)
            {
                boneMatricesVar.SetMatrix(mBones.Bones);
            }
            if (this.hasBoneParameter)
            {
                if (isBoneParamChanged && this.VertexBoneIds.Count >= geometryInternal.Positions.Count)
                {
                    vertexBoneParamsBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.VertexBoneIds);
                    this.isBoneParamChanged = false;
                }
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(this.vertexBoneParamsBuffer.Buffer, this.vertexBoneParamsBuffer.StructureSize, 0));
            }
            if (this.hasInstances)
            {
                // --- update instance buffer
                if (this.isInstanceChanged)
                {
                    InstanceBuffer.UploadDataToBuffer(renderContext.DeviceContext, this.instanceInternal);
                    this.isInstanceChanged = false;
                }
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(this.InstanceBuffer.Buffer, this.InstanceBuffer.StructureSize, 0));
                OnInstancedDrawCall(renderContext);
            }
            else
            {
                // --- bind buffer
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.VertexBuffer.Buffer, this.VertexBuffer.StructureSize, 0));
                OnDrawCall(renderContext);
            }
        }
예제 #16
0
 public static void ApplySDFTransform(EffectMatrixVariable variable, LayerSettings settings, ObjectLayerSettings obj)
 {
     if (obj.Geometry != null)
     {
         if (obj.Geometry.HasBoundingBox)
         {
             Vector3 min   = obj.Geometry.BoundingBox.Minimum;
             Vector3 scale = obj.Geometry.BoundingBox.Maximum - obj.Geometry.BoundingBox.Minimum;
             scale.X = scale.X != 0.0f ? scale.X : 1.0f;
             scale.Y = scale.Y != 0.0f ? scale.Y : 1.0f;
             scale.Z = scale.Z != 0.0f ? scale.Z : 1.0f;
             Matrix m = Matrix.Scaling(scale);
             m.M41 = min.X;
             m.M42 = min.Y;
             m.M43 = min.Z;
             variable.SetMatrix(Matrix.Invert(m));
             return;
         }
     }
     variable.SetMatrix(Matrix.Identity);
 }
예제 #17
0
        public void Render()
        {
            _context.Device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vertexBuffer, _vertexStride, 0));
            _context.Device.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
            _context.Device.InputAssembler.InputLayout       = _inputLayout;

            _wvpVar.SetMatrix(_context.Camera.ViewProjectionMatrix);

            for (int i = 0; i < _technique.Description.PassCount; i++)
            {
                _technique.GetPassByIndex(i).Apply();
                _context.Device.Draw(_vertices.Count, 0);
            }
        }
예제 #18
0
        void UpdateTransform()
        {
            Matrix world_view_matrix = world_matrix * Transform_View;

            world_view_projection_matrix = world_view_matrix * Transform_Projection;

            World_variable.SetMatrix(world_matrix);
            WorldView_variable.SetMatrix(world_view_matrix);
            WorldViewProjection_variable.SetMatrix(world_view_projection_matrix);
            /* for normal in view */
            View_variable.SetMatrix(Transform_View);
            /* for HUD */
            Projection_variable.SetMatrix(Transform_Projection);
        }
예제 #19
0
            /// <summary>
            ///
            /// </summary>
            /// <returns></returns>
            internal void Commit()
            {
                switch (GetUtilValueType())
                {
                case UtilValueType.FLOAT:
                    sv.Set(m_float[0]);
                    break;

                case UtilValueType.FLOAT2:
                    sv.Set(m_float);
                    break;

                case UtilValueType.FLOAT3:
                    sv.Set(m_float);
                    break;

                case UtilValueType.FLOAT4:
                    vv.Set(m_float);
                    break;

                case UtilValueType.FLOAT4x4:
                    mv.SetMatrix(m_float);
                    break;

                case UtilValueType.ARY_FLOAT:
                    sv.Set(m_float);
                    break;

                case UtilValueType.BOOL:
                    sv.Set(m_bool[0]);
                    break;

                case UtilValueType.ARY_BOOL:
                    sv.Set(m_bool);
                    break;

                case UtilValueType.INT:
                    sv.Set(m_int);
                    break;

                case UtilValueType.ARY_INT:
                    sv.Set(m_int);
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }
            }
예제 #20
0
 public override void UpdateShaderVariables(FluxMesh mesh)
 {
     _wvpMatrixVar.SetMatrix(Matrix.Identity * Context.Camera.ViewProjectionMatrix);
     _worldMatrixVar.SetMatrix(Matrix.Identity);
     _useDiffuseTextureVar.Set(mesh.DiffuseTexture != null);
     if (mesh.DiffuseTexture != null)
     {
         _diffuseTextureVar.SetResource(mesh.DiffuseTexture);
     }
     _useNormalTextureVar.Set(mesh.NormalTexture != null);
     if (mesh.NormalTexture != null)
     {
         _normalTextureVar.SetResource(mesh.NormalTexture);
     }
 }
예제 #21
0
        void SetSceneConstants()
        {
            FreeLook freelook = Demo.Freelook;
            Vector3  up       = MathHelper.Convert(freelook.Up);

            sceneConstants.View        = Matrix.LookAtLH(MathHelper.Convert(freelook.Eye), MathHelper.Convert(freelook.Target), up);
            sceneConstants.Projection  = Matrix.PerspectiveFovLH(FieldOfView, AspectRatio, _nearPlane, FarPlane);
            sceneConstants.ViewInverse = Matrix.Invert(sceneConstants.View);

            Vector3 light = new Vector3(20, 30, 10);
            Texture2DDescription depthBuffer = lightDepthTexture.Description;
            Matrix lightView       = Matrix.LookAtLH(light, Vector3.Zero, up);
            Matrix lightProjection = Matrix.OrthoLH(depthBuffer.Width / 8.0f, depthBuffer.Height / 8.0f, _nearPlane, FarPlane);

            sceneConstants.LightViewProjection = lightView * lightProjection;

            DataStream data;

            _immediateContext.MapSubresource(sceneConstantsBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out data);
            Marshal.StructureToPtr(sceneConstants, data.DataPointer, false);
            _immediateContext.UnmapSubresource(sceneConstantsBuffer, 0);
            data.Dispose();

            inverseProjectionVar.SetMatrix(Matrix.Invert(sceneConstants.Projection));
            inverseViewVar.SetMatrix(sceneConstants.ViewInverse);
            lightInverseViewProjectionVar.SetMatrix(Matrix.Invert(sceneConstants.LightViewProjection));
            lightPositionVar.Set(new Vector4(light, 1));
            eyePositionVar.Set(new Vector4(MathHelper.Convert(freelook.Eye), 1));
            eyeZAxisVar.Set(new Vector4(Vector3.Normalize(MathHelper.Convert(freelook.Target - freelook.Eye)), 1));

            float tanHalfFOVY = (float)Math.Tan(FieldOfView * 0.5f);

            tanHalfFOVXVar.Set(tanHalfFOVY * AspectRatio);
            tanHalfFOVYVar.Set(tanHalfFOVY);
            float projectionA = FarPlane / (FarPlane - _nearPlane);
            float projectionB = -projectionA * _nearPlane;

            projectionAVar.Set(projectionA);
            projectionBVar.Set(projectionB);

            Matrix overlayMatrix = Matrix.Scaling(info.Width / _width, info.Height / _height, 1.0f);

            overlayMatrix *= Matrix.Translation(-(_width - info.Width) / _width, (_height - info.Height) / _height, 0.0f);
            overlayViewProjectionVar.SetMatrix(overlayMatrix);
        }
예제 #22
0
        private void RenderNode(SceneGraph Node, Camera Camera, SlimDX.Matrix ProjMatrix, int indexOffset, int vertexOffset, out int indicesConsumed, out int verticesConsumed)
        {
            var ic = indexOffset;
            var vc = vertexOffset;

            if (Node.Renderable != null)
            {
                WorldViewProj = Node.WorldTransform * Camera.GetViewMatrix() * ProjMatrix;
                CPO_WorldViewProj.SetMatrix(WorldViewProj);
                SRV_BasicTexture.SetResource(Flyweights.TextureManager.GetInstance().GetResource(Device, Node.Renderable.GetTexturePath()));
                //ImmediateContext.PixelShader.SetShaderResource(Flyweights.TextureManager.GetInstance().GetResource(Device, Node.Renderable.GetTexturePath()), 0);

                int nIndices = Node.Renderable.GetIndexList(EffectName()).Length;
                int nVerts   = Node.Renderable.GetVertexList(EffectName()).Length;

                // If selected, set the color:
                if (OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode == Node)
                {
                    CPO_SelectionColor.Set(new Color4(0.75f, 0.34f, 0.66f, 1.0f));
                }
                else
                {
                    CPO_SelectionColor.Set(new Color4(0.0f, 0.0f, 0.0f, 0.0f));
                }

                Pass.Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(nIndices, indexOffset, vertexOffset);

                ic += nIndices;
                vc += nVerts;
            }

            foreach (var Child in Node.Children)
            {
                int cic, cvc;
                RenderNode(Child.Value, Camera, ProjMatrix, indexOffset + ic, vertexOffset + vc, out cic, out cvc);
                ic = cic;
                vc = cvc;
            }

            indicesConsumed  = ic;
            verticesConsumed = vc;
        }
예제 #23
0
        public override void DrawScene()
        {
            base.DrawScene();
            ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.LightSteelBlue);
            ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

            ImmediateContext.InputAssembler.InputLayout       = _inputLayout;
            ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vb, VertexPC.Stride, 0));
            ImmediateContext.InputAssembler.SetIndexBuffer(_ib, Format.R32_UInt, 0);

            var wvp = _world * _view * _proj;

            _fxWVP.SetMatrix(wvp);
            for (int p = 0; p < _tech.Description.PassCount; p++)
            {
                _tech.GetPassByIndex(p).Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(_gridIndexCount, 0, 0);
            }
            SwapChain.Present(0, PresentFlags.None);
        }
예제 #24
0
        public override void DrawScene()
        {
            base.DrawScene();
            ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.DarkGray);
            ImmediateContext.ClearDepthStencilView(DepthStencilView,
                                                   DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);

            ImmediateContext.InputAssembler.InputLayout       = _inputLayout;
            ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            var wvp = _world * _view * _proj;

            _fxWVP.SetMatrix(wvp);

            // Lighting
            var array = Util.GetArray(_ambientLight);

            _fxAmbientLight.SetRawValue(
                new DataStream(array, false, false), Marshal.SizeOf(_ambientLight)
                );
            array = Util.GetArray(_spotLight);
            _fxSpotLight.SetRawValue(
                new DataStream(array, false, false), Marshal.SizeOf(_spotLight)
                );
            _fxEyePosW.Set(_eyePosW);

            ImmediateContext.InputAssembler.SetVertexBuffers(0,
                                                             new VertexBufferBinding(_cubeVB, VertexPMN.Stride, 0));
            ImmediateContext.InputAssembler.SetIndexBuffer(_cubeIB, Format.R32_UInt, 0);

            for (int p = 0; p < _tech.Description.PassCount; p++)
            {
                _tech.GetPassByIndex(p).Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(36, 0, 0);
            }

            SwapChain.Present(0, PresentFlags.None);
        }
예제 #25
0
        /// <summary>
        /// Sets up our canonical transform matrices.
        /// </summary>
        private void SetTransforms()
        {
            // world transform: from local coordinates (geo space) to world coordinates (in [0..1] space)
            // this involves a scaling and translation, and also a rotation if we are using the trackball
            m_worldTransform = Matrix.Translation(TranslationVector) * Matrix.Scaling(ScaleVector) * RotationMatrix;

            // view transform: from world coordinates to view (camera, eye) coordinates
            // the "up" direction is the Y axis
            m_worldUp = new Vector3(0, 1, 0);
            view      = Matrix.LookAtLH(CameraPosition, TargetPosition, m_worldUp);

            // projection transform: from view coordinates to perspective space
            float znear = 0.0f;  // in view space
            float zfar  = 10.0f; // in view space

            if (m_perspective)
            {
                float fovY   = DegreesToRadians(45);
                float aspect = 1.0f;
                m_projectionTransform = Matrix.PerspectiveFovLH(fovY, aspect, znear, zfar);
            }
            else
            {
                float width  = 2.0f;
                float height = 2.0f;
                m_projectionTransform = Matrix.OrthoLH(width, height, znear, zfar);
            }

            // compute the summary transform, and push it into the gpu
            SlimDX.Matrix        wvp          = m_worldTransform * view * m_projectionTransform;
            EffectMatrixVariable wvpTransform = m_effect.GetVariableByName("gWVP").AsMatrix();

            wvpTransform.SetMatrix(wvp);

            return;
        }
예제 #26
0
        void UpdateTransform(OculusWrap.OVR.Posef eye_pose, OculusWrap.OVR.FovPort fov)
        {
            // Retrieve the eye rotation quaternion and use it to calculate the LookAt direction and the LookUp direction.
            Camera camera = new Camera()
            {
                Position = main_camera.Position + Vector3.Transform(eye_pose.Position.ToVector3(), main_camera.Rotation),
                Rotation = main_camera.Rotation * SharpDXHelpers.ToQuaternion(eye_pose.Orientation),
            };

            world_matrix         = Matrix.Scaling(ocu_config.Scale);
            Transform_View       = camera.GetViewMatrix();
            Transform_Projection = OculusWrap.OVR.ovrMatrix4f_Projection(fov, ocu_config.Znear, ocu_config.Zfar, OculusWrap.OVR.ProjectionModifier.RightHanded).ToMatrix();
            Transform_Projection.Transpose();

            Matrix world_view_matrix = world_matrix * Transform_View;

            world_view_projection_matrix = world_view_matrix * Transform_Projection;

            World_variable.SetMatrix(world_matrix);
            WorldView_variable.SetMatrix(world_view_matrix);
            WorldViewProjection_variable.SetMatrix(world_view_projection_matrix);
            /* for HUD */
            Projection_variable.SetMatrix(Transform_Projection);
        }
예제 #27
0
파일: BasicEffect.cs 프로젝트: kkdevs/sb3u
 public void SetTexTransform(Matrix m)
 {
     _texTransform.SetMatrix(m);
 }
예제 #28
0
파일: BasicEffect.cs 프로젝트: kkdevs/sb3u
 public void SetWorldInvTranspose(Matrix m)
 {
     _worldInvTranspose.SetMatrix(m);
 }
예제 #29
0
파일: BasicEffect.cs 프로젝트: kkdevs/sb3u
 public void SetWorld(Matrix m)
 {
     _world.SetMatrix(m);
 }
예제 #30
0
파일: BasicEffect.cs 프로젝트: kkdevs/sb3u
 public void SetWorldViewProj(Matrix m)
 {
     _worldViewProj.SetMatrix(m);
 }
예제 #31
0
        public DrawingManager(DeviceManager deviceManager)
        {
            _device = deviceManager.Device;
            _context = deviceManager.Context;
            _vertexLayouts = deviceManager.VertexLayouts;

            var effect = deviceManager.Effect;

            _standardSmooth = effect.GetTechniqueByName("Standard|Smooth");
            _standardFlat = effect.GetTechniqueByName("Standard|Flat");
            _standardWireframe = effect.GetTechniqueByName("Standard|Wireframe");
            _prelitSmooth = effect.GetTechniqueByName("Prelit|Smooth");
            _prelitFlat = effect.GetTechniqueByName("Prelit|Flat");
            _prelitWireframe = effect.GetTechniqueByName("Prelit|Wireframe");

            _worldMatrix = effect.GetVariableByName("g_WorldMatrix").AsMatrix();
            _postWorldMatrix = effect.GetVariableByName("g_PostWorldMatrix").AsMatrix();
            _viewMatrix = effect.GetVariableByName("g_ViewMatrix").AsMatrix();
            _projectionMatrix = effect.GetVariableByName("g_ProjectionMatrix").AsMatrix();
            _color = effect.GetVariableByName("g_Color").AsVector();
            _opacity = effect.GetVariableByName("g_Opacity").AsScalar();
            _ambient = effect.GetVariableByName("g_Ambient").AsScalar();
            _diffuse = effect.GetVariableByName("g_Diffuse").AsScalar();
            _texture = effect.GetVariableByName("g_Texture").AsShaderResource();
            _mask = effect.GetVariableByName("g_Mask").AsShaderResource();
            _textureSampler = effect.GetVariableByName("g_TextureSampler").AsSampler();
            _hasTexture = effect.GetVariableByName("g_HasTexture").AsScalar();
            _hasMask = effect.GetVariableByName("g_HasMask").AsScalar();
            _isInstanced = effect.GetVariableByName("g_IsInstanced").AsScalar();
            _isColorTinted = effect.GetVariableByName("g_IsColorTinted").AsScalar();
            _globalLight = effect.GetVariableByName("g_GlobalLight");
            _lightViewProjectionMatrix = effect.GetVariableByName("g_LightViewProjectionMatrix").AsMatrix();

            //Set the states to Unknown initially.
            _currentDrawingState = DrawingState.Unknown;
            _currentTopologyState = PrimitiveTopologyState.Unknown;

            //Set the default of the g_PostWorldMatrix to Identity, so it isn't required to be set.
            _postWorldMatrix.SetMatrix(Matrix.Identity);

            //Setup shadow map technique.
            var shadowEffect = deviceManager.ShadowEffect;
            _shadowMapStandard = shadowEffect.GetTechniqueByName("ShadowMapTechnique|Standard");
            _shadowMapPrelit = shadowEffect.GetTechniqueByName("ShadowMapTechnique|Prelit");

            _isShadowInstanced = shadowEffect.GetVariableByName("g_IsInstanced").AsScalar();
            _shadowWorldMatrix = shadowEffect.GetVariableByName("g_WorldMatrix").AsMatrix();
            _shadowHasMask = shadowEffect.GetVariableByName("g_HasMask").AsScalar();
            _shadowMask = shadowEffect.GetVariableByName("g_Mask").AsShaderResource();
            _shadowLightViewProjectionMatrix = shadowEffect.GetVariableByName("g_LightViewProjectionMatrix").AsMatrix();
        }