private void UpdateMaterial() { var targetCoronaTechnique = "Variant"; if (cullNear == true) { targetCoronaTechnique += "CullNear"; } if (coronaPerPixel == true) { targetCoronaTechnique += "PerPixel"; } if (meshType == Type.Ring) { targetCoronaTechnique += "Ring"; } // Update surface? if (coronaTechnique != targetCoronaTechnique || coronaMaterial == null) { SGT_Helper.DestroyObject(coronaMaterial); coronaTechnique = targetCoronaTechnique; coronaMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Corona/" + coronaTechnique, coronaRenderQueue); } else { SGT_Helper.SetRenderQueue(coronaMaterial, coronaRenderQueue); } }
private void UpdateTechnique() { var targetTechnique = "Variant"; if (shadow == true) { targetTechnique += "Shadow"; } if (spin == true) { targetTechnique += "Spin"; } if (technique != targetTechnique || ringMaterial == null) { SGT_Helper.DestroyObject(ringMaterial); technique = targetTechnique; ringMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/AsteroidRing/" + technique, ringRenderQueue); } else { SGT_Helper.SetRenderQueue(ringMaterial, ringRenderQueue); } }
private void UpdateMaterial() { var targetAtmosphereTechnique = "Variant"; if (gasGiantObserver != null) { if (InsideGasGiant(gasGiantObserver.transform.position) == false) { targetAtmosphereTechnique += "Outer"; } } if (shadow == true) { switch (shadowType) { case SGT_ShadowOccluder.Ring: targetAtmosphereTechnique += "RingShadow"; break; case SGT_ShadowOccluder.Planet: targetAtmosphereTechnique += "PlanetShadow"; break; } } // Update surface? if (atmosphereMaterial == null || atmosphereTechnique != targetAtmosphereTechnique) { SGT_Helper.DestroyObject(atmosphereMaterial); atmosphereTechnique = targetAtmosphereTechnique; atmosphereMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/GasGiant/" + atmosphereTechnique, atmosphereRenderQueue); } else { SGT_Helper.SetRenderQueue(atmosphereMaterial, atmosphereRenderQueue); } }
private void Validate() { if (nebula == null) { nebula = SGT_Helper.CreateGameObject("Nebula", this); } if (nebulaMesh == null) { nebulaMesh = new SGT_Mesh(); } if (nebulaMaterial == null) { nebulaMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Nebula/" + nebulaTechnique); } SGT_Helper.SetParent(nebula, gameObject); SGT_Helper.SetLayer(nebula, gameObject.layer); SGT_Helper.SetTag(nebula, gameObject.tag); var finalColour = SGT_Helper.Premultiply(particleColour); nebulaMaterial.SetColor("particleColour", finalColour); nebulaMaterial.SetTexture("particleTexture", particleTexture); nebulaMaterial.SetFloat("particleFadeInDistance", particleFadeInDistance); SGT_Helper.SetRenderQueue(nebulaMaterial, nebulaRenderQueue); nebulaMesh.GameObject = nebula; nebulaMesh.HasMeshRenderer = true; nebulaMesh.MeshRendererEnabled = SGT_Helper.IsBlack(finalColour) == false; nebulaMesh.SharedMesh = generatedMesh; nebulaMesh.SharedMaterial = nebulaMaterial; nebulaMesh.Update(); }
public void LateUpdate() { Color volumetricColour; if (SGT_GasGiant.ColourToPoint(Camera.main.transform.position, transform.position, 1.0f, false, false, out volumetricColour) == true) { if (probeMaterial == null) { probeMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Fog/Variant", probeRenderQueue); } probeMaterial.SetColor("fogColour", volumetricColour); SGT_Helper.InsertSharedMaterial(GetComponent <Renderer>(), probeMaterial, probeRecursive); SGT_Helper.SetRenderQueue(probeMaterial, probeRenderQueue); } else { if (probeMaterial != null) { SGT_Helper.RemoveSharedMaterial(GetComponent <Renderer>(), probeMaterial, probeRecursive); probeMaterial = SGT_Helper.DestroyObject(probeMaterial); } } }
private void Validate() { if (dust == null) { dust = SGT_Helper.CreateGameObject("Dust", this); } if (dustMesh == null) { dustMesh = new SGT_Mesh(); } if (dustMaterial == null) { dustMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Dust/" + dustTechnique); } if (dustCamera == null) { dustCamera = SGT_Helper.FindCamera(); } SGT_Helper.SetParent(dust, gameObject); SGT_Helper.SetLayer(dust, gameObject.layer); SGT_Helper.SetTag(dust, gameObject.tag); var finalColour = SGT_Helper.Premultiply(particleColour); var oldDustCameraRotation = dustCameraRotation; if (dustCamera != null) { dustCameraRotation = dustCamera.transform.rotation; } var cameraRotationDelta = Quaternion.Inverse(oldDustCameraRotation) * dustCameraRotation; particleRoll -= cameraRotationDelta.eulerAngles.z; var roll = Quaternion.Euler(new Vector3(0.0f, 0.0f, particleRoll)); dustMaterial.SetTexture("dustTexture", particleTexture); dustMaterial.SetFloat("dustRadius", dustRadius); dustMaterial.SetColor("particleColour", finalColour); dustMaterial.SetFloat("particleFadeInDistance", dustRadius / particleFadeInDistance); dustMaterial.SetFloat("particleFadeOutDistance", dustRadius / particleFadeOutDistance); dustMaterial.SetMatrix("particleRoll", SGT_MatrixHelper.Rotation(roll)); SGT_Helper.SetRenderQueue(dustMaterial, dustRenderQueue); dustMesh.GameObject = dust; dustMesh.HasMeshRenderer = true; dustMesh.MeshRendererEnabled = SGT_Helper.IsBlack(finalColour) == false; dustMesh.SharedMesh = generatedMesh; dustMesh.SharedMaterial = dustMaterial; dustMesh.Update(); }
public static Material[] CreateMaterials(SGT_SurfaceConfiguration surfaceConfiguration, string shaderName, int renderQueue) { var surfaceCount = SurfaceCount(surfaceConfiguration); var materials = new Material[surfaceCount]; materials[0] = SGT_Helper.CreateMaterial(shaderName, renderQueue); for (var i = 1; i < surfaceCount; i++) { materials[i] = SGT_Helper.CloneObject(materials[0]); } return(materials); }
private void Validate() { if (nebula == null) { nebula = SGT_Helper.CreateGameObject("Nebula", this); } if (nebulaMesh == null) { nebulaMesh = new SGT_Mesh(); } if (nebulaMaterial == null) { nebulaMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Nebula/" + nebulaTechnique); } if (nebulaCamera == null) { NebulaCamera = SGT_Helper.FindCamera(); // NOTE: Assigning property } SGT_Helper.SetParent(nebula, gameObject); SGT_Helper.SetLayer(nebula, gameObject.layer); SGT_Helper.SetTag(nebula, gameObject.tag); var sideOrTop = Mathf.Abs(Vector3.Dot((SGT_Helper.GetPosition(nebulaCamera) - transform.position).normalized, transform.up)); var finalColour = SGT_Helper.Premultiply(Color.Lerp(particleSideColour, particleTopColour, sideOrTop)); var oldCameraRotation = nebulaCameraRotation; if (nebulaCamera != null) { nebulaCameraRotation = nebulaCamera.transform.rotation; } var cameraRotationDelta = Quaternion.Inverse(oldCameraRotation) * nebulaCameraRotation; nebulaCameraRoll = SGT_Helper.Wrap(nebulaCameraRoll - cameraRotationDelta.eulerAngles.z, 0.0f, 360.0f); var roll = Quaternion.Euler(new Vector3(0.0f, 0.0f, nebulaCameraRoll)); nebulaMaterial.SetColor("particleColour", finalColour); nebulaMaterial.SetTexture("particleTexture", particleTexture); nebulaMaterial.SetFloat("particleFadeInDistance", particleFadeInDistance); nebulaMaterial.SetMatrix("cameraRoll", SGT_MatrixHelper.Rotation(roll)); SGT_Helper.SetRenderQueue(nebulaMaterial, nebulaRenderQueue); nebulaMesh.GameObject = nebula; nebulaMesh.HasMeshRenderer = true; nebulaMesh.MeshRendererEnabled = SGT_Helper.IsBlack(finalColour) == false; nebulaMesh.SharedMesh = generatedMesh; nebulaMesh.SharedMaterial = nebulaMaterial; nebulaMesh.Update(); }
private void UpdateMaterial() { var targetSkysphereTechnique = "Variant"; // Update surface? if (skysphereMaterial == null || skysphereTechnique != targetSkysphereTechnique) { SGT_Helper.DestroyObject(skysphereMaterial); skysphereTechnique = targetSkysphereTechnique; skysphereMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Skysphere/" + skysphereTechnique, skysphereRenderQueue); } else { SGT_Helper.SetRenderQueue(skysphereMaterial, skysphereRenderQueue); } }
private void UpdateMaterial() { var targetSurfaceTechnique = "Variant"; var targetAtmosphereTechnique = "Variant"; if (starObserver != null) { if (InsideAtmosphere(starObserver.transform.position) == false) { targetSurfaceTechnique += "Outer"; targetAtmosphereTechnique += "Outer"; } } if (atmosphereSurfacePerPixel == true) { targetSurfaceTechnique += "PerPixel"; } // Update surface? if (surfaceMaterials == null || (surfaceTechnique != targetSurfaceTechnique || SGT_ArrayHelper.ContainsSomething(surfaceMaterials) == false || surfaceMaterials.Length != SGT_SurfaceConfiguration_.SurfaceCount(SurfaceConfiguration))) { SGT_Helper.DestroyObjects(surfaceMaterials); surfaceTechnique = targetSurfaceTechnique; surfaceMaterials = SGT_SurfaceConfiguration_.CreateMaterials(surfaceMultiMesh.Configuration, "Hidden/SGT/StarSurface/" + surfaceTechnique, surfaceRenderQueue); } else { SGT_Helper.SetRenderQueues(surfaceMaterials, surfaceRenderQueue); } // Update atmosphere? if (atmosphereTechnique != targetAtmosphereTechnique || atmosphereMaterial == null) { SGT_Helper.DestroyObject(atmosphereMaterial); atmosphereTechnique = targetAtmosphereTechnique; atmosphereMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/StarAtmosphere/" + atmosphereTechnique, atmosphereRenderQueue); } else { SGT_Helper.SetRenderQueue(atmosphereMaterial, atmosphereRenderQueue); } }
private void UpdateMaterial() { var targetStarfieldTechnique = "Variant"; if (starfieldMaterial != null && starfieldTechnique != targetStarfieldTechnique) { starfieldMaterial = SGT_Helper.DestroyObject(starfieldMaterial); } // New material? if (starfieldMaterial == null) { starfieldTechnique = targetStarfieldTechnique; starfieldMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Starfield/" + starfieldTechnique, starfieldRenderQueue); } else { SGT_Helper.SetRenderQueue(starfieldMaterial, starfieldRenderQueue); } }
private void UpdateMaterial() { var targetTechnique = "Variant"; if (tiled == false) { targetTechnique += "Stretched"; } if (shadow == true) { targetTechnique += "Shadow"; } if (lit == true) { targetTechnique += "Lit"; } if (scattering == true) { targetTechnique += "Scattering"; } if (ringMaterial == null || technique != targetTechnique) { SGT_Helper.DestroyObject(ringMaterial); technique = targetTechnique; ringMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Ring/" + technique, renderQueue); ringMesh.SharedMaterial = ringMaterial; } else { SGT_Helper.SetRenderQueue(ringMaterial, renderQueue); } }
private void Validate() { if (dust == null) { dust = SGT_Helper.CreateGameObject("Dust", this); } if (dustMesh == null) { dustMesh = new SGT_Mesh(); } if (dustMaterial == null) { dustMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/Dust/" + dustTechnique); } SGT_Helper.SetParent(dust, gameObject); SGT_Helper.SetLayer(dust, gameObject.layer); SGT_Helper.SetTag(dust, gameObject.tag); var finalColour = SGT_Helper.Premultiply(particleColour); dustMaterial.SetTexture("dustTexture", particleTexture); dustMaterial.SetFloat("dustRadius", dustRadius); dustMaterial.SetColor("particleColour", finalColour); dustMaterial.SetFloat("particleFadeInDistance", dustRadius / particleFadeInDistance); dustMaterial.SetFloat("particleFadeOutDistance", dustRadius / particleFadeOutDistance); SGT_Helper.SetRenderQueue(dustMaterial, dustRenderQueue); dustMesh.GameObject = dust; dustMesh.HasMeshRenderer = true; dustMesh.MeshRendererEnabled = SGT_Helper.IsBlack(finalColour) == false; dustMesh.SharedMesh = generatedMesh; dustMesh.SharedMaterial = dustMaterial; dustMesh.Update(); }
private void UpdateTechnique() { var targetSurfaceTechnique = "Variant"; var targetAtmosphereTechnique = string.Empty; var tagetCloudsTechnique = string.Empty; if (atmosphere == true) { targetSurfaceTechnique += "Atmosphere"; targetAtmosphereTechnique = "Variant"; if (planetObserver != null) { if (InsideAtmosphere(planetObserver.transform.position) == false) { targetSurfaceTechnique += "Outer"; targetAtmosphereTechnique += "Outer"; } } if (atmosphereScattering == true) { //targetSurfaceTechnique += "Scattering"; targetAtmosphereTechnique += "Scattering"; } } if (clouds == true) { tagetCloudsTechnique = "Variant"; } if (surfaceTextureNormal.ContainsSomething == true) { targetSurfaceTechnique += "Normal"; } if (surfaceTextureSpecular.ContainsSomething == true) { targetSurfaceTechnique += "Specular"; } if (shadow == true) { switch (shadowCasterType) { case SGT_ShadowOccluder.Ring: { targetSurfaceTechnique += "RingShadow"; if (atmosphere == true) { targetAtmosphereTechnique += "RingShadow"; } if (clouds == true) { tagetCloudsTechnique += "RingShadow"; } } break; case SGT_ShadowOccluder.Planet: { targetSurfaceTechnique += "PlanetShadow"; if (atmosphere == true) { targetAtmosphereTechnique += "PlanetShadow"; } if (clouds == true) { tagetCloudsTechnique += "PlanetShadow"; } } break; } } if (surfaceTextureDetail != null) { targetSurfaceTechnique += "Detail"; } if (surfaceMaterials != null && (surfaceTechnique != targetSurfaceTechnique || SGT_ArrayHelper.ContainsSomething(surfaceMaterials) == false || surfaceMaterials.Length != SGT_SurfaceConfiguration_.SurfaceCount(SurfaceConfiguration))) { surfaceMaterials = SGT_Helper.DestroyObjects(surfaceMaterials); } if (atmosphereMaterial != null && (atmosphere == false || atmosphereTechnique != targetAtmosphereTechnique)) { atmosphereMaterial = SGT_Helper.DestroyObject(atmosphereMaterial); } if (cloudsMaterials != null && (clouds == false || cloudsTechnique != tagetCloudsTechnique || SGT_ArrayHelper.ContainsSomething(cloudsMaterials) == false || cloudsMaterials.Length != SGT_SurfaceConfiguration_.SurfaceCount(CloudsConfiguration))) { cloudsMaterials = SGT_Helper.DestroyObjects(cloudsMaterials); } // Create planet surface shaders? if (surfaceMaterials == null) { updateShader |= ShaderFlags.Surface; surfaceTechnique = targetSurfaceTechnique; surfaceMaterials = SGT_SurfaceConfiguration_.CreateMaterials(SurfaceConfiguration, "Hidden/SGT/PlanetSurface/" + surfaceTechnique, surfaceRenderQueue); } else { SGT_Helper.SetRenderQueues(surfaceMaterials, surfaceRenderQueue); } // Create planet atmosphere shaders? if (atmosphere == true) { if (atmosphereMaterial == null) { updateShader |= ShaderFlags.Atmosphere; atmosphereTechnique = targetAtmosphereTechnique; atmosphereMaterial = SGT_Helper.CreateMaterial("Hidden/SGT/PlanetAtmosphere/" + atmosphereTechnique, atmosphereRenderQueue); } else { SGT_Helper.SetRenderQueue(atmosphereMaterial, atmosphereRenderQueue); } } // Create planet cloud shaders? if (clouds == true) { if (cloudsMaterials == null) { updateShader |= ShaderFlags.Clouds; cloudsTechnique = tagetCloudsTechnique; cloudsMaterials = SGT_SurfaceConfiguration_.CreateMaterials(CloudsConfiguration, "Hidden/SGT/PlanetClouds/" + cloudsTechnique, atmosphereRenderQueue); } else { SGT_Helper.SetRenderQueues(cloudsMaterials, atmosphereRenderQueue); } } else { if (cloudsMaterials != null) { cloudsMaterials = SGT_Helper.DestroyObjects(cloudsMaterials); } } }