public void SetupWaves(bool custom) { if (!custom) { //create basic waves based off basic wave settings Random.State backupSeed = Random.state; Random.InitState(surfaceData.randomSeed); BasicWaves basicWaves = surfaceData._basicWaveSettings; float a = basicWaves.amplitude; float d = basicWaves.direction; float l = basicWaves.wavelength; int numWave = basicWaves.numWaves; _waves = new Wave[numWave]; float r = 1f / numWave; for (int i = 0; i < numWave; i++) { float p = Mathf.Lerp(0.5f, 1.5f, (float)i * r); float amp = a * p * Random.Range(0.8f, 1.2f); float dir = d + Random.Range(-45f, 45f); float len = l * p * Random.Range(0.6f, 1.4f); _waves[i] = new Wave(amp, dir, len, Vector2.zero, false); Random.InitState(surfaceData.randomSeed + i + 1); } Random.state = backupSeed; } else { _waves = surfaceData._waves.ToArray(); } }
public override void CommonRender(LightweightRenderPipeline pipelineInstance, ScriptableRenderContext context, Camera cameraSrp) { #endif if (!MapsAreAssigned()) { return; } var roll = cameraSrp.transform.localEulerAngles.z; Shader.SetGlobalFloat(CameraRoll, roll); Shader.SetGlobalMatrix(InvViewProjection, (GL.GetGPUProjectionMatrix(cameraSrp.projectionMatrix, false) * cameraSrp.worldToCameraMatrix).inverse); //// Water matrix //const float quantizeValue = 6.25f; //const float forwards = 10f; //const float yOffset = -0.25f; //var newPos = cameraSrp.transform.TransformPoint(Vector3.forward * forwards); //newPos.y = yOffset; //newPos.x = quantizeValue * (int)(newPos.x / quantizeValue); //newPos.z = quantizeValue * (int)(newPos.z / quantizeValue); //var matrix = Matrix4x4.TRS(newPos + transform.position, Quaternion.identity, Vector3.one); // transform.localToWorldMatrix; //Debug.Log("draw mesh"); //foreach (var mesh in defaultWaterMeshes) //{ // Graphics.DrawMesh(mesh, // matrix, // defaultSeaMaterial, // gameObject.layer, // cameraSrp, // 0, // null, // ShadowCastingMode.Off, // true, // null, // LightProbeUsage.Off, // null); //} //reinitalize the waves etc. if any value changes if (_waterDepthVisibility != WaterDepthVisibility || !_absorptionRamp.Equals(AbsorptionRamp) || !_scatterRamp.Equals(ScatterRamp) || _basicWaveSettings.amplitude != BasicWaveSettings.amplitude || _basicWaveSettings.direction != BasicWaveSettings.direction || _basicWaveSettings.numWaves != BasicWaveSettings.numWaves || _basicWaveSettings.wavelength != BasicWaveSettings.wavelength) { Debug.Log("Water waves init called again..."); _waterDepthVisibility = WaterDepthVisibility; _absorptionRamp = new Gradient { alphaKeys = AbsorptionRamp.alphaKeys, colorKeys = AbsorptionRamp.colorKeys, mode = AbsorptionRamp.mode }; _scatterRamp = new Gradient { alphaKeys = ScatterRamp.alphaKeys, colorKeys = ScatterRamp.colorKeys, mode = ScatterRamp.mode }; _basicWaveSettings = new BasicWaves(BasicWaveSettings.amplitude, BasicWaveSettings.direction, BasicWaveSettings.wavelength); _basicWaveSettings.numWaves = BasicWaveSettings.numWaves; Init(); } foreach (var shade in Shades) { if (shade.MaterialToChange.HasProperty("_BumpScale")) { shade.MaterialToChange.SetFloat("_BumpScale", WaveDetail); } if (shade.MaterialToChange.HasProperty("_WaveRefraction")) { shade.MaterialToChange.SetFloat("_WaveRefraction", WaveRefraction); } if (WaterShadow) { shade.MaterialToChange.DisableKeyword("_RECEIVE_SHADOWS_OFF"); } else { shade.MaterialToChange.EnableKeyword("_RECEIVE_SHADOWS_OFF"); } if (UseCustomDepth) { shade.MaterialToChange.EnableKeyword("DO_NOT_USE_DEPTH"); } else { shade.MaterialToChange.DisableKeyword("DO_NOT_USE_DEPTH"); } //if (shade.MaterialToChange.HasProperty("_ManualDistanceSurface")) // shade.MaterialToChange.SetFloat("_ManualDistanceSurface", ManualDistanceForSurface); //if (shade.MaterialToChange.HasProperty("_ManualDistanceDepth")) // shade.MaterialToChange.SetFloat("_ManualDistanceDepth", ManualDistanceForDepth); } }