Unity调试shader
发表于2018-03-01
为了方便大家给模型做效果,就给大家准备了两款调试unity的shader的工具,方便大家提升效率,这两个工具分别是Frame Debugger和RenderDoc。
过渡色shader
Shader "Unlit/NewVerticesUnlitShader" { Properties { _MainTex ("Texture", 2D) = "white" {} _TopColor("Top Color",Color)=(1,1,1,1) _CenterColor("Center Color",Color)=(1,1,1,1) _BottomColor("Bottom Color",Color)=(1,1,1,1) } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fog #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; UNITY_FOG_COORDS(1) float4 vertex : SV_POSITION; fixed4 color : COLOR; }; sampler2D _MainTex; float4 _MainTex_ST; fixed4 _TopColor; fixed4 _CenterColor; fixed4 _BottomColor; v2f vert (appdata v) { v2f o; float3 dir = normalize(v.vertex); float lp; if (dir.y>0) { lp = (1 - dir.y) /1; o.color = lerp(_TopColor, _CenterColor, lp); } else { lp =(1+ dir.y) / 1; o.color = lerp(_CenterColor, _BottomColor, lp); } o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); UNITY_TRANSFER_FOG(o,o.vertex); return o; } fixed4 frag (v2f i) : SV_Target { //// sample the texture //fixed4 col = tex2D(_MainTex, i.uv); //// apply fog //UNITY_APPLY_FOG(i.fogCoord, col); //return col; return i.color; } ENDCG } } }
Frame Debugger
Frame Debugger是unity自带的真调试工具
1. 运行场景
2. 点击Window/Frame Debugger
3. 点击Enable,就可以查看渲染物体的ShaderProperties
4. 截图

RenderDoc
1.下载安装RenderDoc:https://renderdoc.org/
2.重启unity编辑器,右键点击Game窗口load renderdoc

3.运行场景,点击Game窗口右边的人头小图标,即可截图当前帧的数据

4.在RenderDoc右键open当前的截图

5.找到我们想要查看shader的那一块,再点击Vertex Shader,发现这里shader的名称正好是我们需要查看的shader

6.点击Mesh Output就能看见模型实际和渲染很详细的数据
