Convert float4 (SceneTexure) to Texture?

Hi,

I want to take my SceneTexture:CustomStencil channel, modify it and then I want to apply a gaussian blur. For that blur I use a custom expression with following shader:

float3 val = Texture2DSample(Tex, TexSampler, UV);

//Horizontal blur
for(int i = 0; i<horizontalSize; i++)
{
  val += Texture2DSample(Tex, TexSampler, UV+float2(i*texStepSize,0));
  val += Texture2DSample(Tex, TexSampler, UV+float2(-i*texStepSize,0));
}

//Vertical blur
for(int i = 0; i<verticalSize; i++)
{
  val += Texture2DSample(Tex, TexSampler, UV+float2(0,i*texStepSize));
  val += Texture2DSample(Tex, TexSampler, UV+float2(0,-i*texStepSize));
}

val /= verticalSize*2+horizontalSize*2+1;

return val;

If I use a Texture object, it works, but SceneTexture only outputs float4 values and not Texture2D. How can I get Texture2D out of that float4 values? Is there any converter function?

Had you ever found a way to do this?

I can’t speak on how to include modifications to the CustomStencil channel, but you can attach the SceneTexture node directly to the custom expression using ‘SceneTextureLookup’ to replace ‘Texture2DSample.’ I think I was able to get your blur working in the following code using an index of ‘25.’ More information about SceneTextureLookup and SceneTexture indexes can be found here: Unreal Engine 4 Custom Shaders Tutorial | raywenderlich.com

 float3 val = SceneTextureLookup(GetDefaultSceneTextureUV(Parameters, 25), 25, false);
 
 //Horizontal blur
 for(int i = 0; i<horizontalSize; i++)
 {
   val += SceneTextureLookup(GetDefaultSceneTextureUV(Parameters, 25) + float2(i*texStepSize,0), 25, false);
   val +=  SceneTextureLookup(GetDefaultSceneTextureUV(Parameters, 25) + float2(i*texStepSize,0), 25, false);
 }
 
 //Vertical blur
 for(int i = 0; i<verticalSize; i++)
 {
   val +=  SceneTextureLookup(GetDefaultSceneTextureUV(Parameters, 25) + float2(0,i*texStepSize), 25, false);
   val +=  SceneTextureLookup(GetDefaultSceneTextureUV(Parameters, 25) + float2(0,-i*texStepSize), 25, false);
 }
 
 val /= verticalSize*2+horizontalSize*2+1;
 
 return val;

Another solution, albeit an expensive and impractical one, is to render your modified CustomStencil through a Scene Capture 2D and placing the corresponding Render Target into your material.