internal LocalVolumetricFogEngineData ConvertToEngineData() { LocalVolumetricFogEngineData data = new LocalVolumetricFogEngineData(); data.extinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath); data.scattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(data.extinction, (Vector4)albedo); var atlas = LocalVolumetricFogManager.manager.volumeAtlas.GetAtlas(); data.atlasOffset = LocalVolumetricFogManager.manager.volumeAtlas.GetTextureOffset(volumeMask); data.atlasOffset.x /= (float)atlas.width; data.atlasOffset.y /= (float)atlas.height; data.atlasOffset.z /= (float)atlas.volumeDepth; data.useVolumeMask = volumeMask != null ? 1 : 0; float volumeMaskSize = volumeMask != null ? (float)volumeMask.width : 0.0f; // Volume Mask Textures are always cubic data.maskSize = new Vector4(volumeMaskSize / atlas.width, volumeMaskSize / atlas.height, volumeMaskSize / atlas.volumeDepth, volumeMaskSize); data.textureScroll = textureOffset; data.textureTiling = textureTiling; // Clamp to avoid NaNs. Vector3 positiveFade = this.positiveFade; Vector3 negativeFade = this.negativeFade; data.rcpPosFaceFade.x = Mathf.Min(1.0f / positiveFade.x, float.MaxValue); data.rcpPosFaceFade.y = Mathf.Min(1.0f / positiveFade.y, float.MaxValue); data.rcpPosFaceFade.z = Mathf.Min(1.0f / positiveFade.z, float.MaxValue); data.rcpNegFaceFade.y = Mathf.Min(1.0f / negativeFade.y, float.MaxValue); data.rcpNegFaceFade.x = Mathf.Min(1.0f / negativeFade.x, float.MaxValue); data.rcpNegFaceFade.z = Mathf.Min(1.0f / negativeFade.z, float.MaxValue); data.invertFade = invertFade ? 1 : 0; data.falloffMode = falloffMode; float distFadeLen = Mathf.Max(distanceFadeEnd - distanceFadeStart, 0.00001526f); data.rcpDistFadeLen = 1.0f / distFadeLen; data.endTimesRcpDistFadeLen = distanceFadeEnd * data.rcpDistFadeLen; return(data); }
void UpdateShaderVariablesGlobalCBFogParameters(ref ShaderVariablesGlobal cb, HDCamera hdCamera) { bool enableVolumetrics = enableVolumetricFog.value && hdCamera.frameSettings.IsEnabled(FrameSettingsField.Volumetrics); cb._FogEnabled = 1; cb._PBRFogEnabled = IsPBRFogEnabled(hdCamera) ? 1 : 0; cb._EnableVolumetricFog = enableVolumetrics ? 1 : 0; cb._MaxFogDistance = maxFogDistance.value; Color fogColor = (colorMode.value == FogColorMode.ConstantColor) ? color.value : tint.value; cb._FogColorMode = (float)colorMode.value; cb._FogColor = new Color(fogColor.r, fogColor.g, fogColor.b, 0.0f); cb._MipFogParameters = new Vector4(mipFogNear.value, mipFogFar.value, mipFogMaxMip.value, 0.0f); LocalVolumetricFogArtistParameters param = new LocalVolumetricFogArtistParameters(albedo.value, meanFreePath.value, anisotropy.value); LocalVolumetricFogEngineData data = param.ConvertToEngineData(); cb._HeightFogBaseScattering = data.scattering; cb._HeightFogBaseExtinction = data.extinction; float crBaseHeight = baseHeight.value; if (ShaderConfig.s_CameraRelativeRendering != 0) { crBaseHeight -= hdCamera.camera.transform.position.y; } float layerDepth = Mathf.Max(0.01f, maximumHeight.value - baseHeight.value); float H = ScaleHeightFromLayerDepth(layerDepth); cb._HeightFogExponents = new Vector2(1.0f / H, H); cb._HeightFogBaseHeight = crBaseHeight; cb._GlobalFogAnisotropy = anisotropy.value; cb._VolumetricFilteringEnabled = ((int)denoisingMode.value & (int)FogDenoisingMode.Gaussian) != 0 ? 1 : 0; cb._FogDirectionalOnly = directionalLightsOnly.value ? 1 : 0; }