-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathads.glsl
139 lines (102 loc) · 3.97 KB
/
ads.glsl
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "source/render/shaders/layout.glsli"
#include "source/render/shaders/ubo.glsli"
#ifdef _VERTEX_
// Input Variables
layout(location = VertexLayout_Position) in vec3 vertexPosition_modelspace;
layout(location = VertexLayout_Normal) in vec3 vertexNormal;
layout(location = VertexLayout_Colors) in vec4 vertexColor;
layout(location = VertexLayout_Tangent) in vec3 vertexTangent;
layout(location = VertexLayout_TextureCoords) in vec2 vertexUV;
// Output Variables
out vec4 positionViewspace;
out vec3 normalViewspace;
out float linearDepth;
//out vec4 color;
out vec2 uv;
out vec3 tangent;
// Functions
void main()
{
// Get the position and normal in viewspace
normalViewspace = normalize(normalMatrix * vec4(vertexNormal, 0.0)).xyz;
positionViewspace = modelView * vec4(vertexPosition_modelspace, 1.0);
linearDepth = (-positionViewspace.z - frustumNear) * inverseFrustumDistance; // map near..far linearly to 0..1
//color = vertexColor;
uv = vertexUV;
tangent = vertexTangent;
//z = log(z / zn) / log(zf / zn); // logarithmic z
gl_Position = modelViewProjection * vec4(vertexPosition_modelspace, 1.0);
}
#endif
#ifdef _FRAGMENT_
// Uniform Variables
struct Light {
vec4 positionViewspace; // Light position in viewspace
vec3 directionViewspace; // Light spot direction in viewspace
vec3 La; // light color ambient
vec3 Lds; // light color diffuse and specular
float Kc; // attenuation base constant
float Kl; // attenuation linear constant
float Kq; // attenuation quadratic constant
float spotAngleCutoff; // spotlight angle cutoff, dot product comparison (% from 90deg)
float spotEdgeBlendPct; // spotlight edge blend, in % of spot radius
};
struct Material {
vec3 Ma; // Ambient reflectivity
vec3 Md; // Diffuse reflectivity
vec3 Ms; // Specular reflectivity
vec3 Me; // Emissive reflectivity
float shininess; // Specular shininess factor
float metallic; // Metallic determines color of specular highlight
};
uniform Light light;
uniform Material material;
//uniform vec3 diffuseColor;
// these would be used to support models with > 1 channel
// these should go in the per-material uniform buffer
//uniform int diffuseUVChannelIndex0 = 0;
//uniform int diffuseUVChannelIndex1 = 0;
//uniform int diffuseUVChannelIndex2 = 0;
//uniform int diffuseUVChannelIndex3 = 0;
// etc... for each texture
//
//uniform int diffuseVertexColorChannel = 0;
// Input Variables
in vec4 positionViewspace;
in vec3 normalViewspace;
in float linearDepth;
//in vec4 color;
in vec2 uv;
in vec3 tangent;
// Output Variables
layout(location = 0) out vec4 albedoDisplacement;
layout(location = 1) out vec4 eyeSpacePosition;
layout(location = 2) out vec4 normalReflectance;
layout(binding = SamplerBinding_Diffuse1) uniform sampler2D diffuse1;
// Subroutines
subroutine vec3 SurfaceColorSubroutine();
layout(location = SubroutineUniform_SurfaceColor) subroutine uniform SurfaceColorSubroutine getSurfaceColor;
// Functions
#include "source/render/shaders/blinnPhong.glsl"
layout(index = 0) subroutine(SurfaceColorSubroutine) vec3 getSurfaceColorFromTexture()
{
return texture(diffuse1, uv).rgb;
}
layout(index = 1) subroutine(SurfaceColorSubroutine) vec3 getSurfaceColorFromMaterial()
{
return material.Md;
}
float luma(vec3 color) {
return dot(color, vec3(0.299, 0.587, 0.114));
}
void main() {
vec3 surfaceColor = getSurfaceColor();
vec3 lightIntensity = blinnPhongDirectionalLight(positionViewspace, normalViewspace, light.directionViewspace, surfaceColor);
//vec3 lightIntensity = blinnPhongPointLight(positionViewspace, normalViewspace, surfaceColor);
//vec3 lightIntensity = blinnPhongSpotlight(positionViewspace, normalViewspace, surfaceColor);
albedoDisplacement = vec4(lightIntensity, 1.0); //vec4(surfaceColor, 0.0);
eyeSpacePosition = vec4(positionViewspace.xyz, 0.0);
normalReflectance = vec4(normalViewspace, 0.0);
gl_FragDepth = linearDepth;
}
#endif