void UpdateAmbientProperties()
        {
            if (world == null)
            {
                return;
            }

            if (adjustCameraFarClip)
            {
                cameraMain.farClipPlane = visibleChunksDistance * 16f;
            }
            float   thisFogDistance = fogUseCameraFarClip ? cameraMain.farClipPlane : fogDistance;
            float   thisFogStart    = thisFogDistance * fogFallOff;
            Vector3 fogData         = new Vector3(thisFogStart * thisFogStart, thisFogDistance * thisFogDistance - thisFogStart * thisFogStart, 0);

            // Global sky uniforms
            Shader.SetGlobalColor("_VPSkyTint", world.skyTint);
            Shader.SetGlobalVector("_VPFogData", fogData);
            Shader.SetGlobalFloat("_VPFogAmount", fogAmount);
            Shader.SetGlobalFloat("_VPExposure", world.exposure);
            Shader.SetGlobalFloat("_VPAmbientLight", ambientLight);
            Shader.SetGlobalFloat("_VPDaylightShadowAtten", daylightShadowAtten);

            // Update skybox material
            VoxelPlaySkybox worldSkybox = isMobilePlatform ? world.skyboxMobile : world.skyboxDesktop;

            if (worldSkybox != VoxelPlaySkybox.UserDefined)
            {
                if (skyboxMaterial != RenderSettings.skybox)
                {
                    switch (worldSkybox)
                    {
                    case VoxelPlaySkybox.Earth:
                        if (skyboxEarth == null)
                        {
                            skyboxEarth = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Earth");
                        }
                        world.skyTint  = new Color(0.52f, 0.5f, 1f);                         // default color for this style
                        skyboxMaterial = skyboxEarth;
                        break;

                    case VoxelPlaySkybox.EarthSimplified:
                        if (skyboxEarthSimplified == null)
                        {
                            skyboxEarthSimplified = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Earth Simplified");
                        }
                        world.skyTint  = new Color(0.52f, 0.5f, 1f);                         // default color for this style
                        skyboxMaterial = skyboxEarthSimplified;
                        break;

                    case VoxelPlaySkybox.Space:
                        if (skyboxSpace == null)
                        {
                            skyboxSpace = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Space");
                        }
                        world.skyTint  = Color.black;
                        skyboxMaterial = skyboxSpace;
                        break;

                    case VoxelPlaySkybox.EarthNightCubemap:
                        if (skyboxEarthNightCube == null)
                        {
                            skyboxEarthNightCube = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Earth Night Cubemap");
                        }
                        world.skyTint = new Color(0.52f, 0.5f, 1f);                          // default color for this style
                        if (world.skyboxNightCubemap != null)
                        {
                            skyboxEarthNightCube.SetTexture("_NightTex", world.skyboxNightCubemap);
                        }
                        skyboxMaterial = skyboxEarthNightCube;
                        break;

                    case VoxelPlaySkybox.EarthDayNightCubemap:
                        if (skyboxEarthDayNightCube == null)
                        {
                            skyboxEarthDayNightCube = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Earth Day Night Cubemap");
                        }
                        world.skyTint = new Color(0.52f, 0.5f, 1f);                          // default color for this style
                        if (world.skyboxDayCubemap != null)
                        {
                            skyboxEarthDayNightCube.SetTexture("_DayTex", world.skyboxDayCubemap);
                        }
                        if (world.skyboxNightCubemap != null)
                        {
                            skyboxEarthDayNightCube.SetTexture("_NightTex", world.skyboxNightCubemap);
                        }
                        skyboxMaterial = skyboxEarthDayNightCube;
                        break;
                    }
                    RenderSettings.skybox = skyboxMaterial;
                }
            }
        }
Ejemplo n.º 2
0
        void UpdateAmbientProperties()
        {
            if (world == null)
            {
                return;
            }

            if (cameraMain != null)
            {
                if (adjustCameraFarClip && distanceAnchor == cameraMain.transform)
                {
                    cameraMain.farClipPlane = visibleChunksDistance * CHUNK_SIZE;
                }
                float   thisFogDistance = fogUseCameraFarClip ? cameraMain.farClipPlane : fogDistance;
                float   thisFogStart    = thisFogDistance * fogFallOff;
                Vector3 fogData         = new Vector3(thisFogStart * thisFogStart, thisFogDistance * thisFogDistance - thisFogStart * thisFogStart, 0);
                Shader.SetGlobalVector("_VPFogData", fogData);
            }

            //TODO: Force variables
            // Global sky & global uniforms
            Shader.SetGlobalColor("_VPSkyTint", world.skyTint);
            Shader.SetGlobalFloat("_VPFogAmount", fogAmount);
            Shader.SetGlobalFloat("_VPExposure", world.exposure);
            Shader.SetGlobalFloat("_VPAmbientLight", ambientLight);
            Shader.SetGlobalFloat("_VPDaylightShadowAtten", daylightShadowAtten);
            Shader.SetGlobalFloat("_VPGrassWindSpeed", world.grassWindSpeed * 0.01f);
            Shader.SetGlobalFloat("_VPTreeWindSpeed", world.treeWindSpeed * 0.005f);

            // Update skybox material
            VoxelPlaySkybox worldSkybox = isMobilePlatform ? world.skyboxMobile : world.skyboxDesktop;

            if (worldSkybox != VoxelPlaySkybox.UserDefined)
            {
                if (skyboxMaterial != RenderSettings.skybox || RenderSettings.skybox == null)
                {
                    switch (worldSkybox)
                    {
                    case VoxelPlaySkybox.Earth:
                        if (skyboxEarth == null)
                        {
                            skyboxEarth = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Earth");
                        }
                        skyboxMaterial = skyboxEarth;
                        break;

                    case VoxelPlaySkybox.EarthSimplified:
                        if (skyboxEarthSimplified == null)
                        {
                            skyboxEarthSimplified = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Earth Simplified");
                        }
                        skyboxMaterial = skyboxEarthSimplified;
                        break;

                    case VoxelPlaySkybox.Space:
                        if (skyboxSpace == null)
                        {
                            skyboxSpace = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Space");
                        }
                        skyboxMaterial = skyboxSpace;
                        break;

                    case VoxelPlaySkybox.EarthNightCubemap:
                        if (skyboxEarthNightCube == null)
                        {
                            skyboxEarthNightCube = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Earth Night Cubemap");
                        }
                        if (world.skyboxNightCubemap != null)
                        {
                            skyboxEarthNightCube.SetTexture("_NightTex", world.skyboxNightCubemap);
                        }
                        skyboxMaterial = skyboxEarthNightCube;
                        break;

                    case VoxelPlaySkybox.EarthDayNightCubemap:
                        if (skyboxEarthDayNightCube == null)
                        {
                            skyboxEarthDayNightCube = Resources.Load <Material> ("VoxelPlay/Materials/VP Skybox Earth Day Night Cubemap");
                        }
                        if (world.skyboxDayCubemap != null)
                        {
                            skyboxEarthDayNightCube.SetTexture("_DayTex", world.skyboxDayCubemap);
                        }
                        if (world.skyboxNightCubemap != null)
                        {
                            skyboxEarthDayNightCube.SetTexture("_NightTex", world.skyboxNightCubemap);
                        }
                        skyboxMaterial = skyboxEarthDayNightCube;
                        break;
                    }
                    RenderSettings.skybox = skyboxMaterial;
                }
            }
        }