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); } }
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); } } }
protected void CameraPreRender(Camera camera) { if (material != null) { var observer = default(SgtCamera); if (SgtCamera.TryFind(camera, ref observer) == true) { material.SetFloat(SgtShader._CameraRollAngle, observer.RollAngle * Mathf.Deg2Rad); } else { material.SetFloat(SgtShader._CameraRollAngle, 0.0f); } // 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.FilterOutRing(transform.position); SgtShadow.Write(Lit, 2); SgtLight.Write(Lit, transform.position, transform, null, 1.0f, 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); }
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); } }
protected virtual void CameraPreRender(Camera camera) { if (material != null) { SgtHelper.SetTempMaterial(material); var mask = 1 << gameObject.layer; var lights = SgtLight.Find(true, mask, transform.position); SgtShadow.Find(true, mask, lights); SgtShadow.FilterOutSphere(transform.position); SgtShadow.FilterOutMiss(transform.position, SgtHelper.UniformScale(transform.lossyScale) * Radius); SgtShadow.Write(true, 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); }
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); }
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); }