コード例 #1
0
ファイル: LightingDebug.cs プロジェクト: leedejun/Graphics
        public static bool IsEnabledFor(
            this DebugLightFilterMode mode,
            GPULightType gpuLightType,
            SpotLightShape spotLightShape
            )
        {
            switch (gpuLightType)
            {
            case GPULightType.ProjectorBox:
            case GPULightType.ProjectorPyramid:
            case GPULightType.Spot:
            {
                switch (spotLightShape)
                {
                case SpotLightShape.Box: return((mode & DebugLightFilterMode.DirectSpotBox) != 0);

                case SpotLightShape.Cone: return((mode & DebugLightFilterMode.DirectSpotCone) != 0);

                case SpotLightShape.Pyramid: return((mode & DebugLightFilterMode.DirectSpotPyramid) != 0);

                default: throw new ArgumentOutOfRangeException(nameof(spotLightShape));
                }
            }

            case GPULightType.Tube: return((mode & DebugLightFilterMode.DirectTube) != 0);

            case GPULightType.Point: return((mode & DebugLightFilterMode.DirectPunctual) != 0);

            case GPULightType.Rectangle: return((mode & DebugLightFilterMode.DirectRectangle) != 0);

            case GPULightType.Directional: return((mode & DebugLightFilterMode.DirectDirectional) != 0);

            default: throw new ArgumentOutOfRangeException(nameof(gpuLightType));
            }
        }
コード例 #2
0
        // TODO: box spot and pyramid spots with non 1 aspect ratios shadow are incorrectly culled, see when scriptable culling will be here
        public static void ExtractSpotLightData(SpotLightShape shape, float spotAngle, float nearPlane, float aspectRatio, float shapeWidth, float shapeHeight, VisibleLight visibleLight, Vector2 viewportSize, float normalBiasMax, out Matrix4x4 view, out Matrix4x4 invViewProjection, out Matrix4x4 projection, out Matrix4x4 deviceProjection, out ShadowSplitData splitData)
        {
            Vector4 lightDir;

            // There is no aspect ratio for non pyramid spot lights
            if (shape != SpotLightShape.Pyramid)
            {
                aspectRatio = 1.0f;
            }

            float guardAngle = CalcGuardAnglePerspective(spotAngle, viewportSize.x, GetPunctualFilterWidthInTexels(), normalBiasMax, 180.0f - spotAngle);

            ExtractSpotLightMatrix(visibleLight, spotAngle, nearPlane, guardAngle, aspectRatio, out view, out projection, out deviceProjection, out invViewProjection, out lightDir, out splitData);

            if (shape == SpotLightShape.Box)
            {
                projection       = ExtractBoxLightProjectionMatrix(visibleLight.range, shapeWidth, shapeHeight, nearPlane);
                deviceProjection = GL.GetGPUProjectionMatrix(projection, false);
                projection       = GL.GetGPUProjectionMatrix(projection, true);
                InvertOrthographic(ref projection, ref view, out invViewProjection);
            }
        }
コード例 #3
0
        // TODO: box spot and pyramid spots with non 1 aspect ratios shadow are incorrectly culled, see when scriptable culling will be here
        public static void ExtractSpotLightData(LightType lightType, SpotLightShape shape, float aspectRatio, float shapeWidth, float shapeHeight, VisibleLight visibleLight, Vector2 viewportSize, float normalBiasMax, out Matrix4x4 view, out Matrix4x4 invViewProjection, out Matrix4x4 projection, out Matrix4x4 deviceProjection, out ShadowSplitData splitData)
        {
            Vector4 lightDir;

            // There is no aspect ratio for non pyramid spot lights
            if (shape != SpotLightShape.Pyramid)
            {
                aspectRatio = 1.0f;
            }

            float guardAngle = CalcGuardAnglePerspective(visibleLight.light.spotAngle, viewportSize.x, GetPunctualFilterWidthInTexels(lightType), normalBiasMax, 180.0f - visibleLight.light.spotAngle);

            ExtractSpotLightMatrix(visibleLight, guardAngle, aspectRatio, out view, out projection, out deviceProjection, out invViewProjection, out lightDir, out splitData);

            if (shape == SpotLightShape.Box)
            {
                float nearMin = 0.1f;
                float nearZ   = visibleLight.light.shadowNearPlane >= nearMin ? visibleLight.light.shadowNearPlane : nearMin;
                projection       = Matrix4x4.Ortho(-shapeWidth / 2, shapeWidth / 2, -shapeHeight / 2, shapeHeight / 2, nearZ, visibleLight.range);
                deviceProjection = GL.GetGPUProjectionMatrix(projection, false);
                InvertOrthographic(ref projection, ref view, out invViewProjection);
            }
        }
コード例 #4
0
    public static float ConvertPunctualLightCandelaToLumen(LightType lightType, SpotLightShape spotLigthShape, float candela, bool enableSpotReflector, float spotAngle, float aspectRatio)
    {
        if (lightType == LightType.Spot && enableSpotReflector)
        {
            // We just need to multiply candela by solid angle in this case
            if (spotLigthShape == SpotLightShape.Cone)
            {
                return(LightUtils.ConvertSpotLightCandelaToLumen(candela, spotAngle * Mathf.Deg2Rad, true));
            }
            else if (spotLigthShape == SpotLightShape.Pyramid)
            {
                float angleA, angleB;
                LightUtils.CalculateAnglesForPyramid(aspectRatio, spotAngle * Mathf.Deg2Rad, out angleA, out angleB);

                return(LightUtils.ConvertFrustrumLightCandelaToLumen(candela, angleA, angleB));
            }
            else     // Box
            {
                return(LightUtils.ConvertPointLightCandelaToLumen(candela));
            }
        }

        return(LightUtils.ConvertPointLightCandelaToLumen(candela));
    }
コード例 #5
0
        // This is not correct, we use candela instead of luminance but this is request from artists to support EV100 on punctual light
        /// <summary>
        /// Convert a punctual light intensity in EV100 to Lumen.
        /// This is not physically correct but it's handy to have EV100 for punctual lights.
        /// </summary>
        /// <param name="lightType"></param>
        /// <param name="spotLightShape"></param>
        /// <param name="ev"></param>
        /// <param name="enableSpotReflector"></param>
        /// <param name="spotAngle"></param>
        /// <param name="aspectRatio"></param>
        /// <returns></returns>
        public static float ConvertPunctualLightEvToLumen(HDLightType lightType, SpotLightShape spotLightShape, float ev, bool enableSpotReflector, float spotAngle, float aspectRatio)
        {
            float candela = ConvertEvToCandela(ev);

            return(ConvertPunctualLightCandelaToLumen(lightType, spotLightShape, candela, enableSpotReflector, spotAngle, aspectRatio));
        }
コード例 #6
0
        /// <summary>
        /// Convert a punctual light intensity in Lux to Lumen
        /// </summary>
        /// <param name="lightType"></param>
        /// <param name="spotLightShape"></param>
        /// <param name="lux"></param>
        /// <param name="enableSpotReflector"></param>
        /// <param name="spotAngle"></param>
        /// <param name="aspectRatio"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static float ConvertPunctualLightLuxToLumen(HDLightType lightType, SpotLightShape spotLightShape, float lux, bool enableSpotReflector, float spotAngle, float aspectRatio, float distance)
        {
            float candela = ConvertLuxToCandela(lux, distance);

            return(ConvertPunctualLightCandelaToLumen(lightType, spotLightShape, candela, enableSpotReflector, spotAngle, aspectRatio));
        }
コード例 #7
0
 void SetSpotLightShape(SpotLightShape shape)
 {
     m_SpotLightShape = shape;
     UpdateBounds();
 }