New Asset iteration

Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
2021-07-01 22:56:24 +02:00
parent 2cfcb0b4a9
commit b4e263e1c2
278 changed files with 532 additions and 16127 deletions
+6
View File
@@ -0,0 +1,6 @@
#ifndef EV_GLSL_CONSTANTS_H
#define EV_GLSL_CONSTANTS_H
#define PI 3.1415926538
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef EV_GLSL_SRGB_OPS_H
#define EV_GLSL_SRGB_OPS_H
vec4 LinearToSRGB(vec4 linearRGB)
{
bvec4 cutoff = lessThan(linearRGB, vec4(0.0031308));
vec4 higher = vec4(1.055)*pow(linearRGB, vec4(1.0/2.4)) - vec4(0.055);
vec4 lower = linearRGB * vec4(12.92);
return mix(higher, lower, cutoff);
}
vec4 SRGBToLinear(vec4 sRGB)
{
bvec4 cutoff = lessThan(sRGB, vec4(0.04045));
vec4 higher = pow((sRGB + vec4(0.055))/vec4(1.055), vec4(2.4));
vec4 lower = sRGB/vec4(12.92);
return mix(higher, lower, cutoff);
}
#endif
+26
View File
@@ -0,0 +1,26 @@
#ifndef EV_GLSL_TYPES_H
#define EV_GLSL_TYPES_H
struct Material {
vec4 baseColor;
uint albedoTexture;
uint normalTexture;
float metallicFactor;
float roughnessFactor;
uint metallicRoughnessTexture;
vec4 emissiveFactor;
uint emissiveTexture;
};
struct Vertex {
vec4 position;
vec4 normal;
vec2 uv[2];
vec4 tangent;
vec4 bitangent; // No longer needed. // TODO remove
};
#endif
+114 -26
View File
@@ -1,16 +1,9 @@
#version 450
#extension GL_EXT_nonuniform_qualifier : require
struct Material {
vec4 baseColor;
uint albedoTexture;
uint normalTexture;
float metallicFactor;
float roughnessFactor;
uint metallicRoughnessTexture;
};
#include <shaders://_builtins/types.glsl>
#include <shaders://_builtins/constants.glsl>
#include <shaders://_builtins/srgb_ops.glsl>
struct Light {
vec3 color;
@@ -21,7 +14,7 @@ struct Scene {
uint lightsCount;
};
vec3 directional_light = vec3(1.0);
vec3 pointLightColor = vec3(1.0, 1.0, 1.0);
layout( push_constant ) uniform constants
{
@@ -45,35 +38,130 @@ layout(set = 2, binding = 3) buffer MaterialBuffer {
layout(set = 2, binding = 4) uniform sampler2D texSampler[];
layout(location = 0) in vec2 uv;
layout(location = 1) smooth in mat3 TBN;
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 uv;
layout(location = 2) in vec3 cameraPos;
layout(location = 3) in vec3 pointLightPos;
layout(location = 4) smooth in mat3 TBN;
layout(location = 0) out vec4 outColor;
void main() {
float DistributionGGX(vec3 N, vec3 H, float a)
{
float a2 = a*a;
float NdotH = max(dot(N,H),0.0);
float NdotH2 = NdotH*NdotH;
float num = a2;
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
denom = PI * denom * denom;
return num/denom;
}
float GeometrySchlickGGX(float NdotV, float k)
{
float nom = NdotV;
float denom = NdotV * (1.0 - k) + k;
return nom / denom;
}
float GeometrySmith(vec3 N, vec3 V, vec3 L, float k)
{
float NdotV = max(dot(N, V), 0.0);
float NdotL = max(dot(N, L), 0.0);
float ggx1 = GeometrySchlickGGX(NdotV, k);
float ggx2 = GeometrySchlickGGX(NdotL, k);
return ggx1 * ggx2;
}
vec3 fresnelSchlick(float cosTheta, vec3 F0)
{
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
}
void main()
{
Material material = MaterialBuffers.materials[ PushConstants.materialBufferIndex ];
vec3 albedo;
float alpha;
if(material.albedoTexture == 0) {
albedo = material.baseColor.xyz;
} else {
vec4 sampledColor = texture(texSampler[material.albedoTexture], uv);
if(sampledColor.a < 0.5) {
discard;
}
albedo = sampledColor.rgb;
alpha = sampledColor.a;
}
vec3 out_normal;
if(material.normalTexture == 0) {
out_normal = TBN[2].xyz;
} else {
vec3 sampled_normal = texture(texSampler[material.normalTexture], uv).rgb;
vec3 sampled_normal = LinearToSRGB(texture(texSampler[material.normalTexture], uv)).rgb;
sampled_normal = 2.0 * sampled_normal - vec3(1.0);
out_normal = normalize(TBN * sampled_normal);
}
float intensity = dot(out_normal, normalize(directional_light)) + 0.2;
vec3 inColor;
if(material.albedoTexture == 0) {
inColor = material.baseColor.xyz;
float metallicFactor;
float roughnessFactor;
float ao;
if(material.metallicRoughnessTexture == 0) {
metallicFactor = material.metallicFactor;
roughnessFactor = material.roughnessFactor;
} else {
inColor = texture(texSampler[material.albedoTexture], uv).xyz;
vec4 sampled_mr = LinearToSRGB(texture(texSampler[material.metallicRoughnessTexture], uv));
ao = sampled_mr.r;
roughnessFactor = sampled_mr.g;
metallicFactor = sampled_mr.b;
}
outColor = vec4(inColor * intensity, 1.0);
// outColor = vec4(inColor, 1.0);
// outColor = vec4(vec3(intensity), 1.0);
// outColor = vec4(out_normal, 1.0);
vec3 emissiveness;
if(material.emissiveTexture == 0) {
emissiveness = vec3(0.0);
} else {
emissiveness = texture(texSampler[material.emissiveTexture], uv).rgb;
emissiveness *= material.emissiveFactor.xyz;
}
float lightIntensity = 2.0;
vec3 V = normalize(cameraPos - position);
vec3 L = normalize(pointLightPos - position);
vec3 H = normalize(V + L);
vec3 N = out_normal;
float distance = length(pointLightPos - position);
float attenuation = 1.0 / (distance * distance);
vec3 radiance = pointLightColor * attenuation * lightIntensity;
vec3 F0 = vec3(0.04);
F0 = mix(F0, albedo, metallicFactor);
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
float NDF = DistributionGGX(N, H, roughnessFactor);
float G = GeometrySmith(N, V, L, roughnessFactor);
vec3 numerator = NDF * G * F;
float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0);
vec3 specular = numerator / max(denominator, 0.001);
vec3 kS = F;
vec3 kD = vec3(1.0) - kS;
kD *= 1.0 - metallicFactor;
float NdotL = max(dot(N, L), 0.0);
vec3 Lo = (kD * albedo / PI + specular) * radiance * NdotL;
vec3 ambient = vec3(0.03) * albedo * ao;
vec3 color = ambient + Lo;
color += emissiveness;
color = color / (color + vec3(1.0));
outColor = vec4(color, alpha);
}
+15 -21
View File
@@ -1,24 +1,7 @@
#version 450
#extension GL_EXT_nonuniform_qualifier : require
struct Material {
vec4 baseColor;
uint albedoTexture;
uint normalTexture;
float metallicFactor;
float roughnessFactor;
uint metallicRoughnessTexture;
};
struct Vertex {
vec4 position;
vec4 normal;
vec2 uv[2];
vec4 tangent;
vec4 bitangent; // No longer needed. // TODO remove
};
#include <shaders://_builtins/types.glsl>
struct Light {
vec3 color;
@@ -60,8 +43,13 @@ layout(set = 2, binding = 2) buffer IndexBuffer {
layout(set = 2, binding = 4) uniform sampler2D texSampler[];
layout(location = 0) out vec2 uv;
layout(location = 1) smooth out mat3 TBN;
layout(location = 0) out vec3 position;
layout(location = 1) out vec2 uv;
layout(location = 2) out vec3 cameraPos;
layout(location = 3) out vec3 lightPos;
layout(location = 4) smooth out mat3 TBN;
vec4 pointLightPos = vec4(0.0, 2.0, 0.0, 1.0);
void main()
{
@@ -79,5 +67,11 @@ void main()
/* vec3 B = normalize(cross(N, T)); */
TBN = mat3(T, B, N);
gl_Position = Camera.projection * Camera.view * PushConstants.render_matrix * vec4(vertex.position.xyz, 1.0);
mat4 VP = Camera.projection * Camera.view;
mat4 MVP = VP * PushConstants.render_matrix;
gl_Position = MVP * vec4(vertex.position.xyz, 1.0);
position = (PushConstants.render_matrix * vec4(vertex.position.xyz, 1.0)).xyz;
cameraPos = inverse(Camera.view)[3].xyz;
/* lightPos = (pointLightPos).xyz; */
lightPos = cameraPos;
}