private void Start() { _guid = GerstnerWavesJobs.GenId(); _rend = GetComponent <Renderer>(); GetComponent <MeshFilter>().mesh = Mesh2DGrid(0, 2, -0.5f, -0.5f, 1f, 1f, GEOM_HORIZ_DIVISIONS, 1); }
private int _guid; // GUID for the height system public void Start() { m_buoyancy = GetComponentsInChildren <FBuoyancyPart>(); body = GetComponent <Rigidbody>(); heights = new float3[m_buoyancy.Length]; // new NativeSlice<float3>(); normals = new float3[m_buoyancy.Length]; //new NativeSlice<float3>(); samplePoints = new float3[m_buoyancy.Length]; _guid = GerstnerWavesJobs.GenId(); }
public void ExecuteCheckUnder(ScriptableRenderContext context, Camera camera) { if (_rend == null) { return; } Matrix4x4 invviewproj = (camera.projectionMatrix * camera.worldToCameraMatrix).inverse; fofrustum[0] = invviewproj.MultiplyPoint(new Vector3(-1, -1, -1)); fofrustum[1] = invviewproj.MultiplyPoint(new Vector3(+1, -1, -1)); fofrustum[2] = invviewproj.MultiplyPoint(new Vector3(-1, +1, -1)); fofrustum[3] = invviewproj.MultiplyPoint(new Vector3(+1, +1, -1)); fofrustum[4] = camera.transform.position; GerstnerWavesJobs.UpdateSamplePoints(fofrustum, _guid); GerstnerWavesJobs.GetData(_guid, ref heights); _rend.enabled = false; int i = 0; for (; i < 5; i++) { Vector3 contactP = heights[i] + new float3(fofrustum[i].x, NeoOcean.oceanheight, fofrustum[i].z); if (contactP.y - fofrustum[i].y > 0) { // Disable skirt when camera not close to water. In the first few frames collision may not be avail, in that case no choice // but to assume enabled. In the future this could detect if camera is far enough under water, render a simple quad to avoid // finding the intersection line. _rend.enabled = true; break; } } bool bAll = false; if (i == 5) { bAll = true; } if (_rend.enabled) { //avoid culling this.transform.position = camera.transform.position + camera.transform.forward; _rend.sharedMaterial.SetFloat("_OceanHeight", NeoOcean.oceanheight); _rend.sharedMaterial.SetFloat("_HeightOffset", bAll ? -2 : 0); } }
void OnDisable() { GerstnerWavesJobs.Cleanup(); if (reflection) { reflection.enabled = false; } if (instance == this) { instance = null; } }
void LateUpdate() { GerstnerWavesJobs.UpdateHeights(); if (!CheckInstance(false)) { return; } var _e = grids.GetEnumerator(); while (_e.MoveNext()) { _e.Current.SetupMaterial(); } }
private void UpdateMainGrid() { if (!mainPGrid) { return; } UpdateMaterial(mainPGrid.oceanMaterial); //GPU side Shader.SetGlobalVectorArray("waveData", GetWaveData()); Shader.SetGlobalFloat("_WaveTime", gTime); //CPU side GerstnerWavesJobs.Init(); CheckDepth(mainPGrid); }
public float _speed = 3f; // how long the wake lasts for void OnEnable() { // Initial setup for wakes foreach (Wake w in _wakes) { for (int i = 0; i < 2; i++) { WakeLine wl = new WakeLine(); GameObject go = GameObject.Instantiate(_wakePrefab, Vector3.zero, Quaternion.Euler(90f, 0, 0)); LineRenderer LR = go.GetComponent <LineRenderer>(); wl.points = new List <WakePoint>(); wl._lineRenderer = LR; wl.guid = GerstnerWavesJobs.GenId(); wl.go = go; w.lines.Add(wl); go.hideFlags = HideFlags.HideAndDontSave; } } }
// Update is called once per frame void Update() { var pos = boatTransform.TransformPoint(offset); poses[0] = pos; GerstnerWavesJobs.UpdateSamplePoints(poses, _guid); GerstnerWavesJobs.GetData(_guid, ref heights); pos.y = NeoOcean.oceanheight + heights[0].y; transform.position = pos; var fwd = boatTransform.forward; fwd.y = 0; var angle = Vector3.Angle(fwd.normalized, Vector3.forward); if (ps != null) { module.startRotation = angle * Mathf.Deg2Rad; } }
void LateUpdate() { GerstnerWavesJobs.UpdateHeights(); if (!CheckInstance(false)) { return; } var _e = grids.GetEnumerator(); while (_e.MoveNext()) { float scale = (0.5f * m_worldfftSize); _e.Current.SetupMaterial(m_map0, scale); } if (m_queueNode != null) { if (m_queueNode.Value != null && !m_queueNode.Value.IsCreated()) { if (Application.isPlaying) { ForceReload(true); } m_queueNode = null; return; } m_queueNode = m_queueNode.Next; } else { m_queueNode = m_queueRTs.First; } PhysicsUpdate(); }
void Update() { int count = m_buoyancy.Length; for (int i = 0; i < count; i++) { FBuoyancyPart buoyancy = m_buoyancy[i]; if (buoyancy == null) { continue; } if (!buoyancy.enabled) { continue; } samplePoints[i] = buoyancy.transform.position; } GerstnerWavesJobs.UpdateSamplePoints(samplePoints, _guid); GerstnerWavesJobs.GetData(_guid, ref heights, ref normals); }
void Update() { Vector3 origin; //For each wake pair var wCount = _wakes.Count; for (int w = 0; w < wCount; w++) { Wake _wake = _wakes[w]; int s = 0; for (int x = -1; x <= 1; x += 2) { origin = _wake.origin; origin.x *= x; origin = transform.TransformPoint(origin); origin.y = 0;//flatten origin in world WakeLine line = _wake.lines[s]; var pointCount = line.points.Count; //////////////////////////// create points, if needed /////////////////////////////// if (pointCount == 0) { line.points.Insert(0, CreateWakePoint(origin, x)); pointCount++; } else if (Vector3.Distance(line.points[0].pos, origin) > _genDistance) { line.points.Insert(0, CreateWakePoint(origin, x)); pointCount++; } ///////////////////////////// kill points, if needed //////////////////////////////// for (int i = line.points.Count - 1; i >= 0; i--) { if (line.points[i].age > _maxAge) { line.points.RemoveAt(i); pointCount--; } else { line.points[i].age += Time.deltaTime; // increment age line.points[i].pos += line.points[i].dir * _speed * Time.deltaTime; // move points by dir } } ///////////////////// Create the line renderer points /////////////////////////////// line._lineRenderer.positionCount = pointCount + 1; line.poses[0] = origin; for (var i = 0; i < pointCount; i++) { if (i + 1 == line.poses.Length) { break; } line.poses[i + 1] = line.points[i].pos; } GerstnerWavesJobs.UpdateSamplePoints(line.poses, line.guid); GerstnerWavesJobs.GetData(line.guid, ref line.heights); origin.y = NeoOcean.oceanheight + line.heights[0].y; for (var i = 0; i < pointCount; i++) { if (i + 1 == line.poses.Length) { break; } line.points[i].pos.y = NeoOcean.oceanheight + line.heights[i + 1].y; } line._lineRenderer.SetPosition(0, origin); for (var i = 0; i < pointCount; i++) { line._lineRenderer.SetPosition(i + 1, line.points[i].pos); } s++; } } }
private void Start() { _guid = GerstnerWavesJobs.GenId(); module = ps.main; offset = transform.localPosition; }