예제 #1
0
        private void UpdateWeatherMap(WeatherMakerShaderPropertiesScript props, Texture weatherMap, float weatherMapSeed)
        {
            props.SetTexture(WMS._WeatherMakerWeatherMapTexture, weatherMap);
            props.SetVector(WMS._WeatherMakerWeatherMapScale, new Vector4(WeatherMapScale.x, WeatherMapScale.y, WeatherMapScale.z, 1.0f / WeatherMapScale.z));
            props.SetFloat(WMS._CloudCoverVolumetric, CloudLayerVolumetric1.CloudCover.LastValue);
            props.SetFloat(WMS._CloudCoverSecondaryVolumetric, CloudLayerVolumetric1.CloudCoverSecondary.LastValue);
            props.SetFloat(WMS._CloudDensityVolumetric, CloudLayerVolumetric1.CloudDensity.LastValue);
            props.SetFloat(WMS._CloudTypeVolumetric, CloudLayerVolumetric1.CloudType.LastValue);
            props.SetFloat(WMS._CloudTypeSecondaryVolumetric, CloudLayerVolumetric1.CloudTypeSecondary.LastValue);
            props.SetVector(WMS._CloudCoverageVelocity, velocityAccumCoverage);
            props.SetVector(WMS._CloudTypeVelocity, velocityAccumType);
            props.SetFloat(WMS._CloudCoverageFrequency, WeatherMapCloudCoverageScale.LastValue);
            props.SetFloat(WMS._CloudTypeFrequency, WeatherMapCloudTypeScale.LastValue);
            float r = WeatherMapCloudCoverageRotation.LastValue * Mathf.Deg2Rad;

            props.SetVector(WMS._CloudCoverageRotation, new Vector2(Mathf.Sin(r), Mathf.Cos(r)));
            r = WeatherMapCloudTypeRotation.LastValue * Mathf.Deg2Rad;
            props.SetVector(WMS._CloudTypeRotation, new Vector2(Mathf.Sin(r), Mathf.Cos(r)));
            props.SetFloat(WMS._CloudCoverageAdder, WeatherMapCloudCoverageAdder.LastValue);
            //weatherMapMaterial.SetVector(WMS._CloudCoverageOffset, cloudCoverageOffset);
            props.SetFloat(WMS._CloudCoveragePower, WeatherMapCloudCoveragePower.LastValue);
            props.SetFloat(WMS._CloudTypeAdder, WeatherMapCloudTypeAdder.LastValue);
            //weatherMapMaterial.SetVector(WMS._CloudTypeOffset, cloudTypeOffset);
            props.SetFloat(WMS._CloudTypePower, WeatherMapCloudTypePower.LastValue);
            props.SetVector(WMS._MaskOffset, WeatherMapRenderTextureMaskOffset);
            props.SetFloat(WMS._WeatherMakerWeatherMapSeed, weatherMapSeed);
            props.SetVector(WMS._WeatherMakerCloudCameraPosition, CloudCameraPosition);
        }
예제 #2
0
        private void SetShaderVolumetricCloudShaderProperties(WeatherMakerShaderPropertiesScript props, Texture weatherMap, WeatherMakerCelestialObjectScript sun)
        {
            props.SetVector(WMS._WeatherMakerCloudCameraPosition, CloudCameraPosition);
            props.SetTexture(WMS._WeatherMakerWeatherMapTexture, weatherMap);
            props.SetVector(WMS._WeatherMakerWeatherMapScale, new Vector4(WeatherMapScale.x, WeatherMapScale.y, WeatherMapScale.z, 1.0f / WeatherMapScale.z));
            props.SetFloat(WMS._CloudCoverVolumetric, CloudLayerVolumetric1.CloudCover.LastValue);
            props.SetFloat(WMS._CloudCoverSecondaryVolumetric, CloudLayerVolumetric1.CloudCoverSecondary.LastValue);
            props.SetFloat(WMS._CloudTypeVolumetric, CloudLayerVolumetric1.CloudType.LastValue);
            props.SetFloat(WMS._CloudTypeSecondaryVolumetric, CloudLayerVolumetric1.CloudTypeSecondary.LastValue);
            props.SetFloat(WMS._CloudDensityVolumetric, CloudLayerVolumetric1.CloudDensity.LastValue);
            props.SetFloat(WMS._CloudHeightNoisePowerVolumetric, CloudLayerVolumetric1.CloudHeightNoisePowerVolumetric.LastValue);
            props.SetInt(WMS._CloudDirLightRaySampleCount, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightRaySampleCount);
            props.SetFloat(WMS._CloudPlanetRadiusVolumetric, CloudPlanetRadius);
            props.SetFloat(WMS._CloudNoiseScalarVolumetric, CloudLayerVolumetric1.CloudNoiseScalar.LastValue * WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudNoiseMultiplier);
            props.SetTexture(WMS._CloudNoiseShapeVolumetric, CloudLayerVolumetric1.CloudNoiseShape);
            props.SetTexture(WMS._CloudNoiseDetailVolumetric, CloudLayerVolumetric1.CloudNoiseDetail);
            props.SetTexture(WMS._CloudNoiseCurlVolumetric, CloudLayerVolumetric1.CloudNoiseCurl);
            props.SetVector(WMS._CloudShapeAnimationVelocity, CloudLayerVolumetric1.CloudShapeAnimationVelocity);
            props.SetVector(WMS._CloudDetailAnimationVelocity, CloudLayerVolumetric1.CloudDetailAnimationVelocity);
            props.SetVector(WMS._CloudNoiseScaleVolumetric, CloudLayerVolumetric1.CloudNoiseScale);
            props.SetFloat(WMS._CloudNoiseDetailPowerVolumetric, CloudLayerVolumetric1.CloudNoiseDetailPower.LastValue);
            props.SetFloat(WMS._CloudShapeNoiseMinVolumetric, CloudLayerVolumetric1.CloudShapeNoiseMin.LastValue);
            props.SetFloat(WMS._CloudShapeNoiseMaxVolumetric, CloudLayerVolumetric1.CloudShapeNoiseMax.LastValue);
            props.SetFloat(WMS._CloudBottomFadeVolumetric, CloudLayerVolumetric1.CloudBottomFade.LastValue);
            props.SetFloat(WMS._WeatherMakerDirectionalLightScatterMultiplier, DirectionalLightScatterMultiplier);

            // lower cloud level sphere
            // assign global shader so shadow map can see them
            props.SetFloat(WMS._CloudStartVolumetric, CloudHeight.LastValue);
            props.SetFloat(WMS._CloudStartSquaredVolumetric, CloudHeight.LastValue * CloudHeight.LastValue);
            props.SetFloat(WMS._CloudPlanetStartVolumetric, CloudHeight.LastValue + CloudPlanetRadius);
            props.SetFloat(WMS._CloudPlanetStartSquaredVolumetric, Mathf.Pow(CloudHeight.LastValue + CloudPlanetRadius, 2.0f));

            // height of top minus bottom cloud layer
            float height = CloudHeightTop.LastValue - CloudHeight.LastValue;

            props.SetFloat(WMS._CloudHeightVolumetric, height);
            props.SetFloat(WMS._CloudHeightInverseVolumetric, 1.0f / height);
            height *= height;
            props.SetFloat(WMS._CloudHeightSquaredVolumetric, height);
            props.SetFloat(WMS._CloudHeightSquaredInverseVolumetric, 1.0f / height);

            // upper cloud level sphere
            props.SetFloat(WMS._CloudEndVolumetric, CloudHeightTop.LastValue);
            height = CloudHeightTop.LastValue * CloudHeightTop.LastValue;
            props.SetFloat(WMS._CloudEndSquaredVolumetric, height);
            props.SetFloat(WMS._CloudEndSquaredInverseVolumetric, 1.0f / height);
            props.SetFloat(WMS._CloudPlanetEndVolumetric, CloudHeightTop.LastValue + CloudPlanetRadius);
            props.SetFloat(WMS._CloudPlanetEndSquaredVolumetric, Mathf.Pow(CloudHeightTop.LastValue + CloudPlanetRadius, 2.0f));

            props.SetFloat(WMS._CloudPlanetRadiusNegativeVolumetric, -CloudPlanetRadius);
            props.SetFloat(WMS._CloudPlanetRadiusSquaredVolumetric, CloudPlanetRadius * CloudPlanetRadius);

            props.SetVector(WMS._CloudHenyeyGreensteinPhaseVolumetric, CloudLayerVolumetric1.CloudHenyeyGreensteinPhase);
            props.SetFloat(WMS._CloudRayOffsetVolumetric, CloudLayerVolumetric1.CloudRayOffset + additionalCloudRayOffset);
            props.SetFloat(WMS._CloudMinRayYVolumetric, CloudLayerVolumetric1.CloudMinRayY);

            props.SetVector(WMS._CloudGradientStratus, CloudLayerVolumetric1.CloudGradientStratusVector);
            props.SetVector(WMS._CloudGradientStratoCumulus, CloudLayerVolumetric1.CloudGradientStratoCumulusVector);
            props.SetVector(WMS._CloudGradientCumulus, CloudLayerVolumetric1.CloudGradientCumulusVector);

            // flat clouds
            float cloudCover1 = 0.0f;
            float cloudCover2 = 0.0f;
            float cloudCover3 = 0.0f;
            float cloudCover4 = 0.0f;

            if (isAnimating || CloudLayerVolumetric1 == null || CloudLayerVolumetric1.CloudCover.Maximum == 0.0f || !WeatherMakerScript.Instance.PerformanceProfile.EnableVolumetricClouds ||
                (CloudLayerVolumetric1.FlatLayerMask & WeatherMakerVolumetricCloudsFlatLayerMask.One) == WeatherMakerVolumetricCloudsFlatLayerMask.One)
            {
                cloudCover1 = CloudLayer1.CloudCover;
            }
            if (isAnimating || CloudLayerVolumetric1 == null || CloudLayerVolumetric1.CloudCover.Maximum == 0.0f || !WeatherMakerScript.Instance.PerformanceProfile.EnableVolumetricClouds ||
                (CloudLayerVolumetric1.FlatLayerMask & WeatherMakerVolumetricCloudsFlatLayerMask.Two) == WeatherMakerVolumetricCloudsFlatLayerMask.Two)
            {
                cloudCover2 = CloudLayer2.CloudCover;
            }
            if (isAnimating || CloudLayerVolumetric1 == null || CloudLayerVolumetric1.CloudCover.Maximum == 0.0f || !WeatherMakerScript.Instance.PerformanceProfile.EnableVolumetricClouds ||
                (CloudLayerVolumetric1.FlatLayerMask & WeatherMakerVolumetricCloudsFlatLayerMask.Three) == WeatherMakerVolumetricCloudsFlatLayerMask.Three)
            {
                cloudCover3 = CloudLayer3.CloudCover;
            }
            if (isAnimating || CloudLayerVolumetric1 == null || CloudLayerVolumetric1.CloudCover.Maximum == 0.0f || !WeatherMakerScript.Instance.PerformanceProfile.EnableVolumetricClouds ||
                (CloudLayerVolumetric1.FlatLayerMask & WeatherMakerVolumetricCloudsFlatLayerMask.Four) == WeatherMakerVolumetricCloudsFlatLayerMask.Four)
            {
                cloudCover4 = CloudLayer4.CloudCover;
            }
            props.SetTexture(WMS._CloudNoise1, CloudLayer1.CloudNoise ?? Texture2D.blackTexture);
            props.SetTexture(WMS._CloudNoise2, CloudLayer2.CloudNoise ?? Texture2D.blackTexture);
            props.SetTexture(WMS._CloudNoise3, CloudLayer3.CloudNoise ?? Texture2D.blackTexture);
            props.SetTexture(WMS._CloudNoise4, CloudLayer4.CloudNoise ?? Texture2D.blackTexture);
            props.SetVectorArray(WMS._CloudNoiseScale, CloudLayer1.CloudNoiseScale * scaleReducer, CloudLayer2.CloudNoiseScale * scaleReducer, CloudLayer3.CloudNoiseScale * scaleReducer, CloudLayer4.CloudNoiseScale * scaleReducer);
            props.SetVectorArray(WMS._CloudNoiseMultiplier, CloudLayer1.CloudNoiseMultiplier, CloudLayer2.CloudNoiseMultiplier, CloudLayer3.CloudNoiseMultiplier, CloudLayer4.CloudNoiseMultiplier);
            props.SetVectorArray(WMS._CloudNoiseVelocity, cloudNoiseVelocityAccum1, cloudNoiseVelocityAccum2, cloudNoiseVelocityAccum3, cloudNoiseVelocityAccum4);
            props.SetFloatArrayRotation(WMS._CloudNoiseRotation, CloudLayer1.CloudNoiseRotation.LastValue, CloudLayer2.CloudNoiseRotation.LastValue, CloudLayer3.CloudNoiseRotation.LastValue, CloudLayer4.CloudNoiseRotation.LastValue);
            props.SetFloatArray(WMS._CloudHeight, CloudLayer1.CloudHeight, CloudLayer2.CloudHeight, CloudLayer3.CloudHeight, CloudLayer4.CloudHeight);
            props.SetFloatArray(WMS._CloudCover, cloudCover1, cloudCover2, cloudCover3, cloudCover4);
            props.SetFloatArray(WMS._CloudDensity, CloudLayer1.CloudDensity, CloudLayer2.CloudDensity, CloudLayer3.CloudDensity, CloudLayer4.CloudDensity);
            props.SetFloatArray(WMS._CloudSharpness, CloudLayer1.CloudSharpness, CloudLayer2.CloudSharpness, CloudLayer3.CloudSharpness, CloudLayer4.CloudSharpness);
            props.SetFloatArray(WMS._CloudRayOffset, CloudLayer1.CloudRayOffset, CloudLayer2.CloudRayOffset, CloudLayer3.CloudRayOffset, CloudLayer4.CloudRayOffset);

            props.SetVector(WMS._CloudNoiseSampleCountVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudSampleCount.ToVector2());
            props.SetInt(WMS._CloudRaymarchSkipThreshold, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchSkipThreshold);
            props.SetFloat(WMS._CloudRaymarchMaybeInCloudStepMultiplier, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchMaybeInCloudStepMultiplier);
            props.SetFloat(WMS._CloudRaymarchInCloudStepMultiplier, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchInCloudStepMultiplier);
            props.SetFloat(WMS._CloudRaymarchSkipMultiplier, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchSkipMultiplier);
            props.SetInt(WMS._CloudRaymarchSkipMultiplierMaxCount, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchSkipMultiplierMaxCount);
            props.SetVector(WMS._CloudNoiseLodVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudLod.ToVector2());
            props.SetColor(WMS._CloudColorVolumetric, CloudLayerVolumetric1.CloudColor);
            props.SetColor(WMS._CloudDirColorVolumetric, CloudLayerVolumetric1.CloudDirLightGradientColorColor);
            props.SetColor(WMS._CloudEmissionColorVolumetric, CloudLayerVolumetric1.CloudEmissionColor);
            props.SetFloat(WMS._CloudDirLightMultiplierVolumetric, CloudLayerVolumetric1.CloudDirLightMultiplier);
            props.SetFloat(WMS._CloudLightDitherLevel, CloudLayerVolumetric1.CloudLightDitherLevel);
            props.SetFloat(WMS._CloudPointSpotLightMultiplierVolumetric, CloudLayerVolumetric1.CloudPointSpotLightMultiplier);
            props.SetFloat(WMS._CloudAmbientGroundIntensityVolumetric, CloudLayerVolumetric1.CloudAmbientGroundIntensity);
            props.SetFloat(WMS._CloudAmbientSkyIntensityVolumetric, CloudLayerVolumetric1.CloudAmbientSkyIntensity);
            float backgroundSkyStyle = (WeatherMakerSkySphereScript.Instance == null || WeatherMakerSkySphereScript.Instance.SkySphereProfile == null ||
                                        WeatherMakerSkySphereScript.Instance.SkySphereProfile.SkyMode == WeatherMakeSkyMode.ProceduralUnityStyle ||
                                        WeatherMakerSkySphereScript.Instance.SkySphereProfile.SkyMode == WeatherMakeSkyMode.ProceduralTexturedUnityStyle ? 0.0f : 1.0f);

            props.SetVector(WMS._CloudBackgroundSkyIntensityVolumetric, new Vector4(CloudLayerVolumetric1.CloudSkyIntensity, backgroundSkyStyle, 0.0f, 0.0f));
            props.SetFloat(WMS._CloudAmbientSkyHeightMultiplierVolumetric, CloudLayerVolumetric1.CloudAmbientSkyHeightMultiplier);
            props.SetFloat(WMS._CloudAmbientGroundHeightMultiplierVolumetric, CloudLayerVolumetric1.CloudAmbientGroundHeightMultiplier);
            props.SetFloat(WMS._CloudLightAbsorptionVolumetric, CloudLayerVolumetric1.CloudLightAbsorption);
            props.SetFloat(WMS._CloudDirLightIndirectMultiplierVolumetric, CloudLayerVolumetric1.CloudDirLightIndirectMultiplier);
            props.SetFloat(WMS._CloudPowderMultiplierVolumetric, CloudLayerVolumetric1.CloudPowderMultiplier.LastValue);
            props.SetFloat(WMS._CloudOpticalDistanceMultiplierVolumetric, CloudLayerVolumetric1.CloudOpticalDistanceMultiplier);
            props.SetFloat(WMS._CloudHorizonFadeMultiplierVolumetric, CloudLayerVolumetric1.CloudHorizonFadeMultiplier);
            props.SetFloat(WMS._CloudDirLightSampleCount, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightSampleCount);
            props.SetFloat(WMS._CloudLightStepMultiplierVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightStepMultiplier);
            props.SetFloat(WMS._CloudMaxRayLengthMultiplierVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudMaxRayLengthMultiplier);
            props.SetFloat(WMS._CloudRayDitherVolumetric, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRayDither);
            props.SetFloat(WMS._CloudRaymarchMultiplierVolumetric, Mathf.Max(CloudLayerVolumetric1.CloudMinRayMarchMultiplier, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudRaymarchMultiplier));
            props.SetVector(WMS._CloudRayMarchParameters, CloudLayerVolumetric1.CloudRayMarchParamers);

            // sample details for dir light ray march if max lod is small
            props.SetFloat(WMS._CloudDirLightLod, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightLod);
            props.SetInt(WMS._CloudRaymarchSampleDetailsForDirLight, WeatherMakerScript.Instance.PerformanceProfile.VolumetricCloudDirLightSampleDetails ? 1 : 0);

            // flat
            props.SetColorArray(WMS._CloudColor,
                                CloudLayer1.CloudColor * sun.GetGradientColor(CloudLayer1.CloudGradientColor),
                                CloudLayer2.CloudColor * sun.GetGradientColor(CloudLayer2.CloudGradientColor),
                                CloudLayer3.CloudColor * sun.GetGradientColor(CloudLayer3.CloudGradientColor),
                                CloudLayer4.CloudColor * sun.GetGradientColor(CloudLayer4.CloudGradientColor));
            props.SetColorArray(WMS._CloudEmissionColor,
                                CloudLayer1.CloudEmissionColor,
                                CloudLayer2.CloudEmissionColor,
                                CloudLayer3.CloudEmissionColor,
                                CloudLayer4.CloudEmissionColor);
            props.SetFloatArray(WMS._CloudAmbientMultiplier,
                                CloudLayer1.CloudAmbientMultiplier,
                                CloudLayer2.CloudAmbientMultiplier,
                                CloudLayer3.CloudAmbientMultiplier,
                                CloudLayer4.CloudAmbientMultiplier);
            props.SetFloatArray(WMS._CloudScatterMultiplier,
                                CloudLayer1.CloudScatterMultiplier,
                                CloudLayer2.CloudScatterMultiplier,
                                CloudLayer3.CloudScatterMultiplier,
                                CloudLayer4.CloudScatterMultiplier);

            /*
             * if (CloudLayer1.CloudNoiseMask != null || CloudLayer2.CloudNoiseMask != null || CloudLayer3.CloudNoiseMask != null || CloudLayer4.CloudNoiseMask != null)
             * {
             *  cloudMaterial.SetTexture(WMS._CloudNoiseMask1, CloudLayer1.CloudNoiseMask ?? Texture2D.whiteTexture);
             *  cloudMaterial.SetTexture(WMS._CloudNoiseMask2, CloudLayer2.CloudNoiseMask ?? Texture2D.whiteTexture);
             *  cloudMaterial.SetTexture(WMS._CloudNoiseMask3, CloudLayer3.CloudNoiseMask ?? Texture2D.whiteTexture);
             *  cloudMaterial.SetTexture(WMS._CloudNoiseMask4, CloudLayer4.CloudNoiseMask ?? Texture2D.whiteTexture);
             *  WeatherMakerShaderIds.SetVectorArray(cloudMaterial, "_CloudNoiseMaskOffset",
             *      CloudLayer1.CloudNoiseMaskOffset,
             *      CloudLayer2.CloudNoiseMaskOffset,
             *      CloudLayer3.CloudNoiseMaskOffset,
             *      CloudLayer4.CloudNoiseMaskOffset);
             *  WeatherMakerShaderIds.SetVectorArray(cloudMaterial, "_CloudNoiseMaskVelocity", cloudNoiseMaskVelocityAccum1, cloudNoiseMaskVelocityAccum2, cloudNoiseMaskVelocityAccum3, cloudNoiseMaskVelocityAccum4);
             *  WeatherMakerShaderIds.SetFloatArray(cloudMaterial, "_CloudNoiseMaskScale",
             *      (CloudLayer1.CloudNoiseMask == null ? 0.0f : CloudLayer1.CloudNoiseMaskScale * scaleReducer),
             *      (CloudLayer2.CloudNoiseMask == null ? 0.0f : CloudLayer2.CloudNoiseMaskScale * scaleReducer),
             *      (CloudLayer3.CloudNoiseMask == null ? 0.0f : CloudLayer3.CloudNoiseMaskScale * scaleReducer),
             *      (CloudLayer4.CloudNoiseMask == null ? 0.0f : CloudLayer4.CloudNoiseMaskScale * scaleReducer));
             *  WeatherMakerShaderIds.SetFloatArrayRotation(cloudMaterial, "_CloudNoiseMaskRotation",
             *      CloudLayer1.CloudNoiseMaskRotation.LastValue,
             *      CloudLayer2.CloudNoiseMaskRotation.LastValue,
             *      CloudLayer3.CloudNoiseMaskRotation.LastValue,
             *      CloudLayer4.CloudNoiseMaskRotation.LastValue);
             * }
             */
            props.SetFloatArray(WMS._CloudLightAbsorption,
                                CloudLayer1.CloudLightAbsorption,
                                CloudLayer2.CloudLightAbsorption,
                                CloudLayer3.CloudLightAbsorption,
                                CloudLayer4.CloudLightAbsorption);
        }