Exemple #1
0
        void Awake()
        {
            if (_ids == null)
            {
                _ids = new FoWIDs();
                _ids.Initialise();
            }

            Reinitialize();
        }
        void Awake()
        {
            current = this;
            if (_ids == null)
            {
                _ids = new FoWIDs();
                _ids.Initialise();
            }

            Reinitialize();
        }
Exemple #3
0
        void Awake()
        {
            if (_ids == null)
            {
                _ids = new FoWIDs();
                _ids.Initialise();
            }

            onRenderFogTexture = new UnityEngine.Events.UnityEvent();

            Reinitialize();
        }
        public void Render()
        {
            FogOfWarTeam fow = FogOfWarTeam.GetTeam(team);

            if (fow == null)
            {
                Debug.LogWarning("No FogOfWar team found: " + team.ToString());
                return;
            }

            if (fow.finalFogTexture == null)
            {
                return;
            }

            if (_ids == null)
            {
                _ids = new FoWIDs();
            }

#if UNITY_2019_3_OR_NEWER
            FogOfWarClearFog clearfog = null;
            camera.TryGetComponent(out clearfog);
#else
            FogOfWarClearFog clearfog = camera.GetComponent <FogOfWarClearFog>();
#endif
            if (clearfog != null && clearfog.targetCamera?.targetTexture != null)
            {
                fogColorTexture       = clearfog.targetCamera.targetTexture;
                fogTextureScreenSpace = true;
            }

            if ((camera.depthTextureMode & DepthTextureMode.Depth) == 0)
            {
                camera.depthTextureMode |= DepthTextureMode.Depth;
            }

            fow.finalFogTexture.filterMode = pointFiltering ? FilterMode.Point : FilterMode.Bilinear;
            SetTexture(_ids.fogTex, fow.finalFogTexture);
            SetVector(_ids.fogTextureSize, fow.mapResolution.ToFloat());
            SetFloat(_ids.mapSize, fow.mapSize);
            SetVector(_ids.mapOffset, fow.mapOffset);
            SetColor(_ids.mainFogColor, fogColor);
            SetMatrix(_ids.inverseView, camera.cameraToWorldMatrix);
            SetMatrix(_ids.inverseProj, camera.projectionMatrix.inverse);
            SetFloat(_ids.outsideFogStrength, outsideFogStrength);
            SetVector(_ids.cameraWorldPosition, camera.transform.position);
            SetFloat(_ids.stereoSeparation, camera.stereoSeparation);

            // orthographic is treated very differently in the shader, so we have to make sure it executes the right code
            SetKeyword("CAMERA_PERSPECTIVE", !camera.orthographic);
            SetKeyword("CAMERA_ORTHOGRAPHIC", camera.orthographic);

            // which plane will the fog be rendered to?
            SetKeyword("PLANE_XY", fow.plane == FogOfWarPlane.XY);
            SetKeyword("PLANE_YZ", fow.plane == FogOfWarPlane.YZ);
            SetKeyword("PLANE_XZ", fow.plane == FogOfWarPlane.XZ);

            SetKeyword("FOG_COLORED", fogColorTexture == null);
            SetKeyword("FOG_TEXTURED_WORLD", fogColorTexture != null && !fogTextureScreenSpace);
            SetKeyword("FOG_TEXTURED_SCREEN", fogColorTexture != null && fogTextureScreenSpace);
            if (fogColorTexture != null)
            {
                SetTexture(_ids.fogColorTex, fogColorTexture);
                SetVector(_ids.fogColorTexScale, new Vector2(fogColorTextureScale, fogColorTextureHeight));
            }

            SetKeyword("FOGFARPLANE", fogFarPlane);

            BlitToScreen();
        }