понедельник, 27 июня 2016 г.

Unreal: Debugging materials and shaders example

Here is two tips that may be usefull if you want to debug your shader.

There is many ways to debug shaders in Unreal Engine. For example, you can translate your shader into HLSL code and use any software that you like for debug that. Or install a Renderdoc plugin to capture a whole frame in Unreal's viewport and jump to Renderdoc. You can read more about it here.

But sometimes you don't want to dig deeper when debugging and use a third-party software, especially if you are not going to solve something complicated, but want to debug some value or see what shader does after interpretation in hlsl.




There is a very usefull MaterialNodes for debugging values:
  • DebugScalarValues
  • DebugFloat2Values
  • DebugFloat3Values
  • DebugFloat4Values
and few very specific like
  • DebugBinaryValues-Int
  • DebugBinaryValues-Float 
  • DebugTimeSine
Let's see what  DebugScalarValues is. This node generates a texture with image of a number value passed in. It has four input pins: (names are self-explained)
  • Number is a value that we would like to debug
  • MaximumNumberOfDigits
  • DebugTextlocation
  • UVs


DebugScalarValues
On the screenshot above, you can see that texture was generated, and represents a value, that is kept in constant parameter. The other three nodes acts the same way except DebugBinaryValues-Int and DebugBinaryValues-Float. They generate a binary representation of a given value. You can control size and position of texture by using UVs input and DebugTextLocation. You use a few debug nodes with a properly set UV lerped together, in order to debug a few values.


This nodes are extremely helpfull, if you need to see what is inside of a few variables independent of pixel position. If you are looking for a way to control values for each pixel in a frame, you need more complex solution as was written above.



If you need a hlsl code of your shader you can get it from a window menu:



The source code of common shaders may usually be found in a folder C:\Program Files\Epic Games\4.XX\Engine\Shaders. That could be helpfull, if you are going to write your custom nodes and want to use some functions and parameter, that doesn't have any representation in the graph view. 

Комментариев нет:

Отправить комментарий