示例#1
0
        static Material SelectDepthShaderVariant(GraphicsFormat format)
        {
            if (_depthCopyMaterials == null)
            {
                _depthCopyMaterials = new Material[4];
#if HDRP_ENABLED
                if (SRPSupport.GetCurrentPipelineRenderingType() == RenderingPipelineType.HDRP)
                {
                    _depthCopyMaterials[0] = new Material(Shader.Find("usim/BlitCopyDepthHDRP"));
                    _depthCopyMaterials[0].EnableKeyword("HDRP_ENABLED");
                }
                else
#endif // HDRP_ENABLED
                {
                    for (var i = 0; i < _depthCopyMaterials.Length; ++i)
                    {
                        _depthCopyMaterials[i] = new Material(Shader.Find("usim/BlitCopyDepth"));
                        _depthCopyMaterials[i].EnableKeyword($"CHANNELS{i + 1}");
                    }
                    ;
                }
            }

#if HDRP_ENABLED
            if (SRPSupport.GetCurrentPipelineRenderingType() == RenderingPipelineType.HDRP)
            {
                return(_depthCopyMaterials[0]);
            }
            else
#endif // HDRP_ENABLED
            {
                var componentCount = GraphicsUtilities.GetComponentCount(format);
                Debug.Assert(componentCount >= 1 && componentCount <= 4);
                return(_depthCopyMaterials[componentCount - 1]);
            }
        }
示例#2
0
        /// <summary>
        /// Encode the input data as per provided image format.
        /// </summary>
        /// <param name="data">An array of data to be encoded.</param>
        /// <param name="width">Image width.</param>
        /// <param name="height">Image height.</param>
        /// <param name="format">Graphics format used by the render texture.</param>
        /// <param name="imageFormat">Format for encoding the data.</param>
        /// <param name="additionalParam">Additional flags to be passed for the encoding.</param>
        /// <returns></returns>
        /// <exception cref="NotSupportedException"></exception>
        public static Array EncodeArray(Array data, int width, int height, GraphicsFormat format, ImageFormat imageFormat, int additionalParam = 0)
        {
            using (s_Encode.Auto())
            {
                switch (imageFormat)
                {
                case ImageFormat.Raw:
                    return(data);

#if UNITY_2019_3_OR_NEWER
                case ImageFormat.Png:
#if USIM_USE_BUILTIN_PNG_ENCODER
                    return(ImageConversion.EncodeArrayToPNG(data, format, (uint)width, (uint)height, 0));
#else
                    int bitDepth = 8;
                    PngEncoder.ColorType colorType = PngEncoder.GetTypeAndDepth(GraphicsUtilities.GetBlockSize(format), GraphicsUtilities.GetComponentCount(format), ref bitDepth);
                    return(PngEncoder.Encode(ArrayUtilities.Cast <byte>(data), width, height, colorType, bitDepth, (PngEncoder.PngParam)additionalParam));
#endif
                case ImageFormat.Exr:
                    return(ImageConversion.EncodeArrayToEXR(data, format, (uint)width, (uint)height, 0, /*EXRFlags*/ (Texture2D.EXRFlags)additionalParam));

                case ImageFormat.Tga:
                    return(ImageConversion.EncodeArrayToTGA(data, format, (uint)width, (uint)height, 0));
#endif
                case ImageFormat.Jpg:
#if USIM_USE_BUILTIN_JPG_ENCODER && UNITY_2019_3_OR_NEWER
                    return(ImageConversion.EncodeArrayToJPG(data, format, (uint)width, (uint)height, 0, /*quality*/ additionalParam > 0 ? (int)additionalParam : 75));
#else
                    return(JpegEncoder.Encode(ArrayUtilities.Cast <byte>(data), width, height, GraphicsUtilities.GetBlockSize(format), format, /*quality*/ additionalParam > 0 ? (int)additionalParam : 75));
#endif
                default:
                    throw new NotSupportedException("ImageFormat is not supported");
                }
            }
        }