Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        // 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;
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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++;
                }
            }
        }