I’ve followed the excelent tutorial by Temaran @ Pixel and Compute shader in UE4, and I want to make some modifications and came across some errors, and need some help. I cannot seem to find any advanced details inside the official docs.
- Current example code in tutorial shows how to create dynamicTexture, assign it to StaticMesh, then pass it on to compute shader (that in turn modify it), and later on passed on to PixelShader for it to draw.
- Current example use a “1st-person shooter” template, that upon OnFire() event, perform ray tracing to hit object, and that chosen as “render target”.
- Make plugin a type of “Actor component” that I can attach to certain objects.
Then the “effect” will auto run (upon “Play”) on the attached material.
- Make the pixel shader write to the texture itself
(In original example compute shader did the texture modify & pixel shader just read & wrote as is…)
Now I want to modify from within the Pixel Shader.
Whats done so far:
- I’ve created ActorComponent plugin, made code that wraps both Vertex Shader & Pixel Shader (similar to demo project provided).
- Upon BeginPlay() event i’m doing GetOwner()->GetComponents,
- Then itearted over, to extract the Material from it, and then extracted the texture from it as well (UTexture).
- Upon Tick() event I enqueue call to ExecutePixelShader with function that perform parameters assign & draw of screen-aligned quad.
Where I’m stuck ?
Whenever I pass the texture I want to draw on, when I reach the code line:
CurrentTexture = CurrentRenderTarget->GetRenderTargetResource()->GetRenderTargetTexture();
I get exception thrown, saying “read access violation”, as if the texture I’m using is “read only” in some way.
My questions are:
- Can someone please “clear” for me from all texture types (FTexture2DRHIRef, UTexture*, UTextureRenderTarget2d*, FShaderResourceViewRHIRef) - what do I need to pass down the shader, in order to be able to read-write from/to it ?
- Do I need to assign staticMesheCompoenent a Dynamic Texture ?
- I’m kinda “lost” with current example in demo, regarding the textures, why does the “FPixelShaderUsageExample” has 3 textures (“CurrentTexture”, “TextureParameter”, “CurrentRenderTarget”) and on top of it a “TextureParameterSRV” ?
Suppose I want just to pass pointer to the texture I want to write onto, does it still require all of the above ?
would deeply appreciate if anyone can help on matter.