|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +Shader "Hidden/Visual Profiler" |
| 5 | +{ |
| 6 | + Properties |
| 7 | + { |
| 8 | + [MainColor] _Color("Color", Color) = (1.0, 1.0, 1.0, 1.0) |
| 9 | + _BaseColor("Base Color", Color) = (0.0, 0.0, 0.0, 1.0) |
| 10 | + [MainTexture] _FontTexture("Font", 2D) = "black" {} |
| 11 | + } |
| 12 | + |
| 13 | + SubShader |
| 14 | + { |
| 15 | + Pass |
| 16 | + { |
| 17 | + Name "Main" |
| 18 | + Tags{ "RenderType" = "Opaque" } |
| 19 | + Blend Off |
| 20 | + ZWrite On |
| 21 | + ZTest Always |
| 22 | + Cull Off |
| 23 | + |
| 24 | + CGPROGRAM |
| 25 | + |
| 26 | + #pragma vertex vert |
| 27 | + #pragma fragment frag |
| 28 | + |
| 29 | + // Comment in to help with RenderDoc debugging. |
| 30 | + //#pragma enable_d3d11_debug_symbols |
| 31 | + |
| 32 | + #pragma multi_compile_instancing |
| 33 | + |
| 34 | + #include "UnityCG.cginc" |
| 35 | + |
| 36 | + struct appdata_t |
| 37 | + { |
| 38 | + float4 vertex : POSITION; |
| 39 | + float2 uv : TEXCOORD0; |
| 40 | + UNITY_VERTEX_INPUT_INSTANCE_ID |
| 41 | + }; |
| 42 | + |
| 43 | + struct v2f |
| 44 | + { |
| 45 | + float4 vertex : SV_POSITION; |
| 46 | + fixed3 color : COLOR0; |
| 47 | + fixed3 baseColor : COLOR1; |
| 48 | + float2 uv : TEXCOORD0; |
| 49 | + UNITY_VERTEX_OUTPUT_STEREO |
| 50 | + }; |
| 51 | + |
| 52 | + fixed4 _BaseColor; |
| 53 | + sampler2D _FontTexture; |
| 54 | + float2 _FontScale; |
| 55 | + float4x4 _WindowLocalToWorldMatrix; |
| 56 | + |
| 57 | + UNITY_INSTANCING_BUFFER_START(Props) |
| 58 | + UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color) |
| 59 | + UNITY_DEFINE_INSTANCED_PROP(float4, _UVOffsetScaleX) |
| 60 | + UNITY_INSTANCING_BUFFER_END(Props) |
| 61 | + |
| 62 | + v2f vert(appdata_t v) |
| 63 | + { |
| 64 | + v2f o; |
| 65 | + UNITY_SETUP_INSTANCE_ID(v); |
| 66 | + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
| 67 | + |
| 68 | + float4 uvOffsetScaleX = UNITY_ACCESS_INSTANCED_PROP(Props, _UVOffsetScaleX); |
| 69 | + |
| 70 | + // The verticies on the right (UV 1, x) are scaled in the positive X direction for progress bars. |
| 71 | + float3 localVertex = v.vertex.xyz; |
| 72 | + localVertex.x += v.uv.x * uvOffsetScaleX.z; |
| 73 | + |
| 74 | + // Convert from window (local) to world space. |
| 75 | + // We do this in the vertex shader to avoid having to iterate over all instances each frame. |
| 76 | + o.vertex = mul(UNITY_MATRIX_VP, mul(_WindowLocalToWorldMatrix, mul(unity_ObjectToWorld, float4(localVertex, 1.0)))); |
| 77 | + |
| 78 | + // MaterialPropertyBlocks do not have a SetColorArray method, so we need to do color space conversions ourselves. |
| 79 | +#if defined(UNITY_COLORSPACE_GAMMA) |
| 80 | + o.color = UNITY_ACCESS_INSTANCED_PROP(Props, _Color).rgb; |
| 81 | + o.baseColor = _BaseColor.rgb; |
| 82 | +#else |
| 83 | + o.color = GammaToLinearSpace(UNITY_ACCESS_INSTANCED_PROP(Props, _Color).rgb); |
| 84 | + o.baseColor = GammaToLinearSpace(_BaseColor.rgb); |
| 85 | +#endif |
| 86 | + |
| 87 | + // Scale and offset UVs. |
| 88 | + o.uv = (v.uv * _FontScale) + uvOffsetScaleX.xy; |
| 89 | + |
| 90 | + return o; |
| 91 | + } |
| 92 | + |
| 93 | + fixed4 frag(v2f i) : SV_Target |
| 94 | + { |
| 95 | + fixed4 font = tex2D(_FontTexture, i.uv); |
| 96 | + fixed alpha = font.r; |
| 97 | + return fixed4((i.baseColor * (1.0 - alpha)) + (font.rgb * i.color * alpha), 1.0); |
| 98 | + } |
| 99 | + |
| 100 | + ENDCG |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments