This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVRLensFlare.shader
112 lines (90 loc) · 3.58 KB
/
VRLensFlare.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Shader "Hidden/AleVerDes/VR Lens Flare"
{
Properties
{
[MainColor] _BaseColor("BaseColor", Color) = (1,1,1,1)
[MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
_IsLeftEye("IsLeftEye", Float) = 0
_Intensity("Intensity", Float) = 1
}
SubShader
{
Tags
{
"RenderType"="Transparent"
"RenderPipeline"="UniversalRenderPipeline"
}
Blend SrcAlpha One
Pass
{
Tags
{
"LightMode"="UniversalForward"
}
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
float4 _BaseMap_ST;
half4 _BaseColor;
float _IsLeftEye;
float _Intensity;
float4 _FlareColorValue;
float4 _FlareData0; // x: localCos0, y: localSin0, zw: PositionOffsetXY
float4 _FlareData1; // xy: ScreenPos, zw: FlareSize
float4 _EyePositions; // xy: LeftEyeScreenPosition, zw: RightEyeScreenPosition
CBUFFER_END
#define _FlareColor _BaseColor
#define _LocalCos0 _FlareData0.x
#define _LocalSin0 _FlareData0.y
#define _PositionTranslate _FlareData0.zw
#define _ScreenPos _FlareData1.xy
#define _FlareSize _FlareData1.zw
#define _LeftScreenPos _EyePositions.xy
#define _RightScreenPos _EyePositions.zw
Varyings vert(Attributes IN)
{
Varyings OUT;
float2 screenParam = GetScaledScreenParams().xy;
float screenRatio = screenParam.y / screenParam.x;
float4 posPreScale = float4(2.0f, 2.0f, 1.0f, 1.0f) * GetQuadVertexPosition(IN.vertexID) - float4(1.0f, 1.0f, 0.0f, 0.0);
float2 uv = GetQuadTexCoord(IN.vertexID);
uv.x = 1.0f - uv.x;
OUT.texcoord.xy = uv;
posPreScale.xy *= _FlareSize;
float2 local = float2(posPreScale.x * _LocalCos0 - posPreScale.y * _LocalSin0, posPreScale.x * _LocalSin0 + posPreScale.y * _LocalCos0);
local.x *= screenRatio;
#if defined(USING_STEREO_MATRICES)
float2 screenPosition = unity_StereoEyeIndex == 1? _RightScreenPos : _LeftScreenPos;
# else
float2 screenPosition = _ScreenPos;
# endif
OUT.positionCS.xy = local + screenPosition + _PositionTranslate;
OUT.positionCS.z = 1.0f;
OUT.positionCS.w = 1.0f;
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
half4 c = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.texcoord);
c *= _BaseColor;
return c;
}
ENDHLSL
}
}
}