Exemple #1
0
        void    UpdateGraph1D_GPU(double _time)
        {
            m_CB_Main1D.m._resolutionX  = (uint)imagePanel.Width;
            m_CB_Main1D.m._resolutionY  = (uint)imagePanel.Height;
            m_CB_Main1D.m._signalSize   = (uint)SIGNAL_SIZE;
            m_CB_Main1D.m._signalFlags  = (uint)m_signalType1D;
            m_CB_Main1D.m._signalFlags |= checkBoxShowInput.Checked ? 0x100U : 0;
            m_CB_Main1D.m._signalFlags |= checkBoxShowReconstructedSignal.Checked ? 0x200U : 0;
            m_CB_Main1D.m._signalFlags |= (uint)m_filter1D << 16;
            m_CB_Main1D.m._time         = (float)_time;

            m_device1D.SetRenderStates(RASTERIZER_STATE.CULL_NONE, DEPTHSTENCIL_STATE.DISABLED, BLEND_STATE.DISABLED);

            // Generate signal
            if (m_Shader_GenerateSignal1D.Use())
            {
                m_device1D.SetRenderTarget(m_FFT1D_GPU.Input, null);
                m_CB_Main1D.UpdateData();
                m_device1D.RenderFullscreenQuad(m_Shader_GenerateSignal1D);
                m_device1D.RemoveRenderTargets();
            }

            // Apply FFT
            m_FFT1D_GPU.FFT_GPUInOut(-1.0f);

            // Filter signal
            if (m_filter1D != FILTER_TYPE.NONE && m_Shader_FilterSignal1D.Use())
            {
                m_FFT1D_GPU.SwapBuffers();
                m_FFT1D_GPU.Input.SetPS(0);
                m_device1D.SetRenderTarget(m_FFT1D_GPU.Output, null);
                m_CB_Main1D.UpdateData();
                m_device1D.RenderFullscreenQuad(m_Shader_FilterSignal1D);
                m_FFT1D_GPU.Input.RemoveFromLastAssignedSlots();
                m_device1D.RemoveRenderTargets();
            }

            // Copy spectrum & swap buffers
            m_texSpectrumCopy.CopyFrom(m_FFT1D_GPU.Output);
            m_FFT1D_GPU.SwapBuffers();

            // Apply FFT again to obtain signal back
            m_FFT1D_GPU.FFT_GPUInOut(1.0f);

            // Display result
            if (m_Shader_Display1D.Use())
            {
                m_device1D.SetRenderTarget(m_device1D.DefaultTarget, null);
                m_texSpectrumCopy.SetPS(0);
                m_FFT1D_GPU.Output.SetPS(1);

                m_CB_Main1D.UpdateData();

                m_device1D.RenderFullscreenQuad(m_Shader_Display1D);
                m_FFT1D_GPU.Output.RemoveFromLastAssignedSlots();
            }

            m_device1D.Present(false);
        }
Exemple #2
0
        public ThumbnailCapture(int Width, int Height)
        {
            ImgWidth  = Width;
            ImgHeight = Height;

            if (WorldFrame.Instance == null || WorldFrame.Instance.GraphicsContext == null)
            {
                return;
            }

            mTarget       = new RenderTarget(WorldFrame.Instance.GraphicsContext);
            mMatrixBuffer = new ConstantBuffer(WorldFrame.Instance.GraphicsContext);

            mCamera                    = new PerspectiveCamera();
            mCamera.ViewChanged       += delegate { mMatrixBuffer.UpdateData(mCamera.ViewProjection); };
            mCamera.ProjectionChanged += delegate { mMatrixBuffer.UpdateData(mCamera.ViewProjection); };
            mCamera.SetClip(0.2f, 1000.0f);
            mCamera.SetParameters(new Vector3(10, 0, 0), Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);

            renderTimer          = new Timer();
            renderTimer.Interval = 10;
            renderTimer.Tick    += OnRenderTimerTick;

            var texDesc = new Texture2DDescription
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.None,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Height            = ImgWidth,
                Width             = ImgWidth,
                Usage             = ResourceUsage.Default,
                SampleDescription = new SampleDescription(1, 0),
                OptionFlags       = ResourceOptionFlags.None,
                MipLevels         = 1
            };

            if (mResolveTexture != null)
            {
                mResolveTexture.Dispose();
            }

            mResolveTexture = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);

            if (mMapTexture != null)
            {
                mMapTexture.Dispose();
            }

            texDesc.CpuAccessFlags = CpuAccessFlags.Read;
            texDesc.Usage          = ResourceUsage.Staging;
            mMapTexture            = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);

            mTarget.Resize(ImgWidth, ImgHeight, true);
            mCamera.SetAspect((float)ImgWidth / ImgHeight);
        }
Exemple #3
0
        void Application_Idle(object sender, EventArgs e)
        {
            if (m_device == null)
            {
                return;
            }

            // Update main CB
            m_CB_Main.m._resolutionX = (uint)outputPanel.Width;
            m_CB_Main.m._resolutionY = (uint)outputPanel.Height;
            m_CB_Main.m._tanHalfFOV.Set(m_camera.AspectRatio * (float)Math.Tan(0.5 * CAMERA_FOV), (float)Math.Tan(0.5 * CAMERA_FOV));
            m_CB_Main.m._time = (float)(DateTime.Now - m_startTime).TotalSeconds;
            m_CB_Main.UpdateData();

            // Render pipo
            if (m_shader_RenderDistanceField.Use())
            {
                m_device.SetRenderStates(RASTERIZER_STATE.CULL_NONE, DEPTHSTENCIL_STATE.DISABLED, BLEND_STATE.DISABLED);
                m_device.SetRenderTarget(m_device.DefaultTarget, null);

                m_device.RenderFullscreenQuad(m_shader_RenderDistanceField);
            }

            m_device.Present(false);
        }
Exemple #4
0
        void            EncodeCubeMapIntoSH(ImageUtility.ImagesMatrix _cubemap)
        {
            float3[] envSH = _cubemap.EncodeSHOrder2();

            SphericalHarmonics.SHFunctions.FilterHanning(envSH, 2.8f);                  // Important otherwise banding occurs!

            m_CB_SH.m._SH0.Set(envSH[0], 0);
            m_CB_SH.m._SH1.Set(envSH[1], 0);
            m_CB_SH.m._SH2.Set(envSH[2], 0);
            m_CB_SH.m._SH3.Set(envSH[3], 0);
            m_CB_SH.m._SH4.Set(envSH[4], 0);
            m_CB_SH.m._SH5.Set(envSH[5], 0);
            m_CB_SH.m._SH6.Set(envSH[6], 0);
            m_CB_SH.m._SH7.Set(envSH[7], 0);
            m_CB_SH.m._SH8.Set(envSH[8], 0);
            m_CB_SH.UpdateData();


// // Encode as order-9 (100 coefficients), stored into a texture... FOR DEBUG PURPOSE ONLY!!
// float3[]	envSH2 = _cubemap.EncodeSH( 9 );
//
// PixelsBuffer	content = new PixelsBuffer( 100 * 16 );
// using ( BinaryWriter W = content.OpenStreamWrite() )
//  for ( uint i=0; i < 100; i++ ) {
//      W.Write( envSH2[i].x );
//      W.Write( envSH2[i].y );
//      W.Write( envSH2[i].z );
//      W.Write( 0.0f );
//  }
//
// Texture2D	texSH = new Texture2D( m_device, 100, 1, 1, 1, ImageUtility.PIXEL_FORMAT.RGBA32F, ImageUtility.COMPONENT_FORMAT.AUTO, false, false, new PixelsBuffer[] { content } );
//              texSH.Set( 30 );
        }
Exemple #5
0
        private void SyncLoad()
        {
            mSyncLoadToken = null;

            mTexParams.TextureScales   = new Vector4(mData.TextureScales);
            mTexParams.SpecularFactors = new Vector4(mData.SpecularFactors);
            mTexParams.ChunkLine       = new Vector4(0.0f, 0.7f, 0.0f, 0.0f);
            mTexParams.AreaColour      = ChunkEditManager.Instance.GetAreaColour(mData.AreaId, mData.HasImpassFlag);

            mTexAnimBuffer       = new ConstantBuffer(WorldFrame.Instance.GraphicsContext);
            mTexAnimStore.Layer0 = mTexAnimStore.Layer1 = mTexAnimStore.Layer2 = mTexAnimStore.Layer3 = Matrix.Identity;
            mTexAnimBuffer.UpdateData(mTexAnimStore);
            mAlphaTexture = new Graphics.Texture(WorldFrame.Instance.GraphicsContext);
            mAlphaTexture.UpdateMemory(64, 64, Format.R8G8B8A8_UNorm, mData.AlphaValues, 4 * 64);
            mHoleTexture = new Graphics.Texture(WorldFrame.Instance.GraphicsContext);
            mHoleTexture.UpdateMemory(8, 8, Format.R8_UNorm, mData.HoleValues, 8);
            mScaleBuffer = new ConstantBuffer(WorldFrame.Instance.GraphicsContext);
            mScaleBuffer.UpdateData(mTexParams);
            mShaderTextures         = mData.Textures.ToArray();
            mShaderSpecularTextures = mData.SpecularTextures.ToArray();

            SetRenderMode(ChunkEditManager.Instance.ChunkRenderMode); //Set current render mode

            mIsSyncLoaded = true;
        }
        public void OnFrame()
        {
            if (mSkipRendering)
            {
                return;
            }

            if (mIsSyncLoaded == false)
            {
                SyncLoad();
            }

            mAnimator.Update();

            Mesh.BeginDraw();
            Mesh.Program.SetPixelSampler(0, Sampler);

            Mesh.UpdateIndexBuffer(mIndexBuffer);
            Mesh.UpdateVertexBuffer(mVertexBuffer);

            if (mAnimator.GetBones(mAnimationMatrices))
            {
                mAnimBuffer.UpdateData(mAnimationMatrices);
            }

            Mesh.Program.SetVertexConstantBuffer(2, mAnimBuffer);
            Mesh.Program.SetVertexConstantBuffer(3, mPerPassBuffer);

            foreach (var pass in mModel.Passes)
            {
                var cullingDisabled = (pass.RenderFlag & 0x04) != 0;
                Mesh.UpdateRasterizerState(cullingDisabled ? gNoCullState : gCullState);
                Mesh.UpdateBlendState(BlendStates[pass.BlendMode]);

                var oldProgram = Mesh.Program;
                Mesh.Program = (pass.BlendMode > 0 ? gBlendProgram : gNoBlendProgram);
                if (Mesh.Program != oldProgram)
                {
                    Mesh.Program.Bind();
                }

                var unlit    = ((pass.RenderFlag & 0x01) != 0) ? 0.0f : 1.0f;
                var unfogged = ((pass.RenderFlag & 0x02) != 0) ? 0.0f : 1.0f;

                Matrix uvAnimMat;
                mAnimator.GetUvAnimMatrix(pass.TexAnimIndex, out uvAnimMat);

                mPerPassBuffer.UpdateData(new PerModelPassBuffer()
                {
                    uvAnimMatrix    = uvAnimMat,
                    modelPassParams = new Vector4(unlit, unfogged, 0.0f, 0.0f)
                });

                Mesh.StartVertex = 0;
                Mesh.StartIndex  = pass.StartIndex;
                Mesh.IndexCount  = pass.IndexCount;
                Mesh.Program.SetPixelTexture(0, pass.Textures.First());
                Mesh.Draw();
            }
        }
Exemple #7
0
 private void ForceRenderMode(IO.Files.Terrain.MapChunk chunk, bool updateHoles)
 {
     if (chunk == mData)
     {
         if (updateHoles)
         {
             mHoleTexture.UpdateMemory(8, 8, Format.R8_UNorm, mData.HoleValues, 8);
         }
         else
         {
             mTexParams.AreaColour = ChunkEditManager.Instance.GetAreaColour(mData.AreaId, chunk.HasImpassFlag);
             SetRenderMode(ChunkEditManager.Instance.ChunkRenderMode);
             mScaleBuffer.UpdateData(mTexParams);
         }
     }
 }
Exemple #8
0
        public void Initialize(RenderControl window, GxContext context)
        {
            mGlobalBuffer            = new ConstantBuffer(context);
            mGlobalParamsBuffer      = new ConstantBuffer(context);
            mGlobalParamsBufferStore = new GlobalParamsBuffer
            {
                mapAmbient      = new Vector4(0.5f, 0.5f, 0.5f, 1.0f),
                mapDiffuse      = new Vector4(0.25f, 0.5f, 1.0f, 1.0f),
                fogColor        = new Vector4(0.25f, 0.5f, 1.0f, 1.0f),
                fogParams       = new Vector4(500.0f, 900.0f, mMainCamera.FarClip, 0.0f),
                brushParameters = new Vector4(45.0f, 55.0f, 0.0f, 0.0f),
                mousePosition   = new Vector4(float.MaxValue),
                eyePosition     = Vector4.Zero,
                brushSettings   = new Vector4(0, 1, 0, 0)
            };

            mGlobalParamsBuffer.UpdateData(mGlobalParamsBufferStore);

            mGlobalBufferStore = new GlobalBuffer
            {
                eyePosition = Vector4.Zero,
                matProj     = Matrix.Identity,
                matView     = Matrix.Identity
            };

            mGlobalBuffer.UpdateData(mGlobalBufferStore);

            Dispatcher = new GraphicsDispatcher();
            MapChunkRender.Initialize(context);
            MapAreaLowRender.Initialize(context);
            WmoGroupRender.Initialize(context);
            M2BatchRenderer.Initialize(context);
            M2ModelRenderer.Initialize(context);

            StaticAnimationThread.Instance.Initialize();

            WmoManager.Initialize();
            M2Manager.Initialize();

            GraphicsContext = context;

            SetActiveCamera(mMainCamera);
            TextureManager.Instance.Initialize(context);

            MapManager.Initialize();

            mMainCamera.ViewChanged       += ViewChanged;
            mMainCamera.ProjectionChanged += ProjectionChanged;

            ViewChanged(mMainCamera, mMainCamera.View);
            ProjectionChanged(mMainCamera, mMainCamera.Projection);

            CamControl = new CameraControl(window);
            CamControl.PositionChanged += MapManager.UpdatePosition;

            if (!LeftHandedCamera)
            {
                CamControl.InvertY = true;
            }
        }
Exemple #9
0
        private void    ApplyBilateralFiltering(Texture2D _Source, Texture2D _Target, float _BilateralRadius, float _BilateralTolerance, bool _Wrap)
        {
            _Source.SetCS(0);
            _Target.SetCSUAV(0);

            m_CB_Filter.m.Radius    = _BilateralRadius;
            m_CB_Filter.m.Tolerance = _BilateralTolerance;
            m_CB_Filter.m.Tile      = (uint)(_Wrap ? 1 : 0);

            m_CS_BilateralFilter.Use();

            uint h          = Math.Max(1, MAX_LINES * 1024 / W);
            uint callsCount = (uint)Math.Ceiling((float)H / h);

            for (uint i = 0; i < callsCount; i++)
            {
                m_CB_Filter.m.Y0 = i * h;
                m_CB_Filter.UpdateData();

                m_CS_BilateralFilter.Dispatch(W, h, 1);

                m_device.Present(true);

                progressBar.Value = (int)(0.01f * (0 + BILATERAL_PROGRESS * (i + 1) / callsCount) * progressBar.Maximum);
//				for ( int a=0; a < 10; a++ )
                Application.DoEvents();
            }

            // Single gulp (crashes the driver on large images!)
//			m_CS_BilateralFilter.Dispatch( W, H, 1 );

            _Target.RemoveFromLastAssignedSlotUAV();                    // So we can use it as input for next stage
        }
Exemple #10
0
        void Application_Idle(object sender, EventArgs e)
        {
            if (m_device == null)
            {
                return;
            }

            // Setup default target and depth stencil
            m_device.SetRenderTarget(m_device.DefaultTarget, m_device.DefaultDepthStencil);

            // Setup default render states
            m_device.SetRenderStates(RASTERIZER_STATE.CULL_BACK, DEPTHSTENCIL_STATE.READ_WRITE_DEPTH_LESS, BLEND_STATE.DISABLED);

            // Clear target & depth
            m_device.Clear(new float4(0.2f, 0.2f, 0.2f, 1.0f));
            m_device.ClearDepthStencil(m_device.DefaultDepthStencil, 1.0f, 0, true, false);

            // Render the cube
            if (m_shader_renderCube.Use())
            {
                m_CB_Camera.m._world2Proj = ComputeCameraProjection();
                m_CB_Camera.UpdateData();

                m_prim_cube.Render(m_shader_renderCube);
            }

            // Present
            m_device.Present(false);
        }
Exemple #11
0
        void    DrawLine(float3 _start, float3 _end, float3 _ortho, float _thickness, float4 _color)
        {
            if (_thickness <= 0.0f)
            {
                // Compute the world size of a pixel for the farthest extremity of the line
                float3 wsCameraPos = (float3)m_Camera.World2Camera.GetRow(3);
                float3 wsDir       = _end - _start;
                float  t           = -wsDir.Dot(_start - wsCameraPos) / wsDir.Dot(wsDir);
                t = Math.Max(0.0f, Math.Min(1.0f, t));
                float3 wsNearest = _start + t * wsDir;
                float4 csNearest = new float4(wsNearest, 1) * m_Camera.World2Camera;
                float  worldSize = 2.0f * (float)Math.Tan(0.5f * m_Camera.PerspectiveFOV) * csNearest.z;
                _thickness *= -worldSize / panelOutput.Height;
            }

            m_CB_Line.m._wsPosition0 = _start;
            m_CB_Line.m._thickness   = _thickness;
            m_CB_Line.m._wsPosition1 = _end;
            m_CB_Line.m._wsOrtho     = _ortho;
            m_CB_Line.m._color       = _color;
            m_CB_Line.UpdateData();

            m_Shader_Line.Use();
            m_Prim_Quad.Render(m_Shader_Line);
        }
Exemple #12
0
        public SkySphere(float radius, int rings, int sectors, GxContext context)
        {
            mRadius         = radius;
            mBoundingSphere = new BoundingSphere(Vector3.Zero, radius);
            mSampler        = new Sampler(context);
            mMesh           = new Mesh(context);
            mMesh.AddElement("POSITION", 0, 3);
            mMesh.AddElement("TEXCOORD", 0, 2);
            mMesh.BlendState.BlendEnabled = false;
            mMesh.DepthState.DepthEnabled = true;
            mMesh.Stride = IO.SizeCache <SphereVertex> .Size;

            InitVertices(radius, rings, sectors);

            mMesh.VertexBuffer.UpdateData(mVertices);

            mMatrixBuffer = new ConstantBuffer(context);
            mMatrixBuffer.UpdateData(Matrix.Identity);

            var program = new ShaderProgram(context);

            program.SetVertexShader(Resources.Shaders.SkyVertex);
            program.SetPixelShader(Resources.Shaders.SkyPixel);

            mMesh.Program = program;
            mMesh.InitLayout(program);
        }
Exemple #13
0
        private void SyncLoad()
        {
            mIsSyncLoaded = true;

            if (mModel.Vertices.Length == 0 || mModel.Indices.Length == 0 || mModel.Passes.Count == 0)
            {
                mSkipRendering = true;
                return;
            }

            var ctx = WorldFrame.Instance.GraphicsContext;

            mVertexBuffer = new VertexBuffer(ctx);
            mIndexBuffer  = new IndexBuffer(ctx);

            mVertexBuffer.UpdateData(mModel.Vertices);
            mIndexBuffer.UpdateData(mModel.Indices);

            mAnimBuffer = new ConstantBuffer(ctx);
            mAnimBuffer.UpdateData(mAnimationMatrices);

            mPerPassBuffer = new ConstantBuffer(ctx);
            mPerPassBuffer.UpdateData(new PerModelPassBuffer()
            {
                uvAnimMatrix    = Matrix.Identity,
                modelPassParams = Vector4.Zero
            });
        }
Exemple #14
0
        private void SyncLoad()
        {
            mIsSyncLoaded  = true;
            mSyncLoadToken = null;

            if (Model.Vertices.Length == 0 || Model.Indices.Length == 0 || Model.Passes.Count == 0)
            {
                mSkipRendering = true;
                return;
            }

            var ctx = WorldFrame.Instance.GraphicsContext;

            VertexBuffer = new VertexBuffer(ctx);
            IndexBuffer  = new IndexBuffer(ctx);

            VertexBuffer.UpdateData(Model.Vertices);
            IndexBuffer.UpdateData(Model.Indices);

            if (Animator != null)
            {
                AnimBuffer = new ConstantBuffer(ctx);
                AnimBuffer.UpdateData(mAnimationMatrices);
            }

            mBatchRenderer.OnSyncLoad();
            mSingleRenderer.OnSyncLoad();
            mPortraitRenderer.OnSyncLoad();
        }
        void Application_Idle(object sender, EventArgs e)
        {
            if (m_device == null)
            {
                return;
            }

            DateTime currentTime = DateTime.Now;

            m_CB_Main.m._resolutionX = (uint)panelOutput.Width;
            m_CB_Main.m._resolutionY = (uint)panelOutput.Height;
            m_CB_Main.m._time        = (float)(currentTime - m_startTime).TotalSeconds;
            m_CB_Main.m._flags       = (uint)((checkBoxShowNormal.Checked ? 1U : 0U)
                                              | (checkBoxEnableCorrection.Checked ? 2U : 0U)
                                              );
            m_CB_Main.m._bend = floatTrackbarControlCurvatureStrength.Value;
            m_CB_Main.UpdateData();

            m_device.SetRenderStates(RASTERIZER_STATE.CULL_BACK, DEPTHSTENCIL_STATE.READ_WRITE_DEPTH_LESS, BLEND_STATE.DISABLED);
            m_device.Clear(float4.Zero);
            m_device.ClearDepthStencil(m_device.DefaultDepthStencil, 1.0f, (byte)0U, true, false);

//          if ( m_Shader_renderScene.Use() ) {
//              m_device.SetRenderTarget( m_device.DefaultTarget, m_device.DefaultDepthStencil );
//              m_Prim_Cube.Render( m_Shader_renderScene );
//          }
            if (m_Shader_renderSceneFinal.Use())
            {
                m_device.SetRenderTarget(m_device.DefaultTarget, m_device.DefaultDepthStencil);
                m_Prim_Torus.Render(m_Shader_renderSceneFinal);
            }

            m_device.Present(false);
        }
Exemple #16
0
        public static void Initialize(GxContext context)
        {
            gNoBlendState = new BlendState(context)
            {
                BlendEnabled = false
            };
            gAlphaBlendState = new BlendState(context)
            {
                BlendEnabled = true
            };

            gNoCullState = new RasterState(context)
            {
                CullEnabled = false
            };
            gCullState = new RasterState(context)
            {
                CullEnabled = true
            };

            Sampler = new Sampler(context);

            InstanceBuffer = new ConstantBuffer(context);
            InstanceBuffer.UpdateData(Matrix.Identity); // preallocate space so the underlying buffer wont change anymore

            Mesh = new Mesh(context)
            {
                DepthState = { DepthEnabled = true },
                Stride     = IO.SizeCache <IO.Files.Models.WmoVertex> .Size
            };

            Mesh.AddElement("POSITION", 0, 3);
            Mesh.AddElement("NORMAL", 0, 3);
            Mesh.AddElement("TEXCOORD", 0, 2);
            Mesh.AddElement("COLOR", 0, 4, DataType.Byte, true);

            gNoBlendProgram = new ShaderProgram(context);
            gNoBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex);
            gNoBlendProgram.SetPixelShader(Resources.Shaders.WmoPixel);

            gBlendProgram = new ShaderProgram(context);
            gBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex);
            gBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelBlend);

            gIndoorNoBlendProgram = new ShaderProgram(context);
            gIndoorNoBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex);
            gIndoorNoBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelIndoor);

            gIndoorBlendProgram = new ShaderProgram(context);
            gIndoorBlendProgram.SetVertexShader(Resources.Shaders.WmoVertex);
            gIndoorBlendProgram.SetPixelShader(Resources.Shaders.WmoPixelBlendIndoor);

            Mesh.Program = gNoBlendProgram;

            Mesh.InitLayout(gNoBlendProgram);
        }
Exemple #17
0
 void m_camera_CameraTransformChanged(object sender, EventArgs e)
 {
     m_CB_camera.m._Camera2World = m_camera.Camera2World;
     m_CB_camera.m._World2Camera = m_camera.World2Camera;
     m_CB_camera.m._Proj2World   = m_camera.Proj2World;
     m_CB_camera.m._World2Proj   = m_camera.World2Proj;
     m_CB_camera.m._Camera2Proj  = m_camera.Camera2Proj;
     m_CB_camera.m._Proj2Camera  = m_camera.Proj2Camera;
     m_CB_camera.UpdateData();
 }
Exemple #18
0
        public void OnSyncLoad()
        {
            var ctx = WorldFrame.Instance.GraphicsContext;

            if (mAnimator != null)
            {
                mAnimBuffer = new ConstantBuffer(ctx);
                mAnimBuffer.UpdateData(mAnimationMatrices);
            }
        }
Exemple #19
0
 private void CheckUpdateGlobalBuffer()
 {
     if (mGlobalBufferChanged)
     {
         lock (mGlobalBuffer)
         {
             mGlobalBuffer.UpdateData(mGlobalBufferStore);
             mGlobalBufferChanged = false;
         }
     }
 }
Exemple #20
0
 private void SyncLoad()
 {
     mAlphaTexture = new Graphics.Texture(WorldFrame.Instance.GraphicsContext);
     mAlphaTexture.UpdateMemory(64, 64, SharpDX.DXGI.Format.R8G8B8A8_UNorm, mData.AlphaValues, 4 * 64);
     mHoleTexture = new Graphics.Texture(WorldFrame.Instance.GraphicsContext);
     mHoleTexture.UpdateMemory(8, 8, SharpDX.DXGI.Format.R8_UNorm, mData.HoleValues, 8);
     mScaleBuffer = new ConstantBuffer(WorldFrame.Instance.GraphicsContext);
     mScaleBuffer.UpdateData(mData.TextureScales);
     mShaderTextures = mData.Textures.ToArray();
     mSyncLoaded     = true;
 }
Exemple #21
0
        void Application_Idle(object sender, EventArgs e)
        {
            if (m_device == null)
            {
                return;
            }

            DateTime currentTime = DateTime.Now;

            m_CB_Main.m._resolutionX    = (uint)panelOutput3D.Width;
            m_CB_Main.m._resolutionY    = (uint)panelOutput3D.Height;
            m_CB_Main.m._time           = (float)(currentTime - m_startTime).TotalSeconds;
            m_CB_Main.m._glossRoom      = floatTrackbarControlGlossWall.Value;
            m_CB_Main.m._glossSphere    = floatTrackbarControlGlossSphere.Value;
            m_CB_Main.m._noiseInfluence = floatTrackbarControlNoise.Value;
            m_CB_Main.UpdateData();

            m_device.SetRenderStates(RASTERIZER_STATE.CULL_NONE, DEPTHSTENCIL_STATE.DISABLED, BLEND_STATE.DISABLED);

            m_Tex_BlueNoise.SetPS(2);

            //////////////////////////////////////////////////////////////////////////
            // Render the wall texture
            if (m_Shader_renderWall.Use())
            {
                m_device.SetRenderTarget(m_Tex_Wall, null);
                m_device.RenderFullscreenQuad(m_Shader_renderWall);
            }

            //////////////////////////////////////////////////////////////////////////
            // Render the G-Buffer
            if (m_Shader_renderGBuffer.Use())
            {
                m_device.SetRenderTargets(m_Tex_GBuffer.Width, m_Tex_GBuffer.Height, new IView[] { m_Tex_GBuffer.GetView(0, 1, 0, 1), m_Tex_GBuffer.GetView(0, 1, 1, 1) }, null);
                m_device.RenderFullscreenQuad(m_Shader_renderGBuffer);
            }

            //////////////////////////////////////////////////////////////////////////
            // Path trace the scene
            if (m_Shader_renderScene.Use())
            {
                m_device.SetRenderTarget(m_device.DefaultTarget, null);
                m_Tex_GBuffer.SetPS(0);
                m_Tex_Wall.SetPS(1);

                m_device.RenderFullscreenQuad(m_Shader_renderScene);

                m_Tex_GBuffer.RemoveFromLastAssignedSlots();
                m_Tex_Wall.RemoveFromLastAssignedSlots();
            }

            m_device.Present(false);
        }
Exemple #22
0
        void    SetCamera(float3 _wsPosition, float3 _wsTargetPosition, float3 _wsUp, float _FOV)
        {
            m_CB_camera.m._camera2World.BuildRotLeftHanded(_wsPosition, _wsTargetPosition, _wsUp);
            m_CB_camera.m._camera2Proj.BuildProjectionPerspective(_FOV, (float)Width / Height, Z_NEAR, Z_FAR);

            m_CB_camera.m._proj2Camera  = m_CB_camera.m._camera2Proj.Inverse;
            m_CB_camera.m._world2Camera = m_CB_camera.m._camera2World.Inverse;
            m_CB_camera.m._proj2World   = m_CB_camera.m._proj2Camera * m_CB_camera.m._camera2World;
            m_CB_camera.m._world2Proj   = m_CB_camera.m._world2Camera * m_CB_camera.m._camera2Proj;

            m_CB_camera.UpdateData();
        }
Exemple #23
0
        void Application_Idle(object sender, EventArgs e)
        {
            if (m_Device == null)
            {
                return;
            }

            // Setup global data
            m_CB_Main.m._TargetSize = new float4(Width, Height, 1.0f / Width, 1.0f / Height);
            m_CB_Main.m._Flags      = (uint)((checkBoxShowCubeMapFaces.Checked ? 1 : 0) | (checkBoxShowDistance.Checked ? 2 : 0) | (checkBoxShowWSPosition.Checked ? 4 : 0) | (checkBoxShowSamples.Checked ? 8 : 0) | (checkBoxShowNeighbors.Checked ? 16 : 0));
            m_CB_Main.m._Type       = (uint)integerTrackbarControlDisplayType.Value;
            if (checkBoxShowSamples.Checked)
            {
                m_CB_Main.m._Type = (uint)(radioButtonSampleAll.Checked ? 1 : 0) | ((uint)(radioButtonSampleColor.Checked ? 0 : radioButtonSampleAlbedo.Checked ? 1 : radioButtonSampleNormal.Checked ? 2 : 4) << 1);
            }
            if (checkBoxShowNeighbors.Checked)
            {
                m_CB_Main.m._Type = (uint)(radioButtonNeighbors.Checked ? 0 : 1);
            }
            m_CB_Main.m._SampleIndex = (uint)integerTrackbarControlSampleIndex.Value;
            m_CB_Main.UpdateData();


            // Render the scene
            m_Device.SetRenderTarget(m_Device.DefaultTarget, null);
            m_Device.SetRenderStates(RASTERIZER_STATE.CULL_NONE, DEPTHSTENCIL_STATE.DISABLED, BLEND_STATE.DISABLED);

            if (m_Tex_CubeMap != null)
            {
                m_Tex_CubeMap.SetPS(0);
            }
            if (m_SB_Samples != null)
            {
                m_SB_Samples.SetInput(1);
            }
            if (m_SB_EmissiveSurfaces != null)
            {
                m_SB_EmissiveSurfaces.SetInput(2);
            }

            if (m_Shader_Render != null && m_Shader_Render.Use())
            {
                m_Device.RenderFullscreenQuad(m_Shader_Render);
            }
            else
            {
                m_Device.Clear(new float4(1, 1, 0, 0));
            }

            // Show!
            m_Device.Present(false);
        }
Exemple #24
0
        /// <summary>
        /// Main loop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Application_Idle(object sender, EventArgs e)
        {
            if (m_device == null)
            {
                return;
            }

            //////////////////////////////////////////////////////////////////////////
            // Update database & UI
            m_database.OnIdle();
            m_notificationForm.Animate();

            if (!Visible)
            {
                return;                 // Don't render 3D stuff
            }
            //////////////////////////////////////////////////////////////////////////
            // Render 3D stuff
            //
            DateTime frameTime = DateTime.Now;
            float    totalTime = (float)(frameTime - m_startTime).TotalSeconds;
            float    deltaTime = (float)(frameTime - m_lastFrameTime).TotalSeconds;

            m_lastFrameTime = frameTime;

            m_CB_main.m._resolution.Set(Width, Height, 1.0f / Width, 1.0f / Height);
            m_CB_main.m._mouseUV.Set((float)MousePosition.X / Width, (float)MousePosition.Y / Height, 0, 0);
            m_CB_main.m._time_DeltaTime.Set(totalTime, deltaTime);
            m_CB_main.UpdateData();

            // Animate camera
            float  phi              = Mathf.TWOPI * totalTime / 8.0f;                                            // 8 seconds for a full rotation
            float  theta            = Mathf.HALFPI * (1.0f + 0.25f * Mathf.Sin(Mathf.TWOPI * totalTime / 6.0f)); // 6 seconds for a full up/down cycle
            float3 wsTargetPosition = float3.Zero;
            float3 wsAt             = new float3(Mathf.Cos(phi) * Mathf.Sin(theta), Mathf.Sin(phi) * Mathf.Sin(theta), Mathf.Cos(theta));

            SetCamera(wsTargetPosition - 5.0f * wsAt, wsTargetPosition, float3.UnitY, Mathf.ToRad(90.0f));

            m_device.Clear(float4.Zero);
            m_device.ClearDepthStencil(m_device.DefaultDepthStencil, 1, 0, true, false);

            //////////////////////////////////////////////////////////////////////////
            // Display pipo cube
            if (m_shader_displayCube.Use())
            {
                m_device.SetRenderStates(RASTERIZER_STATE.CULL_BACK, DEPTHSTENCIL_STATE.READ_WRITE_DEPTH_LESS, BLEND_STATE.DISABLED);
                m_device.SetRenderTarget(m_device.DefaultTarget, m_device.DefaultDepthStencil);
                m_primitiveCube.Render(m_shader_displayCube);
            }

            m_device.Present(false);
        }
        void Camera_CameraTransformChanged(object sender, EventArgs e)
        {
            m_CB_Camera.m._camera2World = m_camera.Camera2World;
            m_CB_Camera.m._world2Camera = m_camera.World2Camera;

            m_CB_Camera.m._camera2Proj = m_camera.Camera2Proj;
            m_CB_Camera.m._proj2Camera = m_CB_Camera.m._camera2Proj.Inverse;

            m_CB_Camera.m._world2Proj = m_CB_Camera.m._world2Camera * m_CB_Camera.m._camera2Proj;
            m_CB_Camera.m._proj2World = m_CB_Camera.m._proj2Camera * m_CB_Camera.m._camera2World;

            m_CB_Camera.UpdateData();
        }
Exemple #26
0
        private void    Render()
        {
            m_Device.Clear(m_Device.DefaultTarget, 0.5f * new float4(Color.SkyBlue, 1));
            m_Device.ClearDepthStencil(m_Device.DefaultDepthStencil, 1, 0, true, false);


//          // Render the photon vectors
//          if ( checkBoxRenderVectors.Checked )
//          {
//              const int		PHOTON_VECTORS_COUNT_PER_FACE = 10000;
//              m_CB_RenderPhotonVector.m.VectorsPerFace = PHOTON_VECTORS_COUNT_PER_FACE;
//              m_CB_RenderPhotonVector.m.VectorMultiplier = floatTrackbarControlVectorSize.Value;
//              m_CB_RenderPhotonVector.m.ClipAboveValue = checkBoxClipAboveValue.Checked ? 0.01f * floatTrackbarControlClipAbove.Value : 1e6f;
//              m_CB_RenderPhotonVector.UpdateData();
//              m_PS_RenderPhotonVectors.Use();
//              m_Prim_Line.RenderInstanced( m_PS_RenderPhotonVectors, 6*PHOTON_VECTORS_COUNT_PER_FACE );
//          }


            // Render photon layers
            m_CB_Render.m.CloudScapeSize  = m_CloudScapeSize;
            m_CB_Render.m.LayersCount     = LAYERS_COUNT;
            m_CB_Render.m.StartLayerIndex = (uint)integerTrackbarControlLayerDisplayStart.Value;
            m_CB_Render.m.IntensityFactor = floatTrackbarControlDisplayIntensity.Value;
            m_CB_Render.m.DisplayType     = (uint)((radioButtonShowDirection.Checked ? 1 : (radioButtonShowDensityField.Checked ? 2 : 0))
                                                   | (checkBoxShowNormalized.Checked ? 4 : 0));
            m_CB_Render.UpdateData();

            m_Device.SetRenderTarget(m_Device.DefaultTarget, m_Device.DefaultDepthStencil);
            m_Device.SetRenderStates(RASTERIZER_STATE.CULL_NONE, DEPTHSTENCIL_STATE.READ_WRITE_DEPTH_LESS, BLEND_STATE.DISABLED);

            m_Tex_PhotonLayers_Flux.SetPS(0);
            m_Tex_PhotonLayers_Direction.SetPS(1);
            m_Tex_DensityField.SetPS(2);

            m_PS_RenderLayer.Use();

            int instancesCount = Math.Max(1, integerTrackbarControlLayerDisplayEnd.Value - integerTrackbarControlLayerDisplayStart.Value);

            m_Prim_Quad.RenderInstanced(m_PS_RenderLayer, instancesCount);

            // Render the world cube
            m_Device.SetRenderStates(RASTERIZER_STATE.CULL_BACK, DEPTHSTENCIL_STATE.READ_WRITE_DEPTH_LESS, BLEND_STATE.DISABLED);
            m_PS_RenderWorldCube.Use();
            m_Prim_Cube.Render(m_PS_RenderWorldCube);

            // Refresh
            viewportPanel.Invalidate();
        }
Exemple #27
0
        void Camera_CameraTransformChanged(object sender, EventArgs e)
        {
            m_CB_Camera.m._Camera2World = m_camera.Camera2World;
            m_CB_Camera.m._World2Camera = m_camera.World2Camera;

            m_CB_Camera.m._Camera2Proj = m_camera.Camera2Proj;
            m_CB_Camera.m._Proj2Camera = m_CB_Camera.m._Camera2Proj.Inverse;

            m_CB_Camera.m._World2Proj = m_CB_Camera.m._World2Camera * m_CB_Camera.m._Camera2Proj;
            m_CB_Camera.m._Proj2World = m_CB_Camera.m._Proj2Camera * m_CB_Camera.m._Camera2World;

            m_CB_Camera.UpdateData();

            m_groupCounter = 0;                 // Clear buffer
        }
Exemple #28
0
        void    DrawPlane(float3 _position, float3 _normal, float3 _tangent, float _sizeTop, float _sizeBottom, float _sizeY, float4 _color, bool _circle)
        {
            m_CB_Plane.m._wsPosition = _position;
            m_CB_Plane.m._wsNormal   = _normal;
            m_CB_Plane.m._wsTangent  = _tangent;
            m_CB_Plane.m._sizeX0     = _sizeTop;
            m_CB_Plane.m._sizeX1     = _sizeBottom;
            m_CB_Plane.m._sizeY      = _sizeY;
            m_CB_Plane.m._color      = _color;
            m_CB_Plane.m._flags      = (uint)(_circle ? 1 : 0);
            m_CB_Plane.UpdateData();

            m_Shader_Plane.Use();
            m_Prim_Quad.Render(m_Shader_Plane);
        }
        /// <summary>
        /// Directly applies the FFT to the input buffer
        /// </summary>
        /// <param name="_sign">Use -1 for forward FFT (temporal->frequential) and +1 for backward FFT (frequential->temporal)</param>
        public void     FFT_GPUInOut(float _sign)
        {
            try {
                m_CB.m._sign                   = _sign;
                m_CB.m._bitReversalShift       = (uint)(32 - m_POT);
                m_CB.m._normalizationFirstPass = _sign < 0.0f && m_CS__Remainder == null ? 1.0f / m_size : 1.0f;
                m_CB.m._normalizationFinal     = _sign < 0.0f && m_CS__Remainder != null ? 1.0f / m_size : 1.0f;
                m_CB.UpdateData();

                if (!m_CS__1to256.Use())
                {
                    throw new Exception("Failed to use compute shader: did it compile without error?");
                }

                m_texBufferIn.SetCS(0);
                m_texBufferOut.SetCSUAV(0);

                // • We're using groups of 128 threads
                // • Each thread reads and writes 2 values
                // ==> The total amount of elements processed by a group is thus 256
                uint groupsCount = (uint)(m_size >> 8);
                m_CS__1to256.Dispatch(groupsCount, 1, 1);

                m_texBufferIn.RemoveFromLastAssignedSlots();
                m_texBufferOut.RemoveFromLastAssignedSlotUAV();

                if (m_CS__Remainder != null)
                {
                    if (!m_CS__Remainder.Use())
                    {
                        throw new Exception("Failed to use compute shader: did it compile without error?");
                    }

                    // Swap in and out
                    SwapBuffers();

                    m_texBufferIn.SetCS(0);
                    m_texBufferOut.SetCSUAV(0);

                    m_CS__Remainder.Dispatch(4, 1, 1);

                    m_texBufferIn.RemoveFromLastAssignedSlots();
                    m_texBufferOut.RemoveFromLastAssignedSlotUAV();
                }
            } catch (Exception _e) {
                throw new Exception("An error occurred while performing the FFT!", _e);
            }
        }
Exemple #30
0
        public void OnSyncLoad()
        {
            var ctx = WorldFrame.Instance.GraphicsContext;

            mAnimBuffer = new ConstantBuffer(ctx);
            mAnimBuffer.UpdateData(mAnimationMatrices);

            mPerPassBuffer = new ConstantBuffer(ctx);
            mPerPassBuffer.UpdateData(new PerModelPassBuffer()
            {
                uvAnimMatrix1   = Matrix.Identity,
                modelPassParams = Vector4.Zero
            });

            gCullState.CullCounterClock = FileManager.Instance.Version >= FileDataVersion.Lichking;
        }