Unity HDRP Product Visualizer 1.0.0
Interactive 3D product showcase built with Unity 6 and HDRP
Loading...
Searching...
No Matches
GradientBackground.shader
Go to the documentation of this file.
1Shader "Custom/GradientBackground"
2{
3 Properties
4 {
5 _TopColor ("Top Color", Color) = (0.06, 0.06, 0.18, 1)
6 _BottomColor ("Bottom Color", Color) = (0.01, 0.01, 0.04, 1)
7 _VignetteAmount("Vignette Strength", Range(0,4)) = 1.2
8 _VignetteOffsetY("Vignette Center Y", Range(0,1)) = 0.45
9 }
10
11 HLSLINCLUDE
12 #pragma target 4.5
13 #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
14 ENDHLSL
15
16 SubShader
17 {
18 Tags
19 {
20 "RenderPipeline" = "HDRenderPipeline"
21 "RenderType" = "Opaque"
22 "Queue" = "Geometry-100"
23 }
24
25 // ---- Forward pass -----------------------------------------------
26 Pass
27 {
28 Name "ForwardOnly"
29 Tags { "LightMode" = "ForwardOnly" }
30
31 ZWrite On
32 ZTest LEqual
33 Cull Back
34
35 HLSLPROGRAM
36 #pragma vertex Vert
37 #pragma fragment Frag
38
39 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
40 #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
41
42 CBUFFER_START(UnityPerMaterial)
43 float4 _TopColor;
44 float4 _BottomColor;
45 float _VignetteAmount;
46 float _VignetteOffsetY;
47 CBUFFER_END
48
49 struct Attributes
50 {
51 float3 positionOS : POSITION;
52 float2 uv : TEXCOORD0;
53 UNITY_VERTEX_INPUT_INSTANCE_ID
54 };
55
56 struct Varyings
57 {
58 float4 positionCS : SV_POSITION;
59 float2 uv : TEXCOORD0;
60 UNITY_VERTEX_OUTPUT_STEREO
61 };
62
63 Varyings Vert(Attributes input)
64 {
65 Varyings output;
66 UNITY_SETUP_INSTANCE_ID(input);
67 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
68 output.positionCS = TransformObjectToHClip(input.positionOS);
69 output.uv = input.uv;
70 return output;
71 }
72
73 float4 Frag(Varyings input) : SV_Target
74 {
75 float3 color = lerp(_BottomColor.rgb, _TopColor.rgb, input.uv.y);
76
77 // Radial vignette
78 float2 d = input.uv - float2(0.5, _VignetteOffsetY);
79 d.x *= 0.55; // compensate for wide aspect
80 float vignette = 1.0 - saturate(dot(d, d) * _VignetteAmount * 3.5);
81 color *= lerp(0.25, 1.0, vignette);
82
83 return float4(color, 1.0);
84 }
85 ENDHLSL
86 }
87
88 // ---- Depth prepass -----------------------------------------------
89 Pass
90 {
91 Name "DepthOnly"
92 Tags { "LightMode" = "DepthOnly" }
93
94 ZWrite On
95 ZTest LEqual
96 Cull Back
97 ColorMask 0
98
99 HLSLPROGRAM
100 #pragma vertex Vert
101 #pragma fragment Frag
102
103 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
104 #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
105
106 struct Attributes { float3 positionOS : POSITION; };
107 struct Varyings { float4 positionCS : SV_POSITION; };
108
109 Varyings Vert(Attributes i)
110 {
111 Varyings o;
112 o.positionCS = TransformObjectToHClip(i.positionOS);
113 return o;
114 }
115
116 void Frag(Varyings i) {}
117 ENDHLSL
118 }
119 }
120}