Ejemplo n.º 1
0
        protected virtual void LateUpdate()
        {
            // Write lights and shadows
            SgtHelper.SetTempMaterial(material);

            var mask   = 1 << gameObject.layer;
            var lights = SgtLight.Find(lit, mask, transform.position);

            SgtShadow.Find(lit, mask, lights);
            SgtShadow.FilterOutRing(transform.position);
            SgtShadow.Write(lit, 2);

            SgtLight.FilterOut(transform.position);
            SgtLight.Write(lit, transform.position, null, null, scatteringStrength, 2);

            // Update scrolling?
            if (detail == true)
            {
                if (Application.isPlaying == true)
                {
                    detailOffset += detailSpeed * Time.deltaTime;
                }

                if (material != null)
                {
                    material.SetVector(SgtShader._DetailOffset, detailOffset);
                }
            }
        }
Ejemplo n.º 2
0
        private void CameraPreRender(Camera camera)
        {
            if (model != null)
            {
                model.Restore(camera);
            }

            // Write these once to save CPU
            if (renderedThisFrame == false)
            {
                renderedThisFrame = true;

                // Write lights and shadows
                SgtHelper.SetTempMaterial(material);

                var mask   = 1 << gameObject.layer;
                var lights = SgtLight.Find(Lit, mask);

                SgtShadow.Find(Lit, mask, lights);
                SgtShadow.FilterOutSphere(transform.position);
                SgtShadow.Write(Lit, 2);

                SgtLight.FilterOut(transform.position);
                SgtLight.Write(Lit, transform.position, null, null, 1.0f, 2);
            }
        }
Ejemplo n.º 3
0
        protected virtual void LateUpdate()
        {
            if (dirtyMaterial == true)
            {
                UpdateMaterial(); dirtyMaterial = false;
            }

            // Write lights and shadows
            SgtHelper.SetTempMaterial(material);

            var mask   = 1 << gameObject.layer;
            var lights = SgtLight.Find(lit, mask, transform.position);

            SgtLight.FilterOut(transform.position);

            SgtShadow.Find(lit, mask, lights);
            SgtShadow.FilterOutSphere(transform.position);
            SgtShadow.Write(lit, 2);

            SgtLight.Write(lit, transform.position, transform, null, scatteringStrength, 2);

            // Write matrices
            var scale        = radius;
            var localToWorld = transform.localToWorldMatrix * Matrix4x4.Scale(new Vector3(scale, scale, scale));             // Double mesh radius so the max thickness caps at 1.0

            material.SetMatrix(SgtShader._WorldToLocal, localToWorld.inverse);
            material.SetMatrix(SgtShader._LocalToWorld, localToWorld);
        }
Ejemplo n.º 4
0
        protected virtual void LateUpdate()
        {
            if (generatedMesh == null || dirtyMesh == true)
            {
                Rebuild();
            }

            if (generatedMesh != null && material != null)
            {
                Properties.SetFloat(SgtShader._WaterLevel, waterLevel);

                // Write direction of nearest light?
                if (material.GetFloat("_HasNight") == 1.0f)
                {
                    var mask   = 1 << gameObject.layer;
                    var lights = SgtLight.Find(true, mask, transform.position);

                    SgtLight.FilterOut(transform.position);

                    if (lights.Count > 0)
                    {
                        var position  = Vector3.zero;
                        var direction = Vector3.forward;
                        var color     = Color.white;

                        SgtLight.Calculate(lights[0], transform.position, default(Transform), default(Transform), ref position, ref direction, ref color);

                        properties.SetVector(Shader.PropertyToID("_NightDirection"), -direction);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void CameraPreRender(Camera camera)
        {
            if (model != null)
            {
                model.Restore(camera);
            }

            // Write camera-dependant shader values
            if (innerMaterial != null && outerMaterial != null)
            {
                var localPosition  = cachedTransform.InverseTransformPoint(camera.transform.position);
                var localDistance  = localPosition.magnitude;
                var height01       = Mathf.InverseLerp(OuterRadius, InnerMeshRadius, localDistance);
                var innerThickness = default(float);
                var outerThickness = default(float);
                var innerRatio     = SgtHelper.Divide(InnerMeshRadius, OuterRadius);
                var middleRatio    = Mathf.Lerp(innerRatio, 1.0f, Middle);
                var distance       = SgtHelper.Divide(localDistance, OuterRadius);
                var innerDensity   = 1.0f - InnerFog;
                var outerDensity   = 1.0f - OuterFog;

                SgtHelper.CalculateHorizonThickness(innerRatio, middleRatio, distance, out innerThickness, out outerThickness);

                innerMaterial.SetFloat(SgtShader._HorizonLengthRecip, SgtHelper.Reciprocal(innerThickness * innerDensity));
                outerMaterial.SetFloat(SgtShader._HorizonLengthRecip, SgtHelper.Reciprocal(outerThickness * outerDensity));

                if (OuterDepthTex != null)
                {
#if UNITY_EDITOR
                    SgtHelper.MakeTextureReadable(OuterDepthTex);
#endif
                    outerMaterial.SetFloat(SgtShader._Sky, GetSky(camera) * OuterDepthTex.GetPixelBilinear(height01 / outerDensity, 0.0f).a);
                }

                var scale        = SgtHelper.Divide(OuterMeshRadius, OuterRadius);
                var worldToLocal = Matrix4x4.Scale(new Vector3(scale, scale, scale)) * cachedTransform.worldToLocalMatrix;                 // cachedTransform might not be set here, so use the property

                innerMaterial.SetMatrix(SgtShader._WorldToLocal, worldToLocal);
                outerMaterial.SetMatrix(SgtShader._WorldToLocal, worldToLocal);

                // Write lights and shadows
                SgtHelper.SetTempMaterial(innerMaterial, outerMaterial);

                var mask   = 1 << gameObject.layer;
                var lights = SgtLight.Find(Lit, mask);

                SgtShadow.Find(Lit, mask, lights);
                SgtShadow.FilterOutSphere(transform.position);
                SgtShadow.Write(Lit, 2);

                SgtLight.FilterOut(transform.position);
                SgtLight.Write(Lit, transform.position, cachedTransform, null, ScatteringStrength, 2);
            }
        }
Ejemplo n.º 6
0
        protected virtual void LateUpdate()
        {
            // Write lights and shadows
            SgtHelper.SetTempMaterial(generatedMaterial);

            var mask   = 1 << gameObject.layer;
            var lights = SgtLight.Find(lit, mask, cachedTransform.position);

            SgtShadow.Find(lit, mask, lights);
            SgtShadow.FilterOutSphere(cachedTransform.position);
            SgtShadow.Write(lit, 2);

            SgtLight.FilterOut(cachedTransform.position);
            SgtLight.Write(lit, cachedTransform.position, null, null, 1.0f, 2);
        }
Ejemplo n.º 7
0
        private void CameraPreRender(Camera camera)
        {
            if (material != null)
            {
                var cameraPosition      = camera.transform.position;
                var localCameraPosition = transform.InverseTransformPoint(cameraPosition);
                var localDistance       = localCameraPosition.magnitude;
                var scaleDistance       = SgtHelper.Divide(localDistance, Radius);

                if (DepthTex != null)
                {
#if UNITY_EDITOR
                    SgtHelper.MakeTextureReadable(DepthTex);
#endif
                    material.SetFloat(SgtShader._Sky, Sky * DepthTex.GetPixelBilinear(1.0f - scaleDistance, 0.0f).a);
                }

                // Write these once to save CPU
                if (renderedThisFrame == false)
                {
                    renderedThisFrame = true;

                    // Write lights and shadows
                    SgtHelper.SetTempMaterial(material);

                    var mask   = 1 << gameObject.layer;
                    var lights = SgtLight.Find(Lit, mask, transform.position);

                    SgtLight.FilterOut(transform.position);

                    SgtShadow.Find(Lit, mask, lights);
                    SgtShadow.FilterOutSphere(transform.position);
                    SgtShadow.Write(Lit, 2);

                    SgtLight.Write(Lit, transform.position, transform, null, ScatteringStrength, 2);

                    // Write matrices
                    var scale        = Radius;
                    var localToWorld = transform.localToWorldMatrix * Matrix4x4.Scale(new Vector3(scale, scale, scale));                     // Double mesh radius so the max thickness caps at 1.0

                    material.SetMatrix(SgtShader._WorldToLocal, localToWorld.inverse);
                    material.SetMatrix(SgtShader._LocalToWorld, localToWorld);
                }
            }
        }
Ejemplo n.º 8
0
        private void CameraPreRender(Camera camera)
        {
            // Write these once to save CPU
            if (renderedThisFrame == false && material != null)
            {
                renderedThisFrame = true;

                // Write lights and shadows
                SgtHelper.SetTempMaterial(material);

                var mask   = 1 << gameObject.layer;
                var lights = SgtLight.Find(Lit, mask);

                SgtShadow.Find(Lit, mask, lights);
                SgtShadow.FilterOutRing(transform.position);
                SgtShadow.Write(Lit, mask, 2);

                SgtLight.FilterOut(transform.position);
                SgtLight.Write(Lit, transform.position, null, null, ScatteringStrength, 2);
            }
        }
Ejemplo n.º 9
0
        protected virtual void LateUpdate()
        {
            var scale        = SgtHelper.Divide(outerMeshRadius, OuterRadius);
            var worldToLocal = Matrix4x4.Scale(new Vector3(scale, scale, scale)) * cachedTransform.worldToLocalMatrix;

            innerMaterial.SetMatrix(SgtShader._WorldToLocal, worldToLocal);
            outerMaterial.SetMatrix(SgtShader._WorldToLocal, worldToLocal);

            // Write lights and shadows
            SgtHelper.SetTempMaterial(innerMaterial, outerMaterial);

            var mask   = 1 << gameObject.layer;
            var lights = SgtLight.Find(lit, mask, cachedTransform.position);

            SgtShadow.Find(lit, mask, lights);
            SgtShadow.FilterOutSphere(cachedTransform.position);
            SgtShadow.Write(lit, 2);

            SgtLight.FilterOut(cachedTransform.position);
            SgtLight.Write(lit, cachedTransform.position, cachedTransform, null, scatteringStrength, 2);
        }