x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Depth texture using unreal shader

Hi, I have created a render texture which I can visualize using the view menu from UE editor. Currently, the texture is a single solid color. I want to populate the texture with pixel depths using unreal shader. I am aware that the depth buffer is already there, but this exercise is going to help me understand the entire shader pipeline in UE. Is there a way to get the depth values from the shader dumped onto a texture ? I have the following vertex shader.

 struct FTriangleIDPassVSToPS
 {
     float4 Position : SV_POSITION;
 };

 #define FTriangleIDPassVSOutput FTriangleIDPassVSToPS
 void MainVS(FVertexFactoryInput Input,
     out FTriangleIDPassVSOutput Output
 #if USE_GLOBAL_CLIP_PLANE
     , out float OutGlobalClipPlaneDistance : SV_ClipDistance
 #endif
 )
 {
     ResolvedView = ResolveView();
 
     FVertexFactoryIntermediates VFIntermediates = GetVertexFactoryIntermediates(Input);
     float4 WorldPos = VertexFactoryGetWorldPosition(Input, VFIntermediates);
 
     float3x3 TangentToLocal = VertexFactoryGetTangentToLocal(Input, VFIntermediates);
     FMaterialVertexParameters VertexParameters = GetMaterialVertexParameters(Input, VFIntermediates, WorldPos.xyz, TangentToLocal);
 
     // Isolate instructions used for world position offset
     // As these cause the optimizer to generate different position calculating instructions in each pass, resulting in self-z-fighting.
     // This is only necessary for shaders used in passes that have depth testing enabled.
     ISOLATE
     {
         WorldPos.xyz += GetMaterialWorldPositionOffset(VertexParameters);
     }
 
     ISOLATE
     {
         float4 RasterizedWorldPosition = VertexFactoryGetRasterizedWorldPosition(Input, VFIntermediates, WorldPos);
     #if ODS_CAPTURE
         float3 ODS = OffsetODS(RasterizedWorldPosition.xyz, ResolvedView.TranslatedWorldCameraOrigin.xyz, ResolvedView.StereoIPD);
         Output.Position = INVARIANT(mul(float4(RasterizedWorldPosition.xyz + ODS, 1.0), ResolvedView.TranslatedWorldToClip));
     #else
         Output.Position = INVARIANT(mul(RasterizedWorldPosition, ResolvedView.TranslatedWorldToClip));
     #endif
     }
 }

I understand the Output gives the clip space position of the vertex. In the pixel shader, should I do something like ?

 void MainPS(FTriangleIDPassVSToPS Output, out uint OutColor : SV_Target0)
 {
     OutColor = Output.Position.z / Output.Position.w;
 }

This doesn't give the expected result. Maybe I am missing something. Any kind of help is appreciated. Thanks.

Product Version: UE 4.20
Tags:
more ▼

asked Sep 19 '18 at 12:25 PM in Rendering

avatar image

sud7052
16 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question