Merge branch 'master' into gltfskinning

This commit is contained in:
Sascha Willems 2020-05-23 19:54:58 +02:00
commit 85106a6bb2
310 changed files with 11430 additions and 58 deletions

Binary file not shown.

Binary file not shown.

View file

@ -2,12 +2,17 @@
layout (binding = 1) uniform samplerCube samplerEnvMap;
layout (binding = 0) uniform UBO {
mat4 projection;
mat4 modelview;
mat4 inverseModelview;
} ubo;
layout (location = 0) in vec3 inUVW;
layout (location = 1) in vec3 inPos;
layout (location = 2) in vec3 inNormal;
layout (location = 3) in vec3 inViewVec;
layout (location = 4) in vec3 inLightVec;
layout (location = 5) in mat4 inInvModelView;
layout (location = 0) out vec4 outColor0;
layout (location = 1) out vec4 outColor1;
@ -17,37 +22,37 @@ layout (constant_id = 0) const int type = 0;
#define PI 3.1415926
#define TwoPI (2.0 * PI)
layout (binding = 2) uniform UBO {
layout (binding = 2) uniform Exposure {
float exposure;
} ubo;
} exposure;
void main()
void main()
{
vec4 color;
vec3 wcNormal;
switch (type) {
case 0: // Skybox
case 0: // Skybox
{
vec3 normal = normalize(inUVW);
color = texture(samplerEnvMap, normal);
}
break;
case 1: // Reflect
{
vec3 wViewVec = mat3(inInvModelView) * normalize(inViewVec);
vec3 wViewVec = mat3(ubo.inverseModelview) * normalize(inViewVec);
vec3 normal = normalize(inNormal);
vec3 wNormal = mat3(inInvModelView) * normal;
vec3 wNormal = mat3(ubo.inverseModelview) * normal;
float NdotL = max(dot(normal, inLightVec), 0.0);
vec3 eyeDir = normalize(inViewVec);
vec3 eyeDir = normalize(inViewVec);
vec3 halfVec = normalize(inLightVec + eyeDir);
float NdotH = max(dot(normal, halfVec), 0.0);
float NdotV = max(dot(normal, eyeDir), 0.0);
float NdotH = max(dot(normal, halfVec), 0.0);
float NdotV = max(dot(normal, eyeDir), 0.0);
float VdotH = max(dot(eyeDir, halfVec), 0.0);
// Geometric attenuation
float NH2 = 2.0 * NdotH;
float g1 = (NH2 * NdotV) / VdotH;
@ -61,27 +66,27 @@ void main()
float fresnel = pow(1.0 - VdotH, 5.0);
fresnel *= (1.0 - F0);
fresnel += F0;
float spec = (fresnel * geoAtt) / (NdotV * NdotL * 3.14);
color = texture(samplerEnvMap, reflect(-wViewVec, wNormal));
color = texture(samplerEnvMap, reflect(-wViewVec, wNormal));
color = vec4(color.rgb * NdotL * (k + spec * (1.0 - k)), 1.0);
}
break;
case 2: // Refract
case 2: // Refract
{
vec3 wViewVec = mat3(inInvModelView) * normalize(inViewVec);
vec3 wNormal = mat3(inInvModelView) * inNormal;
color = texture(samplerEnvMap, refract(-wViewVec, wNormal, 1.0/1.6));
vec3 wViewVec = mat3(ubo.inverseModelview) * normalize(inViewVec);
vec3 wNormal = mat3(ubo.inverseModelview) * inNormal;
color = texture(samplerEnvMap, refract(-wViewVec, wNormal, 1.0/1.6));
}
break;
}
// Color with manual exposure into attachment 0
outColor0.rgb = vec3(1.0) - exp(-color.rgb * ubo.exposure);
outColor0.rgb = vec3(1.0) - exp(-color.rgb * exposure.exposure);
// Bright parts for bloom into attachment 1
float l = dot(outColor0.rgb, vec3(0.2126, 0.7152, 0.0722));

Binary file not shown.

View file

@ -8,6 +8,7 @@ layout (constant_id = 0) const int type = 0;
layout (binding = 0) uniform UBO {
mat4 projection;
mat4 modelview;
mat4 inverseModelview;
} ubo;
layout (location = 0) out vec3 outUVW;
@ -15,14 +16,13 @@ layout (location = 1) out vec3 outPos;
layout (location = 2) out vec3 outNormal;
layout (location = 3) out vec3 outViewVec;
layout (location = 4) out vec3 outLightVec;
layout (location = 5) out mat4 outInvModelView;
out gl_PerVertex
out gl_PerVertex
{
vec4 gl_Position;
};
void main()
void main()
{
outUVW = inPos;
@ -37,11 +37,9 @@ void main()
break;
}
outPos = vec3(ubo.modelview * vec4(inPos, 1.0));
outNormal = mat3(ubo.modelview) * inNormal;
outInvModelView = inverse(ubo.modelview);
outNormal = mat3(ubo.modelview) * inNormal;
vec3 lightPos = vec3(0.0f, -5.0f, 5.0f);
outLightVec = lightPos.xyz - outPos.xyz;
outViewVec = -outPos.xyz;
outViewVec = -outPos.xyz;
}

Binary file not shown.

View file

@ -2,21 +2,28 @@
layout (binding = 1) uniform samplerCube samplerColor;
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
mat4 invModel;
float lodBias;
} ubo;
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNormal;
layout (location = 2) in float inLodBias;
layout (location = 3) in vec3 inViewVec;
layout (location = 4) in vec3 inLightVec;
layout (location = 5) in mat4 inInvModelView;
layout (location = 0) out vec4 outFragColor;
void main()
void main()
{
vec3 cI = normalize (inPos);
vec3 cR = reflect (cI, normalize(inNormal));
cR = vec3(inInvModelView * vec4(cR, 0.0));
cR = vec3(ubo.invModel * vec4(cR, 0.0));
cR.x *= -1.0;
vec4 color = texture(samplerColor, cR, inLodBias);
@ -28,5 +35,5 @@ void main()
vec3 ambient = vec3(0.5) * color.rgb;
vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0);
vec3 specular = pow(max(dot(R, V), 0.0), 16.0) * vec3(0.5);
outFragColor = vec4(ambient + diffuse * color.rgb + specular, 1.0);
outFragColor = vec4(ambient + diffuse * color.rgb + specular, 1.0);
}

View file

@ -3,10 +3,11 @@
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNormal;
layout (binding = 0) uniform UBO
layout (binding = 0) uniform UBO
{
mat4 projection;
mat4 model;
mat4 invModel;
float lodBias;
} ubo;
@ -15,24 +16,21 @@ layout (location = 1) out vec3 outNormal;
layout (location = 2) out float outLodBias;
layout (location = 3) out vec3 outViewVec;
layout (location = 4) out vec3 outLightVec;
layout (location = 5) out mat4 outInvModelView;
out gl_PerVertex
out gl_PerVertex
{
vec4 gl_Position;
};
void main()
void main()
{
gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
outPos = vec3(ubo.model * vec4(inPos, 1.0));
outNormal = mat3(ubo.model) * inNormal;
outNormal = mat3(ubo.model) * inNormal;
outLodBias = ubo.lodBias;
outInvModelView = inverse(ubo.model);
vec3 lightPos = vec3(0.0f, -5.0f, 5.0f);
outLightVec = lightPos.xyz - outPos.xyz;
outViewVec = -outPos.xyz;
outViewVec = -outPos.xyz;
}