예제 #1
0
 private void LateUpdate()
 {
     if (Application.isPlaying)
     {
         GerstnerWavesJobs.UpdateHeights();
     }
 }
예제 #2
0
        void Update()
        {
            for (var i = 0; i < samplePoints.Length; i++)
            {
                samplePoints[i] = transform.TransformPoint(voxels[i]);
            }

            if (_buoyancyType == BuoyancyType.PhysicalVoxel || _buoyancyType == BuoyancyType.Physical) // if acurate the are more points so only heights are needed
            {
                GerstnerWavesJobs.UpdateSamplePoints(samplePoints, _guid, false);
                GerstnerWavesJobs.GetData(_guid, ref heights);
            }
            else
            {
                GerstnerWavesJobs.UpdateSamplePoints(samplePoints, _guid, true);
                GerstnerWavesJobs.GetSimpleData(_guid, ref heights, ref normals);

                if (_buoyancyType == BuoyancyType.NonPhysical)
                {
                    Vector3 vec = transform.position;
                    vec.y = heights[0].y;
                    transform.position = vec;
                    transform.up       = Vector3.Slerp(transform.up, normals[0], Time.deltaTime);
                }
                else if (_buoyancyType == BuoyancyType.NonPhysicalVoxel)
                {
                    // do the voxel non-physical
                }
            }
        }
예제 #3
0
        private void Update()
        {
            switch (_buoyancyType)
            {
            case BuoyancyType.NonPhysical:
            {
                var t   = transform;
                var vec = t.position;
                vec.y      = Heights[0].y + waterLevelOffset;
                t.position = vec;
                t.up       = Vector3.Slerp(t.up, _normals[0], Time.deltaTime);
                break;
            }

            case BuoyancyType.NonPhysicalVoxel:
                // do the voxel non-physical
                break;

            case BuoyancyType.Physical:
                LocalToWorldJob.CompleteJob(_guid);
                GetVelocityPoints();
                break;

            case BuoyancyType.PhysicalVoxel:
                LocalToWorldJob.CompleteJob(_guid);
                GetVelocityPoints();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            GerstnerWavesJobs.UpdateSamplePoints(ref _samplePoints, _guid);
            GerstnerWavesJobs.GetData(_guid, ref Heights, ref _normals);
        }
예제 #4
0
 void Cleanup()
 {
     if (Application.isPlaying)
     {
         GerstnerWavesJobs.Cleanup();
     }
     RenderPipelineManager.beginCameraRendering -= BeginCameraRendering;
     if (_depthCam)
     {
         _depthCam.targetTexture = null;
         SafeDestroy(_depthCam.gameObject);
     }
     if (_depthTex)
     {
         SafeDestroy(_depthTex);
     }
     if (_waveBuffer != null)
     {
         _waveBuffer.Dispose();
     }
 }
예제 #5
0
        private void SetWaves()
        {
            SetupWaves(surfaceData._customWaves);

            // set default resources
            Shader.SetGlobalTexture(FoamMap, resources.defaultFoamMap);
            Shader.SetGlobalTexture(SurfaceMap, resources.defaultSurfaceMap);

            _maxWaveHeight = 0f;
            foreach (var w in _waves)
            {
                _maxWaveHeight += w.amplitude;
            }
            _maxWaveHeight /= _waves.Length;

            _waveHeight = transform.position.y;

            Shader.SetGlobalFloat(WaveHeight, _waveHeight);
            Shader.SetGlobalFloat(MaxWaveHeight, _maxWaveHeight);
            Shader.SetGlobalFloat(MaxDepth, surfaceData._waterMaxVisibility);

            switch (settingsData.refType)
            {
            case ReflectionType.Cubemap:
                Shader.EnableKeyword("_REFLECTION_CUBEMAP");
                Shader.DisableKeyword("_REFLECTION_PROBES");
                Shader.DisableKeyword("_REFLECTION_PLANARREFLECTION");
                Shader.SetGlobalTexture(CubemapTexture, settingsData.cubemapRefType);
                break;

            case ReflectionType.ReflectionProbe:
                Shader.DisableKeyword("_REFLECTION_CUBEMAP");
                Shader.EnableKeyword("_REFLECTION_PROBES");
                Shader.DisableKeyword("_REFLECTION_PLANARREFLECTION");
                break;

            case ReflectionType.PlanarReflection:
                Shader.DisableKeyword("_REFLECTION_CUBEMAP");
                Shader.DisableKeyword("_REFLECTION_PROBES");
                Shader.EnableKeyword("_REFLECTION_PLANARREFLECTION");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Shader.SetGlobalInt(WaveCount, _waves.Length);

            //GPU side
            if (_useComputeBuffer)
            {
                Shader.EnableKeyword("USE_STRUCTURED_BUFFER");
                if (waveBuffer == null)
                {
                    waveBuffer = new ComputeBuffer(10, (sizeof(float) * 6));
                }
                waveBuffer.SetData(_waves);
                Shader.SetGlobalBuffer(WaveDataBuffer, waveBuffer);
            }
            else
            {
                Shader.DisableKeyword("USE_STRUCTURED_BUFFER");
                Shader.SetGlobalVectorArray(WaveData, GetWaveData());
            }
            //CPU side
            if (GerstnerWavesJobs.Initialized == false && Application.isPlaying)
            {
                GerstnerWavesJobs.Init();
            }
        }
예제 #6
0
 private void LateUpdate()
 {
     GerstnerWavesJobs.UpdateHeights();
 }
예제 #7
0
 private void OnApplicationQuit()
 {
     GerstnerWavesJobs.Cleanup();
 }
예제 #8
0
        void SetWaves()
        {
            SetupWaves(surfaceData._customWaves);

            // set default resources
            Shader.SetGlobalTexture("_FoamMap", resources.defaultFoamMap);
            Shader.SetGlobalTexture("_SurfaceMap", resources.defaultSurfaceMap);

            _maxWaveHeight = 0f;
            foreach (Wave w in _waves)
            {
                _maxWaveHeight += w.amplitude;
            }
            _maxWaveHeight /= (float)_waves.Length;

            Shader.SetGlobalFloat("_MaxWaveHeight", _maxWaveHeight);
            Shader.SetGlobalFloat("_MaxDepth", surfaceData._waterMaxVisibility);

            switch (settingsData.refType)
            {
            case ReflectionType.Cubemap:
                Shader.EnableKeyword("_REFLECTION_CUBEMAP");
                Shader.DisableKeyword("_REFLECTION_PROBES");
                Shader.DisableKeyword("_REFLECTION_PLANARREFLECTION");
                Shader.SetGlobalTexture("_CubemapTexture", settingsData.cubemapRefType);
                break;

            case ReflectionType.ReflectionProbe:
                Shader.DisableKeyword("_REFLECTION_CUBEMAP");
                Shader.EnableKeyword("_REFLECTION_PROBES");
                Shader.DisableKeyword("_REFLECTION_PLANARREFLECTION");
                break;

            case ReflectionType.PlanarReflection:
                Shader.DisableKeyword("_REFLECTION_CUBEMAP");
                Shader.DisableKeyword("_REFLECTION_PROBES");
                Shader.EnableKeyword("_REFLECTION_PLANARREFLECTION");
                break;
            }

            Shader.SetGlobalInt("_WaveCount", _waves.Length);

            //GPU side
            if (useComputeBuffer)
            {
                Shader.EnableKeyword("USE_STRUCTURED_BUFFER");
                if (_waveBuffer == null)
                {
                    _waveBuffer = new ComputeBuffer(10, (sizeof(float) * 6));
                }
                _waveBuffer.SetData(_waves);
                Shader.SetGlobalBuffer("_WaveDataBuffer", _waveBuffer);
            }
            else
            {
                Shader.DisableKeyword("USE_STRUCTURED_BUFFER");
                Shader.SetGlobalVectorArray("waveData", GetWaveData());
            }
            //CPU side
            if (GerstnerWavesJobs.init == false && Application.isPlaying)
            {
                GerstnerWavesJobs.Init();
            }
        }