예제 #1
0
 /// <summary>
 /// If rendered with FXAA we'll need an additional (final) pass, that takes the lighted scene, rendered to a texture, as input.
 /// </summary>
 /// <param name="srcTex">RenderTarget, that contains a single texture in the Albedo/Specular channel, that contains the lighted scene.</param>
 /// <param name="screenParams">The width and height of the screen.</param>
 // see: http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf
 // http://blog.simonrodriguez.fr/articles/30-07-2016_implementing_fxaa.html
 public static ShaderEffect FXAARenderTargetEffect(WritableTexture srcTex, float2 screenParams)
 {
     //TODO: #define constants to uniforms
     return(new ShaderEffect(new[]
     {
         new EffectPassDeclaration
         {
             VS = AssetStorage.Get <string>("Deferred.vert"),
             PS = AssetStorage.Get <string>("FXAA.frag"),
             StateSet = new RenderStateSet
             {
                 AlphaBlendEnable = false,
                 ZEnable = true,
             }
         }
     },
                             new[]
     {
         new EffectParameterDeclaration {
             Name = UniformNameDeclarations.DeferredRenderTextures[(int)RenderTargetTextureTypes.Albedo], Value = srcTex
         },
         new EffectParameterDeclaration {
             Name = UniformNameDeclarations.ScreenParams, Value = screenParams
         },
     }));
 }
예제 #2
0
 public ITextureHandle GetWritableTextureHandleFromTexture(WritableTexture texture)
 {
     if (!_identifierToTextureHandleDictionary.TryGetValue(texture.SessionUniqueIdentifier, out var foundTextureHandle))
     {
         return(RegisterNewTexture(texture));
     }
     return(foundTextureHandle);
 }
예제 #3
0
        private ITextureHandle RegisterNewTexture(WritableTexture texture)
        {
            // Configure newly created TextureHandle to reflect Texture's properties on GPU (allocate buffers)
            ITextureHandle textureHandle = _renderContextImp.CreateTexture(texture);

            // Setup handler to observe changes of the texture data and dispose event (deallocation)
            texture.TextureChanged += TextureChanged;

            _identifierToTextureHandleDictionary.Add(texture.SessionUniqueIdentifier, textureHandle);

            return(textureHandle);
        }
예제 #4
0
        /// <summary>
        /// Creates a blurred SSAO texture, to hide rectangular artifacts originating from the noise texture;
        /// </summary>
        /// <param name="ssaoRenderTex">The non blurred SSAO texture.</param>
        public static ShaderEffect SSAORenderTargetBlurEffect(WritableTexture ssaoRenderTex)
        {
            //TODO: is there a smart(er) way to set #define KERNEL_LENGTH in file?
            var   frag = AssetStorage.Get <string>("SimpleBlur.frag");
            float blurKernelSize;

            switch (ssaoRenderTex.Width)
            {
            case (int)TexRes.Low:
                blurKernelSize = 2.0f;
                break;

            default:
            case (int)TexRes.Middle:
                blurKernelSize = 4.0f;
                break;

            case (int)TexRes.High:
                blurKernelSize = 8.0f;
                break;
            }

            if (blurKernelSize != 4.0f)
            {
                var lines = frag.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                lines[2] = $"#define KERNEL_SIZE_HALF {blurKernelSize * 0.5}";
                frag     = string.Join("\n", lines);
            }

            return(new ShaderEffect(new[]
            {
                new EffectPassDeclaration
                {
                    VS = AssetStorage.Get <string>("Deferred.vert"),
                    PS = frag,
                    StateSet = new RenderStateSet
                    {
                        AlphaBlendEnable = false,
                        ZEnable = true,
                    }
                }
            },
                                    new[]
            {
                new EffectParameterDeclaration {
                    Name = "InputTex", Value = ssaoRenderTex
                },
            }));
        }
예제 #5
0
 /// <summary>
 /// Generates a albedo and specular (alpha channel) texture and sets it at the correct position in the RenderTextures Array.
 /// </summary>
 public void SetAlbedoSpecularTex()
 {
     RenderTextures[(int)RenderTargetTextureTypes.Albedo] = WritableTexture.CreateAlbedoTex((int)TextureResolution, (int)TextureResolution);
 }
예제 #6
0
 /// <summary>
 /// Sets a RenderTexture into the correct position in the RederTexture array.
 /// </summary>
 /// <param name="src">The source RenderTexture.</param>
 /// <param name="tex">The type of the texture.</param>
 public void SetTexture(WritableTexture src, RenderTargetTextureTypes tex)
 {
     RenderTextures[(int)tex] = src ?? throw new ArgumentException("Texture from source target is null!");
 }
예제 #7
0
 /// <summary>
 /// Generates a position texture and sets it at the correct position in the RenderTextures Array.
 /// </summary>
 public void SetPositionTex()
 {
     RenderTextures[(int)RenderTargetTextureTypes.Position] = WritableTexture.CreatePosTex((int)TextureResolution, (int)TextureResolution);
 }
예제 #8
0
 /// <summary>
 /// Creates a new instance of type "RenderTarget".
 /// </summary>
 /// <param name="texRes">Resolution of the created Textures.</param>
 public RenderTarget(TexRes texRes)
 {
     RenderTextures    = new WritableTexture[Enum.GetNames(typeof(RenderTargetTextureTypes)).Length];
     TextureResolution = texRes;
     IsDepthOnly       = false;
 }
예제 #9
0
 /// <summary>
 /// Generates a specular texture and sets it at the correct position in the RenderTextures Array.
 /// </summary>
 public void SetSpecularTex()
 {
     RenderTextures[(int)RenderTargetTextureTypes.Specular] = WritableTexture.CreateSpecularTex((int)TextureResolution, (int)TextureResolution);
 }
예제 #10
0
 /// <summary>
 /// Generates a SSAO texture and sets it at the correct position in the RenderTextures Array.
 /// </summary>
 public void SetSSAOTex()
 {
     RenderTextures[(int)RenderTargetTextureTypes.Ssao] = WritableTexture.CreateSSAOTex((int)TextureResolution, (int)TextureResolution);
 }
예제 #11
0
 /// <summary>
 /// Generates a depth texture and sets it at the correct position in the RenderTextures Array.
 /// </summary>
 public void SetDepthTex(TextureCompareMode compareMode = TextureCompareMode.None, Compare compareFunc = Compare.Less)
 {
     RenderTextures[(int)RenderTargetTextureTypes.Depth] = WritableTexture.CreateDepthTex((int)TextureResolution, (int)TextureResolution, compareMode, compareFunc);
 }
예제 #12
0
 /// <summary>
 /// Generates a normal texture and sets it at the correct position in the RenderTextures Array.
 /// </summary>
 public void SetNormalTex()
 {
     RenderTextures[(int)RenderTargetTextureTypes.Normal] = WritableTexture.CreateNormalTex((int)TextureResolution, (int)TextureResolution);
 }