private void CameraPreRender(Camera camera) { // Write CameraOffset if (Outers != null) { var dir = camera.transform.position - transform.position; var pos = transform.InverseTransformPoint(transform.position + dir.normalized * CameraOffset); for (var i = Outers.Count - 1; i >= 0; i--) { var outer = Outers[i]; if (outer != null) { outer.transform.localPosition = pos; } } } // Write camera-dependant shader values if (InnerMaterial != null && OuterMaterial != null) { var cameraPosition = camera.transform.position; var localCameraPosition = transform.InverseTransformPoint(cameraPosition); var localDistance = localCameraPosition.magnitude; var clampedSky = Mathf.InverseLerp(OuterRadius, InnerMeshRadius, localDistance); var innerAtmosphereDepth = default(float); var outerAtmosphereDepth = default(float); var radiusRatio = SgtHelper.Divide(InnerMeshRadius, OuterRadius); var scaleDistance = SgtHelper.Divide(localDistance, OuterRadius); var innerDensity = 1.0f - InnerFog; var outerDensity = 1.0f - OuterFog; SgtHelper.CalculateAtmosphereThicknessAtHorizon(radiusRatio, 1.0f, scaleDistance, out innerAtmosphereDepth, out outerAtmosphereDepth); SgtHelper.SetTempMaterial(InnerMaterial, OuterMaterial); if (scaleDistance > 1.0f) { SgtHelper.EnableKeyword("SGT_A"); // Outside } else { SgtHelper.DisableKeyword("SGT_A"); // Outside } InnerMaterial.SetFloat("_HorizonLengthRecip", SgtHelper.Reciprocal(innerAtmosphereDepth * innerDensity)); OuterMaterial.SetFloat("_HorizonLengthRecip", SgtHelper.Reciprocal(outerAtmosphereDepth * outerDensity)); if (OuterDepthTex != null) { #if UNITY_EDITOR SgtHelper.MakeTextureReadable(OuterDepthTex); #endif OuterMaterial.SetFloat("_Sky", Sky * OuterDepthTex.GetPixelBilinear(clampedSky / outerDensity, 0.0f).a); } UpdateMaterialNonSerialized(); } }
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, MeshRadius); 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); } } UpdateMaterialNonSerialized(); } }
public void UpdateMaterial() { updateMaterialCalled = true; if (Material == null) { Material = SgtHelper.CreateTempMaterial("Prominence (Generated)", SgtHelper.ShaderNamePrefix + "Prominence"); if (Planes != null) { for (var i = Planes.Count - 1; i >= 0; i--) { var plane = Planes[i]; if (plane != null) { plane.SetMaterial(Material); } } } } var color = SgtHelper.Premultiply(SgtHelper.Brighten(Color, Brightness)); var renderQueue = (int)RenderQueue + RenderQueueOffset; if (Material.renderQueue != renderQueue) { Material.renderQueue = renderQueue; } Material.SetTexture("_MainTex", MainTex); Material.SetColor("_Color", color); Material.SetVector("_WorldPosition", transform.position); SgtHelper.SetTempMaterial(Material); if (FadeEdge == true) { SgtHelper.EnableKeyword("SGT_A"); Material.SetFloat("_FadePower", FadePower); } else { SgtHelper.DisableKeyword("SGT_A"); } if (ClipNear == true) { SgtHelper.EnableKeyword("SGT_B"); Material.SetFloat("_ClipPower", ClipPower); } else { SgtHelper.DisableKeyword("SGT_B"); } }
public void UpdateMaterial() { updateMaterialCalled = true; if (Material == null) { Material = SgtHelper.CreateTempMaterial("Spacetime (Generated)", SgtHelper.ShaderNamePrefix + "Spacetime"); ApplyMaterial(); } var ambientColor = SgtHelper.Brighten(AmbientColor, AmbientBrightness); var displacementColor = SgtHelper.Brighten(DisplacementColor, DisplacementBrightness); var higlightColor = SgtHelper.Brighten(HighlightColor, HighlightBrightness); Material.renderQueue = (int)RenderQueue + RenderQueueOffset; Material.SetTexture("_MainTex", MainTex); Material.SetColor("_Color", SgtHelper.Brighten(Color, Brightness)); Material.SetColor("_AmbientColor", ambientColor); Material.SetColor("_DisplacementColor", displacementColor); Material.SetColor("_HighlightColor", higlightColor); Material.SetFloat("_HighlightPower", HighlightPower); Material.SetFloat("_HighlightScale", HighlightScale); Material.SetFloat("_Tile", Tile); if (Displacement == DisplacementType.Pinch) { Material.SetFloat("_Power", Power); } if (Displacement == DisplacementType.Offset) { SgtHelper.EnableKeyword("SGT_A", Material); Material.SetVector("_Offset", Offset); } else { SgtHelper.DisableKeyword("SGT_A", Material); } if (Accumulate == true) { SgtHelper.EnableKeyword("SGT_B", Material); } else { SgtHelper.DisableKeyword("SGT_B", Material); } }
public void UpdateMaterial() { updateMaterialCalled = true; if (Material == null) { Material = SgtHelper.CreateTempMaterial("Cloudsphere (Generated)", SgtHelper.ShaderNamePrefix + "Cloudsphere"); if (Models != null) { for (var i = Models.Count - 1; i >= 0; i--) { var model = Models[i]; if (model != null) { model.SetMaterial(Material); } } } } var renderQueue = (int)RenderQueue + RenderQueueOffset; var color = SgtHelper.Brighten(Color, Brightness); Material.renderQueue = renderQueue; Material.SetColor("_Color", color); Material.SetTexture("_MainTex", MainTex); Material.SetTexture("_DepthTex", DepthTex); if (Fade == true) { SgtHelper.EnableKeyword("SGT_A", Material); // Fade Material.SetTexture("_FadeTex", FadeTex); Material.SetFloat("_FadeDistanceRecip", SgtHelper.Reciprocal(FadeDistance)); } else { SgtHelper.DisableKeyword("SGT_A", Material); // Fade } if (Lit == true) { Material.SetTexture("_LightingTex", LightingTex); } }
public void UpdateMaterial() { if (Material == null) { Material = SgtHelper.CreateTempMaterial("Jovian Material (Generated)", SgtHelper.ShaderNamePrefix + "Jovian"); if (Models != null) { for (var i = Models.Count - 1; i >= 0; i--) { var model = Models[i]; if (model != null) { model.SetMaterial(Material); } } } } Material.renderQueue = (int)RenderQueue + RenderQueueOffset; Material.SetTexture("_MainTex", MainTex); Material.SetTexture("_DepthTex", DepthTex); Material.SetColor("_Color", SgtHelper.Brighten(Color, Brightness)); if (Lit == true) { Material.SetTexture("_LightingTex", LightingTex); } SgtHelper.SetTempMaterial(Material); if (Scattering == true) { Material.SetTexture("_ScatteringTex", ScatteringTex); SgtHelper.EnableKeyword("SGT_B"); // Scattering } else { SgtHelper.DisableKeyword("SGT_B"); // Scattering } UpdateMaterialNonSerialized(); }
public void UpdateMaterial() { updateMaterialCalled = true; if (Material == null) { Material = SgtHelper.CreateTempMaterial("Singulairty (Generated)", SgtHelper.ShaderNamePrefix + "Singularity"); if (Models != null) { for (var i = Models.Count - 1; i >= 0; i--) { var model = Models[i]; if (model != null) { model.SetMaterial(Material); } } } } Material.renderQueue = (int)RenderQueue + RenderQueueOffset; Material.SetVector("_Center", SgtHelper.NewVector4(transform.position, 1.0f)); Material.SetFloat("_PinchPower", PinchPower); Material.SetFloat("_PinchScale", SgtHelper.Reciprocal(1.0f - PinchOffset)); Material.SetFloat("_PinchOffset", PinchOffset); Material.SetFloat("_HolePower", HolePower); Material.SetColor("_HoleColor", HoleColor); SgtHelper.SetTempMaterial(Material); if (Tint == true) { SgtHelper.EnableKeyword("SGT_A"); // Tint Material.SetFloat("_TintPower", TintPower); Material.SetColor("_TintColor", TintColor); } else { SgtHelper.DisableKeyword("SGT_A"); // Tint } if (EdgeFade == EdgeFadeType.Center) { SgtHelper.EnableKeyword("SGT_B"); // Fade Center Material.SetFloat("_EdgeFadePower", EdgeFadePower); } else { SgtHelper.DisableKeyword("SGT_B"); // Fade Center } if (EdgeFade == EdgeFadeType.Fragment) { SgtHelper.EnableKeyword("SGT_C"); // Fade Fragment Material.SetFloat("_EdgeFadePower", EdgeFadePower); } else { SgtHelper.DisableKeyword("SGT_C"); // Fade Fragment } }
public void UpdateWells() { if (Material != null) { var gaussianCount = 0; var rippleCount = 0; var twistCount = 0; WriteWells(ref gaussianCount, ref rippleCount, ref twistCount); // 12 is the shader instruction limit if ((gaussianCount & 1 << 0) != 0) { SgtHelper.EnableKeyword("SGT_C", Material); } else { SgtHelper.DisableKeyword("SGT_C", Material); } if ((gaussianCount & 1 << 1) != 0) { SgtHelper.EnableKeyword("SGT_D", Material); } else { SgtHelper.DisableKeyword("SGT_D", Material); } if ((gaussianCount & 1 << 2) != 0) { SgtHelper.EnableKeyword("SGT_E", Material); } else { SgtHelper.DisableKeyword("SGT_E", Material); } if ((gaussianCount & 1 << 3) != 0) { SgtHelper.EnableKeyword("LIGHT_0", Material); } else { SgtHelper.DisableKeyword("LIGHT_0", Material); } if ((rippleCount & 1 << 0) != 0) { SgtHelper.EnableKeyword("LIGHT_1", Material); } else { SgtHelper.DisableKeyword("LIGHT_1", Material); } if ((twistCount & 1 << 0) != 0) { SgtHelper.EnableKeyword("SHADOW_1", Material); } else { SgtHelper.DisableKeyword("SHADOW_1", Material); } } }
public virtual void UpdateMaterial() { updateMaterialCalled = true; if (Material == null) { Material = SgtHelper.CreateTempMaterial("Ring (Generated)", ShaderName); if (Models != null) { for (var i = Models.Count - 1; i >= 0; i--) { var model = Models[i]; if (model != null) { model.SetMaterial(Material); } } } } var color = SgtHelper.Brighten(Color, Brightness); var renderQueue = (int)RenderQueue + RenderQueueOffset; Material.renderQueue = renderQueue; Material.SetColor("_Color", color); Material.SetTexture("_MainTex", MainTex); if (Detail == true) { SgtHelper.EnableKeyword("SGT_B", Material); // Detail Material.SetTexture("_DetailTex", DetailTex); Material.SetVector("_DetailScale", new Vector2(DetailScaleX, DetailScaleY)); Material.SetFloat("_DetailTwist", DetailTwist); Material.SetFloat("_DetailTwistBias", DetailTwistBias); } else { SgtHelper.DisableKeyword("SGT_B", Material); // Detail } if (Fade == true) { SgtHelper.EnableKeyword("SGT_C", Material); // Fade Material.SetTexture("_FadeTex", FadeTex); Material.SetFloat("_FadeDistanceRecip", SgtHelper.Reciprocal(FadeDistance)); } else { SgtHelper.DisableKeyword("SGT_C", Material); // Fade } if (Lit == true) { Material.SetTexture("_LightingTex", LightingTex); } if (Scattering == true) { SgtHelper.EnableKeyword("SGT_A", Material); // Scattering Material.SetFloat("_ScatteringMie", ScatteringMie * ScatteringMie); } else { SgtHelper.DisableKeyword("SGT_A", Material); // Scattering } UpdateMaterialNonSerialized(); }
public void UpdateMaterial() { updateMaterialCalled = true; if (Material == null) { Material = SgtHelper.CreateTempMaterial("Aurora (Generated)", SgtHelper.ShaderNamePrefix + "Aurora"); if (Models != null) { for (var i = Models.Count - 1; i >= 0; i--) { var model = Models[i]; if (model != null) { model.SetMaterial(Material); } } } } var color = SgtHelper.Premultiply(SgtHelper.Brighten(Color, Brightness)); var renderQueue = (int)RenderQueue + RenderQueueOffset; if (Material.renderQueue != renderQueue) { Material.renderQueue = renderQueue; } Material.SetColor("_Color", color); Material.SetTexture("_MainTex", MainTex); Material.SetFloat("_RadiusMin", RadiusMin); Material.SetFloat("_RadiusSize", RadiusMax - RadiusMin); SgtHelper.SetTempMaterial(Material); if (FadeNear == true) { SgtHelper.EnableKeyword("SGT_A"); // FadeNear Material.SetTexture("_FadeNearTex", FadeNearTex); Material.SetFloat("_FadeNearRadius", FadeNearRadius); Material.SetFloat("_FadeNearScale", SgtHelper.Reciprocal(FadeNearThickness)); } else { SgtHelper.DisableKeyword("SGT_A"); // FadeNear } if (Anim == true) { SgtHelper.EnableKeyword("SGT_B"); // Anim Material.SetFloat("_AnimOffset", AnimOffset); } else { SgtHelper.DisableKeyword("SGT_B"); // Anim } }
public void UpdateMaterials() { updateMaterialsCalled = true; if (InnerMaterial == null) { InnerMaterial = SgtHelper.CreateTempMaterial("Atmosphere Inner (Generated)", SgtHelper.ShaderNamePrefix + "AtmosphereInner"); if (InnerRenderers != null) { for (var i = InnerRenderers.Count - 1; i >= 0; i--) { var innerRenderer = InnerRenderers[i]; if (innerRenderer != null) { SgtHelper.AddMaterial(innerRenderer, InnerMaterial); } } } UpdateTerrainMaterials(); } if (OuterMaterial == null) { OuterMaterial = SgtHelper.CreateTempMaterial("Atmosphere Outer (Generated)", SgtHelper.ShaderNamePrefix + "AtmosphereOuter"); if (Outers != null) { for (var i = Outers.Count - 1; i >= 0; i--) { var outer = Outers[i]; if (outer != null) { outer.SetMaterial(OuterMaterial); } } } } var color = SgtHelper.Brighten(Color, Brightness); var renderQueue = (int)RenderQueue + RenderQueueOffset; InnerMaterial.renderQueue = renderQueue; OuterMaterial.renderQueue = renderQueue; InnerMaterial.SetColor("_Color", color); OuterMaterial.SetColor("_Color", color); InnerMaterial.SetTexture("_DepthTex", InnerDepthTex); OuterMaterial.SetTexture("_DepthTex", OuterDepthTex); if (Lit == true) { InnerMaterial.SetTexture("_LightingTex", LightingTex); OuterMaterial.SetTexture("_LightingTex", LightingTex); if (Scattering == true) { OuterMaterial.SetTexture("_ScatteringTex", ScatteringTex); OuterMaterial.SetFloat("_ScatteringMie", ScatteringMie); OuterMaterial.SetFloat("_ScatteringRayleigh", ScatteringRayleigh); SgtHelper.EnableKeyword("SGT_B", OuterMaterial); // Scattering if (GroundScattering == true) { InnerMaterial.SetTexture("_ScatteringTex", ScatteringTex); InnerMaterial.SetFloat("_ScatteringMie", ScatteringMie); InnerMaterial.SetFloat("_ScatteringRayleigh", ScatteringRayleigh); SgtHelper.EnableKeyword("SGT_B", InnerMaterial); // Scattering } else { SgtHelper.DisableKeyword("SGT_B", InnerMaterial); // Scattering } } else { SgtHelper.DisableKeyword("SGT_B", InnerMaterial); // Scattering SgtHelper.DisableKeyword("SGT_B", OuterMaterial); // Scattering } } SgtHelper.SetTempMaterial(InnerMaterial, OuterMaterial); UpdateMaterialNonSerialized(); }
protected override void BuildMaterial() { base.BuildMaterial(); if (Wrap == true) { SgtHelper.EnableKeyword("SGT_B", Material); // Wrap Material.SetVector("_WrapSize", WrapSize); Material.SetVector("_WrapSizeRecip", SgtHelper.Reciprocal3(WrapSize)); } else { SgtHelper.DisableKeyword("SGT_B", Material); // Wrap } if (Stretch == true) { SgtHelper.EnableKeyword("SGT_C", Material); // Stretch } else { SgtHelper.DisableKeyword("SGT_C", Material); // Stretch } if (FadeNear == true) { SgtHelper.EnableKeyword("SGT_D", Material); // Fade near Material.SetTexture("_FadeNearTex", FadeNearTex); Material.SetFloat("_FadeNearRadius", FadeNearRadius); Material.SetFloat("_FadeNearScale", SgtHelper.Reciprocal(FadeNearThickness)); } else { SgtHelper.DisableKeyword("SGT_D", Material); // Fade near } if (FadeFar == true) { SgtHelper.EnableKeyword("SGT_E", Material); // Fade far Material.SetTexture("_FadeFarTex", FadeFarTex); Material.SetFloat("_FadeFarRadius", FadeFarRadius); Material.SetFloat("_FadeFarScale", SgtHelper.Reciprocal(FadeFarThickness)); } else { SgtHelper.DisableKeyword("SGT_E", Material); // Fade far } if (Pulse == true) { SgtHelper.EnableKeyword("LIGHT_1", Material); // Pulse // This is also set in Update Material.SetFloat("_PulseOffset", PulseOffset); } else { SgtHelper.DisableKeyword("LIGHT_1", Material); // Pulse } if (Softness > 0.0f) { SgtHelper.EnableKeyword("LIGHT_2", Material); // Softness Material.SetFloat("_InvFade", SgtHelper.Reciprocal(Softness)); } else { SgtHelper.DisableKeyword("LIGHT_2", Material); // Softness } }