public DensityVolumeEngineData ConvertToEngineData()
        {
            DensityVolumeEngineData data = new DensityVolumeEngineData();

            data.extinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
            data.scattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(data.extinction, (Vector3)(Vector4)albedo);

            data.textureIndex  = textureIndex;
            data.textureScroll = volumeScrollingAmount;
            data.textureTiling = textureTiling;

            // Note that we do not clamp here. Infinities work in the expected way in the shader.
            // This also allows us to avoid artifacts caused by numerical issues.
            data.rcpPosFade.x = 1.0f / positiveFade.x;
            data.rcpPosFade.y = 1.0f / positiveFade.y;
            data.rcpPosFade.z = 1.0f / positiveFade.z;

            data.rcpNegFade.y = 1.0f / negativeFade.y;
            data.rcpNegFade.x = 1.0f / negativeFade.x;
            data.rcpNegFade.z = 1.0f / negativeFade.z;

            data.invertFade = invertFade ? 1 : 0;

            return(data);
        }
Esempio n. 2
0
        public DensityVolumeEngineData ConvertToEngineData()
        {
            DensityVolumeEngineData data = new DensityVolumeEngineData();

            data.extinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
            data.scattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(data.extinction, (Vector3)(Vector4)albedo);

            data.textureIndex  = textureIndex;
            data.textureScroll = volumeScrollingAmount;
            data.textureTiling = textureTiling;

            // Clamp to avoid NaNs.
            Vector3 positiveFade = this.positiveFade;
            Vector3 negativeFade = this.negativeFade;

            data.rcpPosFade.x = Mathf.Min(1.0f / positiveFade.x, float.MaxValue);
            data.rcpPosFade.y = Mathf.Min(1.0f / positiveFade.y, float.MaxValue);
            data.rcpPosFade.z = Mathf.Min(1.0f / positiveFade.z, float.MaxValue);

            data.rcpNegFade.y = Mathf.Min(1.0f / negativeFade.y, float.MaxValue);
            data.rcpNegFade.x = Mathf.Min(1.0f / negativeFade.x, float.MaxValue);
            data.rcpNegFade.z = Mathf.Min(1.0f / negativeFade.z, float.MaxValue);

            data.invertFade = invertFade ? 1 : 0;

            return(data);
        }
Esempio n. 3
0
        public override void PushShaderParameters(HDCamera hdCamera, CommandBuffer cmd)
        {
            PushShaderParametersCommon(hdCamera, cmd, FogType.Volumetric);

            DensityVolumeArtistParameters param = new DensityVolumeArtistParameters(albedo, meanFreePath, anisotropy);

            DensityVolumeEngineData data = param.ConvertToEngineData();

            cmd.SetGlobalVector(HDShaderIDs._HeightFogBaseScattering, data.scattering);
            cmd.SetGlobalFloat(HDShaderIDs._HeightFogBaseExtinction, data.extinction);

            float crBaseHeight = baseHeight;

            if (ShaderConfig.s_CameraRelativeRendering != 0)
            {
                crBaseHeight -= hdCamera.camera.transform.position.y;
            }

            float relativeMeanHeight = Mathf.Max(0.01f, meanHeight - baseHeight);

            // FogExponent = 1 / BaseRelative(MeanHeight)
            cmd.SetGlobalVector(HDShaderIDs._HeightFogExponents, new Vector2(1.0f / relativeMeanHeight, relativeMeanHeight));
            cmd.SetGlobalFloat(HDShaderIDs._HeightFogBaseHeight, crBaseHeight);
            cmd.SetGlobalFloat(HDShaderIDs._GlobalFogAnisotropy, anisotropy);
            cmd.SetGlobalInt(HDShaderIDs._EnableDistantFog, enableDistantFog ? 1 : 0);
        }
Esempio n. 4
0
        public override void PushShaderParameters(HDCamera hdCamera, CommandBuffer cmd)
        {
            DensityVolumeArtistParameters param = new DensityVolumeArtistParameters(albedo, meanFreePath, anisotropy);

            DensityVolumeEngineData data = param.ConvertToEngineData();

            cmd.SetGlobalInt(HDShaderIDs._AtmosphericScatteringType, (int)FogType.Volumetric);

            cmd.SetGlobalVector(HDShaderIDs._GlobalScattering, data.scattering);
            cmd.SetGlobalFloat(HDShaderIDs._GlobalExtinction, data.extinction);
            cmd.SetGlobalFloat(HDShaderIDs._GlobalAnisotropy, anisotropy);
        }
        public static void PushNeutralShaderParameters(HDCamera hdCamera, CommandBuffer cmd)
        {
            cmd.SetGlobalInt(HDShaderIDs._AtmosphericScatteringType, (int)FogType.None);

            // In case volumetric lighting is enabled, we need to make sure that all rendering passes
            // (not just the atmospheric scattering one) receive neutral parameters.
            if (hdCamera.frameSettings.enableVolumetrics)
            {
                var data = DensityVolumeEngineData.GetNeutralValues();

                cmd.SetGlobalVector(HDShaderIDs._GlobalScattering, data.scattering);
                cmd.SetGlobalFloat(HDShaderIDs._GlobalExtinction, data.extinction);
                cmd.SetGlobalFloat(HDShaderIDs._GlobalAnisotropy, 0.0f);
            }
        }
Esempio n. 6
0
        public DensityVolumeEngineData GetData()
        {
            DensityVolumeEngineData data = new DensityVolumeEngineData();

            data.extinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
            data.scattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(data.extinction, (Vector3)(Vector4)albedo);

            data.textureIndex  = textureIndex;
            data.textureScroll = volumeScrollingAmount;
            data.textureTiling = textureTiling;

            // Avoid numerical problems by clamping extreme values.
            data.rcpPosFade.x = Mathf.Clamp(1.0f / positiveFade.x, 0.00001526f, 65536.0f);
            data.rcpNegFade.x = Mathf.Clamp(1.0f / negativeFade.x, 0.00001526f, 65536.0f);
            data.rcpPosFade.y = Mathf.Clamp(1.0f / positiveFade.y, 0.00001526f, 65536.0f);
            data.rcpNegFade.y = Mathf.Clamp(1.0f / negativeFade.y, 0.00001526f, 65536.0f);
            data.rcpPosFade.z = Mathf.Clamp(1.0f / positiveFade.z, 0.00001526f, 65536.0f);
            data.rcpNegFade.z = Mathf.Clamp(1.0f / negativeFade.z, 0.00001526f, 65536.0f);

            return(data);
        }
        public override void PushShaderParameters(HDCamera hdCamera, CommandBuffer cmd)
        {
            DensityVolumeArtistParameters param = new DensityVolumeArtistParameters(albedo, meanFreePath, anisotropy);

            DensityVolumeEngineData data = param.ConvertToEngineData();

            cmd.SetGlobalInt(HDShaderIDs._AtmosphericScatteringType, (int)FogType.Volumetric);

            cmd.SetGlobalVector(HDShaderIDs._HeightFogBaseScattering, data.scattering);
            cmd.SetGlobalFloat(HDShaderIDs._HeightFogBaseExtinction, data.extinction);

            float crBaseHeight = baseHeight;

            if (ShaderConfig.s_CameraRelativeRendering != 0)
            {
                crBaseHeight -= hdCamera.camera.transform.position.y;
            }

            cmd.SetGlobalVector(HDShaderIDs._HeightFogExponents, new Vector2(heightExponent, 1.0f / heightExponent));
            cmd.SetGlobalFloat(HDShaderIDs._HeightFogBaseHeight, crBaseHeight);
            cmd.SetGlobalFloat(HDShaderIDs._GlobalFogAnisotropy, anisotropy);
        }