Esempio n. 1
0
        public override void UpdateNode()
        {
            if (!MapView.MapIsEnabled)
            {
                base.UpdateNode();

                m_fourier.PeformFFT(m_fourierBuffer5, m_fourierBuffer6, m_fourierBuffer7);

                m_whiteCapsPrecomputeMat.SetTexture("_Map5", m_fourierBuffer5[m_idx]);
                m_whiteCapsPrecomputeMat.SetTexture("_Map6", m_fourierBuffer6[m_idx]);
                m_whiteCapsPrecomputeMat.SetTexture("_Map7", m_fourierBuffer7[m_idx]);
                m_whiteCapsPrecomputeMat.SetVector("_Choppyness", m_choppyness * choppynessMultiplier);

                RenderTexture[] buffers = new RenderTexture[] {
                    m_foam0, m_foam1
                };

                //			RTUtility.MultiTargetBlit(buffers, m_whiteCapsPrecomputeMat);
                RTUtility.MultiTargetBlit(buffers, m_whiteCapsPrecomputeMat, 0);

                m_oceanMaterialFar.SetFloat("_Ocean_WhiteCapStr", m_whiteCapStr);
                m_oceanMaterialFar.SetFloat("farWhiteCapStr", m_farWhiteCapStr);
                m_oceanMaterialFar.SetTexture("_Ocean_Foam0", m_foam0);
                m_oceanMaterialFar.SetTexture("_Ocean_Foam1", m_foam1);

                m_oceanMaterialNear.SetFloat("_Ocean_WhiteCapStr", m_whiteCapStr);
                m_oceanMaterialNear.SetFloat("farWhiteCapStr", m_farWhiteCapStr);
                m_oceanMaterialNear.SetTexture("_Ocean_Foam0", m_foam0);
                m_oceanMaterialNear.SetTexture("_Ocean_Foam1", m_foam1);
            }
        }
Esempio n. 2
0
        protected override void InitWaveSpectrum(float t)
        {
            base.InitWaveSpectrum(t);

            // Init jacobians (5,6,7)
            RenderTexture[] buffers567 = new RenderTexture[] { m_fourierBuffer5[1], m_fourierBuffer6[1], m_fourierBuffer7[1] };
            m_initJacobiansMat.SetFloat(ShaderProperties._T_PROPERTY, t);
            //			RTUtility.MultiTargetBlit(buffers567, m_initJacobiansMat);
            RTUtility.MultiTargetBlit(buffers567, m_initJacobiansMat, 0);
        }
Esempio n. 3
0
        public int PeformFFT(RenderTexture[] data0, RenderTexture[] data1, RenderTexture[] data2)
        {
            RenderTexture[] pass0 = new RenderTexture[] { data0[0], data1[0], data2[0] };
            RenderTexture[] pass1 = new RenderTexture[] { data0[1], data1[1], data2[1] };

            int i;
            int idx = 0; int idx1;
            int j = 0;

            for (i = 0; i < m_passes; i++, j++)
            {
                idx  = j % 2;
                idx1 = (j + 1) % 2;

                m_fourier.SetTexture("_ButterFlyLookUp", m_butterflyLookupTable[i]);

                m_fourier.SetTexture("_ReadBuffer0", data0[idx1]);
                m_fourier.SetTexture("_ReadBuffer1", data1[idx1]);
                m_fourier.SetTexture("_ReadBuffer2", data2[idx1]);

                if (idx == 0)
                {
                    RTUtility.MultiTargetBlit(pass0, m_fourier, PASS_X_3);
                }
                else
                {
                    RTUtility.MultiTargetBlit(pass1, m_fourier, PASS_X_3);
                }
            }

            for (i = 0; i < m_passes; i++, j++)
            {
                idx  = j % 2;
                idx1 = (j + 1) % 2;

                m_fourier.SetTexture("_ButterFlyLookUp", m_butterflyLookupTable[i]);

                m_fourier.SetTexture("_ReadBuffer0", data0[idx1]);
                m_fourier.SetTexture("_ReadBuffer1", data1[idx1]);
                m_fourier.SetTexture("_ReadBuffer2", data2[idx1]);

                if (idx == 0)
                {
                    RTUtility.MultiTargetBlit(pass0, m_fourier, PASS_Y_3);
                }
                else
                {
                    RTUtility.MultiTargetBlit(pass1, m_fourier, PASS_Y_3);
                }
            }

            return(idx);
        }
Esempio n. 4
0
        public int PeformFFT(RenderTexture[] data0, RenderTexture[] data1)
        {
            RenderTexture[] pass0 = new RenderTexture[] { data0[0], data1[0] };
            RenderTexture[] pass1 = new RenderTexture[] { data0[1], data1[1] };

            int i;
            int idx = 0; int idx1;
            int j = 0;

            for (i = 0; i < m_passes; i++, j++)
            {
                idx  = j % 2;
                idx1 = (j + 1) % 2;

                m_fourier.SetTexture(ShaderProperties._ButterFlyLookUp_PROPERTY, m_butterflyLookupTable[i]);

                m_fourier.SetTexture(ShaderProperties._ReadBuffer0_PROPERTY, data0[idx1]);
                m_fourier.SetTexture(ShaderProperties._ReadBuffer1_PROPERTY, data1[idx1]);

                if (idx == 0)
                {
                    RTUtility.MultiTargetBlit(pass0, m_fourier, PASS_X_2);
                }
                else
                {
                    RTUtility.MultiTargetBlit(pass1, m_fourier, PASS_X_2);
                }
            }

            for (i = 0; i < m_passes; i++, j++)
            {
                idx  = j % 2;
                idx1 = (j + 1) % 2;

                m_fourier.SetTexture(ShaderProperties._ButterFlyLookUp_PROPERTY, m_butterflyLookupTable[i]);

                m_fourier.SetTexture(ShaderProperties._ReadBuffer0_PROPERTY, data0[idx1]);
                m_fourier.SetTexture(ShaderProperties._ReadBuffer1_PROPERTY, data1[idx1]);

                if (idx == 0)
                {
                    RTUtility.MultiTargetBlit(pass0, m_fourier, PASS_Y_2);
                }
                else
                {
                    RTUtility.MultiTargetBlit(pass1, m_fourier, PASS_Y_2);
                }
            }

            return(idx);
        }
Esempio n. 5
0
        /*
         * Initializes the data to the shader that needs to
         * have the fourier transform applied to it this frame.
         */
        protected virtual void InitWaveSpectrum(float t)
        {
            // init heights (0) and slopes (1,2)
            RenderTexture[] buffers012 = new RenderTexture[] {
                m_fourierBuffer0[1], m_fourierBuffer1[1], m_fourierBuffer2[1]
            };
            m_initSpectrumMat.SetFloat(ShaderProperties._T_PROPERTY, t);
            //			RTUtility.MultiTargetBlit(buffers012, m_initSpectrumMat);
            RTUtility.MultiTargetBlit(buffers012, m_initSpectrumMat, 0);

            // Init displacement (3,4)
            RenderTexture[] buffers34 = new RenderTexture[] {
                m_fourierBuffer3[1], m_fourierBuffer4[1]
            };
            m_initDisplacementMat.SetTexture(ShaderProperties._Buffer1_PROPERTY, m_fourierBuffer1[1]);
            m_initDisplacementMat.SetTexture(ShaderProperties._Buffer2_PROPERTY, m_fourierBuffer2[1]);
            //			RTUtility.MultiTargetBlit(buffers34, m_initDisplacementMat);
            RTUtility.MultiTargetBlit(buffers34, m_initDisplacementMat, 0);
        }
Esempio n. 6
0
        void Start()
        {
            m_irradianceT = new RenderTexture[2];
            m_inscatterT  = new RenderTexture[2];

            m_transmittanceT = new RenderTexture(TRANSMITTANCE_W, TRANSMITTANCE_H, 0, RenderTextureFormat.ARGBFloat);
            m_transmittanceT.enableRandomWrite = true;
            m_transmittanceT.Create();

            m_irradianceT[0] = new RenderTexture(SKY_W, SKY_H, 0, RenderTextureFormat.ARGBFloat);
            m_irradianceT[0].enableRandomWrite = true;
            m_irradianceT[0].Create();

            m_irradianceT[1] = new RenderTexture(SKY_W, SKY_H, 0, RenderTextureFormat.ARGBFloat);
            m_irradianceT[1].enableRandomWrite = true;
            m_irradianceT[1].Create();

            m_inscatterT[0]                   = new RenderTexture(RES_MU_S * RES_NU, RES_MU, 0, RenderTextureFormat.ARGBFloat);
            m_inscatterT[0].isVolume          = true;
            m_inscatterT[0].enableRandomWrite = true;
            m_inscatterT[0].volumeDepth       = RES_R;
            m_inscatterT[0].Create();

            m_inscatterT[1]                   = new RenderTexture(RES_MU_S * RES_NU, RES_MU, 0, RenderTextureFormat.ARGBFloat);
            m_inscatterT[1].isVolume          = true;
            m_inscatterT[1].enableRandomWrite = true;
            m_inscatterT[1].volumeDepth       = RES_R;
            m_inscatterT[1].Create();

            m_deltaET = new RenderTexture(SKY_W, SKY_H, 0, RenderTextureFormat.ARGBFloat);
            m_deltaET.enableRandomWrite = true;
            m_deltaET.Create();

            m_deltaSRT                   = new RenderTexture(RES_MU_S * RES_NU, RES_MU, 0, RenderTextureFormat.ARGBFloat);
            m_deltaSRT.isVolume          = true;
            m_deltaSRT.enableRandomWrite = true;
            m_deltaSRT.volumeDepth       = RES_R;
            m_deltaSRT.Create();

            m_deltaSMT                   = new RenderTexture(RES_MU_S * RES_NU, RES_MU, 0, RenderTextureFormat.ARGBFloat);
            m_deltaSMT.isVolume          = true;
            m_deltaSMT.enableRandomWrite = true;
            m_deltaSMT.volumeDepth       = RES_R;
            m_deltaSMT.Create();

            m_deltaJT                   = new RenderTexture(RES_MU_S * RES_NU, RES_MU, 0, RenderTextureFormat.ARGBFloat);
            m_deltaJT.isVolume          = true;
            m_deltaJT.enableRandomWrite = true;
            m_deltaJT.volumeDepth       = RES_R;
            m_deltaJT.Create();

            SetParameters(m_copyInscatter1);
            SetParameters(m_copyInscatterN);
            SetParameters(m_copyIrradiance);
            SetParameters(m_inscatter1);
            SetParameters(m_inscatterN);
            SetParameters(m_inscatterS);
            SetParameters(m_irradiance1);
            SetParameters(m_irradianceN);
            SetParameters(m_transmittance);

            m_step  = 0;
            m_order = 2;

            RTUtility.ClearColor(m_irradianceT);

            while (!m_finished)
            {
                Preprocess();
            }
        }
Esempio n. 7
0
        void Preprocess()
        {
            if (m_step == 0)
            {
                // computes transmittance texture T (line 1 in algorithm 4.1)
                m_transmittance.SetTexture(0, "transmittanceWrite", m_transmittanceT);
                m_transmittance.Dispatch(0, TRANSMITTANCE_W / NUM_THREADS, TRANSMITTANCE_H / NUM_THREADS, 1);
            }
            else if (m_step == 1)
            {
                // computes irradiance texture deltaE (line 2 in algorithm 4.1)
                m_irradiance1.SetTexture(0, "transmittanceRead", m_transmittanceT);
                m_irradiance1.SetTexture(0, "deltaEWrite", m_deltaET);
                m_irradiance1.Dispatch(0, SKY_W / NUM_THREADS, SKY_H / NUM_THREADS, 1);

                if (WRITE_DEBUG_TEX)
                {
                    SaveAs8bit(SKY_W, SKY_H, 4, "/deltaE_debug", m_deltaET);
                }
            }
            else if (m_step == 2)
            {
                // computes single scattering texture deltaS (line 3 in algorithm 4.1)
                // Rayleigh and Mie separated in deltaSR + deltaSM
                m_inscatter1.SetTexture(0, "transmittanceRead", m_transmittanceT);
                m_inscatter1.SetTexture(0, "deltaSRWrite", m_deltaSRT);
                m_inscatter1.SetTexture(0, "deltaSMWrite", m_deltaSMT);

                //The inscatter calc's can be quite demanding for some cards so process
                //the calc's in layers instead of the whole 3D data set.
                for (int i = 0; i < RES_R; i++)
                {
                    m_inscatter1.SetInt("layer", i);
                    m_inscatter1.Dispatch(0, (RES_MU_S * RES_NU) / NUM_THREADS, RES_MU / NUM_THREADS, 1);
                }

                if (WRITE_DEBUG_TEX)
                {
                    SaveAs8bit(RES_MU_S * RES_NU, RES_MU * RES_R, 4, "/deltaSR_debug", m_deltaSRT);
                }

                if (WRITE_DEBUG_TEX)
                {
                    SaveAs8bit(RES_MU_S * RES_NU, RES_MU * RES_R, 4, "/deltaSM_debug", m_deltaSMT);
                }
            }
            else if (m_step == 3)
            {
                // copies deltaE into irradiance texture E (line 4 in algorithm 4.1)
                m_copyIrradiance.SetFloat("k", 0.0f);
                m_copyIrradiance.SetTexture(0, "deltaERead", m_deltaET);
                m_copyIrradiance.SetTexture(0, "irradianceRead", m_irradianceT[READ]);
                m_copyIrradiance.SetTexture(0, "irradianceWrite", m_irradianceT[WRITE]);
                m_copyIrradiance.Dispatch(0, SKY_W / NUM_THREADS, SKY_H / NUM_THREADS, 1);

                RTUtility.Swap(m_irradianceT);
            }
            else if (m_step == 4)
            {
                // copies deltaS into inscatter texture S (line 5 in algorithm 4.1)
                m_copyInscatter1.SetTexture(0, "deltaSRRead", m_deltaSRT);
                m_copyInscatter1.SetTexture(0, "deltaSMRead", m_deltaSMT);
                m_copyInscatter1.SetTexture(0, "inscatterWrite", m_inscatterT[WRITE]);

                //The inscatter calc's can be quite demanding for some cards so process
                //the calc's in layers instead of the whole 3D data set.
                for (int i = 0; i < RES_R; i++)
                {
                    m_copyInscatter1.SetInt("layer", i);
                    m_copyInscatter1.Dispatch(0, (RES_MU_S * RES_NU) / NUM_THREADS, RES_MU / NUM_THREADS, 1);
                }

                RTUtility.Swap(m_inscatterT);
            }
            else if (m_step == 5)
            {
                // computes deltaJ (line 7 in algorithm 4.1)
                m_inscatterS.SetInt("first", (m_order == 2) ? 1 : 0);
                m_inscatterS.SetTexture(0, "transmittanceRead", m_transmittanceT);
                m_inscatterS.SetTexture(0, "deltaERead", m_deltaET);
                m_inscatterS.SetTexture(0, "deltaSRRead", m_deltaSRT);
                m_inscatterS.SetTexture(0, "deltaSMRead", m_deltaSMT);
                m_inscatterS.SetTexture(0, "deltaJWrite", m_deltaJT);

                //The inscatter calc's can be quite demanding for some cards so process
                //the calc's in layers instead of the whole 3D data set.
                for (int i = 0; i < RES_R; i++)
                {
                    m_inscatterS.SetInt("layer", i);
                    m_inscatterS.Dispatch(0, (RES_MU_S * RES_NU) / NUM_THREADS, RES_MU / NUM_THREADS, 1);
                }
            }
            else if (m_step == 6)
            {
                // computes deltaE (line 8 in algorithm 4.1)
                m_irradianceN.SetInt("first", (m_order == 2) ? 1 : 0);
                m_irradianceN.SetTexture(0, "deltaSRRead", m_deltaSRT);
                m_irradianceN.SetTexture(0, "deltaSMRead", m_deltaSMT);
                m_irradianceN.SetTexture(0, "deltaEWrite", m_deltaET);
                m_irradianceN.Dispatch(0, SKY_W / NUM_THREADS, SKY_H / NUM_THREADS, 1);
            }
            else if (m_step == 7)
            {
                // computes deltaS (line 9 in algorithm 4.1)
                m_inscatterN.SetTexture(0, "transmittanceRead", m_transmittanceT);
                m_inscatterN.SetTexture(0, "deltaJRead", m_deltaJT);
                m_inscatterN.SetTexture(0, "deltaSRWrite", m_deltaSRT);

                //The inscatter calc's can be quite demanding for some cards so process
                //the calc's in layers instead of the whole 3D data set.
                for (int i = 0; i < RES_R; i++)
                {
                    m_inscatterN.SetInt("layer", i);
                    m_inscatterN.Dispatch(0, (RES_MU_S * RES_NU) / NUM_THREADS, RES_MU / NUM_THREADS, 1);
                }
            }
            else if (m_step == 8)
            {
                // adds deltaE into irradiance texture E (line 10 in algorithm 4.1)
                m_copyIrradiance.SetFloat("k", 1.0f);
                m_copyIrradiance.SetTexture(0, "deltaERead", m_deltaET);
                m_copyIrradiance.SetTexture(0, "irradianceRead", m_irradianceT[READ]);
                m_copyIrradiance.SetTexture(0, "irradianceWrite", m_irradianceT[WRITE]);
                m_copyIrradiance.Dispatch(0, SKY_W / NUM_THREADS, SKY_H / NUM_THREADS, 1);

                RTUtility.Swap(m_irradianceT);
            }
            else if (m_step == 9)
            {
                // adds deltaS into inscatter texture S (line 11 in algorithm 4.1)
                m_copyInscatterN.SetTexture(0, "deltaSRead", m_deltaSRT);
                m_copyInscatterN.SetTexture(0, "inscatterRead", m_inscatterT[READ]);
                m_copyInscatterN.SetTexture(0, "inscatterWrite", m_inscatterT[WRITE]);

                //The inscatter calc's can be quite demanding for some cards so process
                //the calc's in layers instead of the whole 3D data set.
                for (int i = 0; i < RES_R; i++)
                {
                    m_copyInscatterN.SetInt("layer", i);
                    m_copyInscatterN.Dispatch(0, (RES_MU_S * RES_NU) / NUM_THREADS, RES_MU / NUM_THREADS, 1);
                }

                RTUtility.Swap(m_inscatterT);

                if (m_order < 4)
                {
                    m_step   = 4;
                    m_order += 1;
                }
            }
            else if (m_step == 10)
            {
                SaveAsRaw(TRANSMITTANCE_W * TRANSMITTANCE_H, 3, "/transmittance", m_transmittanceT);

                SaveAsRaw(SKY_W * SKY_H, 3, "/irradiance", m_irradianceT[READ]);

                SaveAsRaw((RES_MU_S * RES_NU) * RES_MU * RES_R, 4, "/inscatter", m_inscatterT[READ]);

                if (WRITE_DEBUG_TEX)
                {
                    SaveAs8bit(TRANSMITTANCE_W, TRANSMITTANCE_H, 4, "/transmittance_debug", m_transmittanceT);

                    SaveAs8bit(SKY_W, SKY_H, 4, "/irradiance_debug", m_irradianceT[READ], 10.0f);

                    SaveAs8bit(RES_MU_S * RES_NU, RES_MU * RES_R, 4, "/inscater_debug", m_inscatterT[READ]);
                }
            }
            else if (m_step == 11)
            {
                m_finished = true;
                Debug.Log("Proland::PreProcessAtmo::Preprocess - Preprocess done. Files saved to - " + m_filePath);
            }

            m_step += 1;
        }