private bool SetMaterialUniforms() { if (!(heightFogSettings.enabled || distanceFogSettings.enabled)) { return(false); } bool seperateColorSettings = (distanceFogSettings.colorSelectionType != ColorSelectionType.ShareOther && heightFogSettings.colorSelectionType != ColorSelectionType.ShareOther) && (heightFogSettings.enabled && distanceFogSettings.enabled); if (seperateColorSettings) { material.SetInt("_SharedColor", 0); material.SetTexture("_FogColorTexture0", distanceFogSettings.colorSelectionType == ColorSelectionType.Gradient ? distanceColorTexture : distanceColorSource.colorRamp); material.SetTexture("_FogColorTexture1", heightFogSettings.colorSelectionType == ColorSelectionType.Gradient ? heightColorTexture : heightColorSource.colorRamp); } else { material.SetInt("_SharedColor", 1); bool selectingFromDistanceFog = distanceFogSettings.colorSelectionType != ColorSelectionType.ShareOther; ColorSelectionType activeSelectionType = selectingFromDistanceFog ? distanceFogSettings.colorSelectionType : heightFogSettings.colorSelectionType; if (activeSelectionType == ColorSelectionType.Gradient) { material.SetTexture("_FogColorTexture0", selectingFromDistanceFog ? distanceColorTexture : heightColorTexture); } else { material.SetTexture("_FogColorTexture0", selectingFromDistanceFog ? distanceColorSource.colorRamp : heightColorSource.colorRamp); } } Vector4 fogModeSettings = new Vector4(); fogModeSettings.x = distanceFogSettings.enabled ? 1f : 0f; fogModeSettings.y = heightFogSettings.enabled ? 1f : 0f; fogModeSettings.z = distanceFogSettings.fogSkybox ? 1f : 0f; fogModeSettings.w = heightFogSettings.fogSkybox ? 1f : 0f; Vector4 fogParameters = new Vector4(); fogParameters.x = distanceFogSettings.endDistance; fogParameters.y = heightFogSettings.baseHeight; fogParameters.z = heightFogSettings.baseDensity; fogParameters.w = heightFogSettings.densityFalloff; material.SetMatrix("_InverseViewMatrix", camera_.cameraToWorldMatrix); material.SetVector("_FogModeSettings", fogModeSettings); material.SetVector("_FogParameters", fogParameters); return(true); }
private void UpdateHeightFogTextures(ColorSelectionType selectionType) { // If the gradient texture is not used, delete it. if (selectionType != ColorSelectionType.Gradient) { //if (m_HeightColorTexture != null) //DestroyImmediate(m_HeightColorTexture); m_HeightColorTexture = null; } if (selectionType == ColorSelectionType.Gradient) { BakeFogColor(HeightColorTexture, heightColorSource.gradient); } }
private void UpdateDistanceFogTextures(ColorSelectionType selectionType) { // If the gradient texture is not used, delete it. if (selectionType != ColorSelectionType.Gradient) { if (m_DistanceColorTexture != null) { DestroyImmediate(m_DistanceColorTexture); } m_DistanceColorTexture = null; } if (selectionType == ColorSelectionType.Gradient) { BakeFogColor(distanceColorTexture, distanceColorSource.gradient); } }
private void UpdateHeightFogTextures() { ColorSelectionType selectionType = heightFogSettings.colorSelectionType; // If the gradient texture is not used, delete it. if (selectionType != ColorSelectionType.Gradient) { if (m_HeightColorTexture != null) { DestroyImmediate(m_HeightColorTexture); } m_HeightColorTexture = null; } if (heightColorSource.m_GradientDirty && heightFogSettings.colorSelectionType == ColorSelectionType.Gradient) { BakeFogColor(heightColorTexture, heightColorSource.gradient); m_HeightColorSource.m_GradientDirty = false; } }
private FogTypePass SetMaterialUniforms(Camera camera) { // Determine the fog type pass FogTypePass fogType = FogTypePass.DistanceOnly; if (!distanceFog.enabled && heightFog.enabled) { fogType = FogTypePass.HeightOnly; } // Share color settings if one of the sources are set to copy the other bool sharedColorSettings = (distanceFog.colorSelectionType == ColorSelectionType.CopyOther) || (heightFog.colorSelectionType == ColorSelectionType.CopyOther); if (distanceFog.enabled && heightFog.enabled) { if (sharedColorSettings) { fogType = FogTypePass.BothSharedColorSettings; } else { fogType = FogTypePass.BothSeperateColorSettinsg; } } if (!distanceFog.enabled && !heightFog.enabled) { return(FogTypePass.None); } // Get the inverse view matrix for converting depth to world position. Matrix4x4 inverseViewMatrix = camera.cameraToWorldMatrix; Material.SetMatrix("_InverseViewMatrix", inverseViewMatrix); // Decide wheter the skybox should have fog applied Material.SetInt("_ApplyDistToSkybox", distanceFog.fogSkybox ? 1 : 0); Material.SetInt("_ApplyHeightToSkybox", heightFog.fogSkybox ? 1 : 0); // Is the shared color sampled from a texture? Otherwise it's from a single color( picker) if (sharedColorSettings) { bool selectingFromDistance = true; FogColorSource activeSelectionSource = distanceColorSource; ColorSelectionType activeSelectionType = distanceFog.colorSelectionType; if (activeSelectionType == ColorSelectionType.CopyOther) { activeSelectionType = heightFog.colorSelectionType; activeSelectionSource = heightColorSource; selectingFromDistance = false; } SetDistanceFogUniforms(); SetHeightFogUniforms(); if (activeSelectionType == ColorSelectionType.Gradient) { Material.SetTexture("_FogColorTexture0", selectingFromDistance ? DistanceColorTexture : HeightColorTexture); } else { Material.SetTexture("_FogColorTexture0", selectingFromDistance ? distanceColorSource.colorRamp : heightColorSource.colorRamp); } } else { if (distanceFog.enabled) { Material.SetTexture("_FogColorTexture0", distanceFog.colorSelectionType == ColorSelectionType.Gradient ? DistanceColorTexture : distanceColorSource.colorRamp); } if (heightFog.enabled) { string colorTextureIdentifier = fogType == FogTypePass.HeightOnly ? "_FogColorTexture0" : "_FogColorTexture1"; Material.SetTexture(colorTextureIdentifier, heightFog.colorSelectionType == ColorSelectionType.Gradient ? HeightColorTexture : heightColorSource.colorRamp); } } // Set distance fog properties if (distanceFog.enabled) { SetDistanceFogUniforms(); } // Set height fog properties if (heightFog.enabled) { SetHeightFogUniforms(); } return(fogType); }
public DisplayOnSelectionType(ColorSelectionType _selectionType) { selectionType = _selectionType; }