In Visual Studio 2012, Microsoft has indroduced Graphics Debugger, you can use it to capture a frame from platforms like Unity Editor, Windows Standalone or Universal Windows Platform.
It’s recommended to use Visual Studio 2013, as it contains several fixes for Graphics Debugger.
Note: Unity Editor contains multiple child windows inside, this may cause Graphics Debugger to capture frame from incorrect window, to ensure that correct window will be captured, check ‘Maximize on Play’ tab, and hit Play button before capturing, but even then there’s no guarantee that the correct window will be captured, that’s why it’s not recommended to use Unity Editor for frame capturing.
Note: Frames can only be captured if Unity is running under DirectX 11, you can select DirectX 11 from Player Settings (PC, Mac & LinuxStandalone) -> Other Settings.
Steps to capture frame from Unity Editor or Windows Standalone:
Launch Visual Studio 2013
Go to File->New->Project->Visual C++->Empty Project
Go to Project->Properties->Configuration Properties->Debugging
In Command field, replace $(TargetPath) with path to Unity Editor or Windows Standalone, for ex., C:\MyApp\MyApp.exe
(Optional) In Command Arguments specify -force-d3d11, this will force Windows Standalone or Unity Editor to run under DirectX 11
You’re ready to run Graphics Debugger, go to Debug->Graphics->Start Diagnostics
If everything is configured correctly you should see “Use ‘Print Screen’ key to capture a frame” message in top left corner of the application. See screenshot below.
Steps to debug DirectX 11 shader:
To debug a shader you have to compile with debug symbols, to do that, you have insert #pragma enable_d3d11_debug_symbols
Let’s try to create a basic example:
Create a new Unity project
Create a new shader in Assets window
Insert #pragma enable_d3d11_debug_symbols
Create a new material and select your custom shader
If everything done correctly, you should see the following captured frame, right click and select Pixel History and select the pixel of an object which has your custom shader assigned.
Click the play button next to the Vertex Shader (circled in red in screenshot above), you should be able to debug vertex shader.
Universal Windows Platform
For Universal Windows Platform, it’s a bit easier because you don’t need to create a dummy Visual Studio project as the project is already created by Unity.
Steps for capturing the frame and shader debugging are the same like for Unity Editor or Windows Standalone.
Alternative shader debugging techniques
In the Unity Editor, you can also use RenderDoc to debug shaders, by capturing the scene from within the editor and debugging in the standalone tool.
Did you find this page useful? Please give it a rating:
Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thanks for helping to make the Unity documentation better!