Exemple #1
0
        protected void CameraPreRender(Camera camera)
        {
            if (material != null)
            {
                var observer = default(SgtCamera);

                if (SgtCamera.TryFind(camera, ref observer) == true)
                {
                    material.SetFloat("_CameraRollAngle", observer.RollAngle * Mathf.Deg2Rad);
                }
                else
                {
                    material.SetFloat("_CameraRollAngle", 0.0f);
                }

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

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

                    SgtLight.Write(Lit, transform.position, transform, null, 1.0f, 2);
                    SgtShadow.Write(Lit, gameObject, 2);
                }
            }
        }
        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);
        }
Exemple #3
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);
            }
        }
Exemple #4
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);
                }
            }
        }
Exemple #5
0
        private void CameraPreCull(Camera camera)
        {
            // Write these once to save CPU
            if (renderedThisFrame == false && material != null)
            {
                renderedThisFrame = true;

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

                SgtLight.Write(Lit, transform.position, null, null, 1.0f, 1);
                SgtShadow.Write(Lit, gameObject, 1);
            }

            if (CameraOffset != 0.0f)
            {
                if (model != null)
                {
                    model.Revert();
                    {
                        if (CameraOffset != 0.0f)
                        {
                            var direction = transform.position - camera.transform.position;

                            model.transform.position += direction.normalized * CameraOffset;
                        }
                    }
                    model.Save(camera);
                }
            }
        }
Exemple #6
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);
            }
        }
Exemple #7
0
        protected virtual void LateUpdate()
        {
            // The lights and shadows may have moved, so write them
            if (innerMaterial != null && outerMaterial != null)
            {
                SgtHelper.SetTempMaterial(innerMaterial, outerMaterial);

                SgtLight.Write(Lit, transform.position, transform, null, ScatteringStrength, 2);
                SgtShadow.Write(Lit, gameObject, 2);
            }
        }
Exemple #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);

                SgtLight.Write(Lit, transform.position, null, null, ScatteringStrength, 2);
                SgtShadow.Write(Lit, gameObject, 2);
            }
        }
        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);
        }
Exemple #10
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 (scaleDistance > 1.0f)
                {
                    SgtHelper.EnableKeyword("SGT_A", material);                     // Outside
                }
                else
                {
                    SgtHelper.DisableKeyword("SGT_A", material);                     // Outside

                    if (DepthTex != null)
                    {
#if UNITY_EDITOR
                        SgtHelper.MakeTextureReadable(DepthTex);
#endif
                        material.SetFloat("_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);

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

                    // Write matrices
                    var localToWorld = transform.localToWorldMatrix * SgtHelper.Scaling(Radius * 2.0f);                     // Double mesh radius so the max thickness caps at 1.0

                    material.SetMatrix("_WorldToLocal", localToWorld.inverse);

                    material.SetMatrix("_LocalToWorld", localToWorld);
                }
            }
        }
        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);
                }
            }
        }
        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);
            }
        }
        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);
        }
Exemple #14
0
        protected override void LateUpdate()
        {
            base.LateUpdate();

            if (Application.isPlaying == true)
            {
                orbitOffset += Time.deltaTime * orbitSpeed;
            }

            material.SetFloat(SgtShader._Age, orbitOffset);

            // 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.Write(lit, transform.position, transform, null, 1.0f, 2);
        }