diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-10-17 21:44:48 +1100 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-10-17 21:44:48 +1100 |
commit | bda9a0d8b503e6ed75daafd1dd288a28590a8df6 (patch) | |
tree | 2dbe59563d5f4749bdee180b530b181a68b78346 | |
parent | 70175cfce551a6b534771bd2b1dea6cfb417be1f (diff) |
remove old shaders
30 files changed, 32 insertions, 963 deletions
diff --git a/assets/shaders/blinn_phong.frag b/assets/shaders/blinn_phong.frag deleted file mode 100644 index 267c71b..0000000 --- a/assets/shaders/blinn_phong.frag +++ /dev/null @@ -1,97 +0,0 @@ -#version 430 core -out vec4 FragColor; - -// A Blinn-Phong material with textures for diffuse and specular -// lighting maps and a numeric shininess factor. -struct Material { - sampler2D diffuse; - sampler2D specular; - float shininess; -}; - -struct DirLight { - vec3 direction; - vec3 ambient; - vec3 diffuse; - vec3 specular; -}; - -struct PointLight { - vec3 position; - // fall off properties - float constant; - float linear; - float quadratic; - - vec3 ambient; - vec3 diffuse; - vec3 specular; -}; - -in VS_OUT { - vec3 FragPos; - vec3 Normal; - vec2 TexCoords; - // vec4 FragPosLightSpace; - vec4 Color; -} fs_in; - -// --- Uniforms -#define NUM_POINT_LIGHTS 4 -uniform vec3 viewPos; -uniform Material material; -uniform DirLight dirLight; -uniform PointLight pointLights[NUM_POINT_LIGHTS]; - -// --- Function prototypes -vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir); -vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir); - -void main() { - vec3 norm = normalize(fs_in.Normal); - vec3 viewDir = normalize(viewPos - fs_in.FragPos); - - vec3 result = CalcDirLight(dirLight, norm, viewDir); - for (int i = 0; i < 4; i++) { - result += CalcPointLight(pointLights[i], norm, fs_in.FragPos, viewDir); - } - -// FragColor = vec4(result, 1.0); - FragColor = fs_in.Color + 0.5; -} - -vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir) -{ - vec3 lightDir = normalize(-light.direction); - // diffuse shading - float diff = max(dot(normal, lightDir), 0.0); - // specular shading - vec3 reflectDir = reflect(-lightDir, normal); - float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); - // combine result - vec3 ambient = light.ambient * vec3(texture(material.diffuse, fs_in.TexCoords)); - vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, fs_in.TexCoords)); - vec3 specular = light.specular * spec * vec3(texture(material.specular, fs_in.TexCoords)); - return (ambient + diffuse + specular); -} - -vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir) -{ - vec3 lightDir = normalize(light.position - fragPos); - // diffuse - float diff = max(dot(normal, lightDir), 0.0); - // specular - vec3 reflectDir = reflect(-lightDir, normal); - float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); - // attentuation - float distance = length(light.position - fragPos); - float attentuation = 1.0 / (light.constant + light.linear * distance * light.quadratic * (distance * distance)); - // result - vec3 ambient = light.ambient * vec3(texture(material.diffuse, fs_in.TexCoords)); - vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, fs_in.TexCoords)); - vec3 specular = light.specular * spec * vec3(texture(material.specular, fs_in.TexCoords)); - ambient *= attentuation; - diffuse *= attentuation; - specular *= attentuation; - return (ambient + diffuse + specular); -} diff --git a/assets/shaders/blinn_phong.vert b/assets/shaders/blinn_phong.vert deleted file mode 100644 index 18609b7..0000000 --- a/assets/shaders/blinn_phong.vert +++ /dev/null @@ -1,37 +0,0 @@ -#version 410 core - -struct Uniforms { - mat4 model; - mat4 view; - mat4 projection; -}; - -uniform Uniforms ubo; - -// Inputs -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inTexCoords; - -// uniform mat4 model; -// uniform mat4 view; -// uniform mat4 projection; -// uniform mat4 lightSpaceMatrix; - -// Output -out VS_OUT { - vec3 FragPos; - vec3 Normal; - vec2 TexCoords; - // vec4 FragPosLightSpace; - vec4 Color; -} vs_out; - -void main() { - vs_out.FragPos = vec3(ubo.model * vec4(inPos, 1.0)); - vs_out.Normal = inNormal; - vs_out.TexCoords = inTexCoords; - // vs_out.FragPosLightSpace = lightSpaceMatrix * vec4(vs_out.FragPos, 1.0); - vs_out.Color = vec4(1.0); - gl_Position = ubo.projection * ubo.view * ubo.model * vec4(inPos, 1.0); -} diff --git a/assets/shaders/cube.frag b/assets/shaders/cube.frag deleted file mode 100644 index a405e6a..0000000 --- a/assets/shaders/cube.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 410 - -layout(location = 0) in vec3 fragColor; -layout(location = 1) in vec2 fragTexCoord; - - uniform sampler2D texSampler; - -layout(location = 0) out vec4 outColor; - -void main() { - outColor = texture(texSampler, fragTexCoord); // vec4(fragTexCoord, 0.0); - // outColor = vec4(1.0); -} diff --git a/assets/shaders/cube.metal b/assets/shaders/cube.metal new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/assets/shaders/cube.metal diff --git a/assets/shaders/cube.vert b/assets/shaders/cube.vert deleted file mode 100644 index cd345f6..0000000 --- a/assets/shaders/cube.vert +++ /dev/null @@ -1,21 +0,0 @@ -#version 410 core - -uniform Matrices { - mat4 model; - mat4 view; - mat4 proj; -} ubo; - -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec3 inNormal; -layout(location = 2) in vec2 inTexCoords; - -layout(location = 0) out vec3 fragColor; -layout(location = 1) out vec2 fragTexCoord; - -void main() { - gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); - // gl_Position = vec4(inPosition, 1.0); - fragColor = abs(inNormal); - fragTexCoord = inTexCoords; -} diff --git a/assets/shaders/debug_quad.frag b/assets/shaders/debug_quad.frag deleted file mode 100644 index 877b26a..0000000 --- a/assets/shaders/debug_quad.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 410 core -out vec4 FragColor; - -in vec2 TexCoords; - -uniform sampler2D depthMap; - -void main() -{ - float depthValue = texture(depthMap, TexCoords).r; - FragColor = vec4(vec3(depthValue), 1.0); // orthographic - //FragColor = vec4(1.0); -} diff --git a/assets/shaders/debug_quad.vert b/assets/shaders/debug_quad.vert deleted file mode 100644 index 8b8201c..0000000 --- a/assets/shaders/debug_quad.vert +++ /dev/null @@ -1,13 +0,0 @@ -#version 410 core -layout (location = 0) in vec3 inPosition; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inTexCoords; - -out vec2 TexCoords; - -void main() -{ - TexCoords = inTexCoords; - vec2 xy = inPosition.xz; - gl_Position = vec4(xy, 0.0, 1.0); -} diff --git a/assets/shaders/grid.frag b/assets/shaders/grid.frag deleted file mode 100644 index 6cf8a7c..0000000 --- a/assets/shaders/grid.frag +++ /dev/null @@ -1,60 +0,0 @@ -#version 410 core - -out vec4 FragColor; - -in float near; //0.01 -in float far; //100 -in vec3 nearPoint; -in vec3 farPoint; -in mat4 fragView; -in mat4 fragProj; - -// void main() { -// // FragColor = vec4(1.0, 0.0, 0.0, 1.0); -// float t = -nearPoint.y / (farPoint.y - nearPoint.y); -// if (t > 0) { -// FragColor = vec4(1.0, 0.0, 0.0, 1.0); -// } else { -// FragColor = vec4(0.0); -// } -// // FragColor = vec4(1.0, 0.0, 0.0, 1.0 * float(t > 0)); // opacity = 1 when t > 0, opacity = 0 otherwise -// } - -vec4 grid(vec3 fragPos3D, float scale, bool drawAxis) { - vec2 coord = fragPos3D.xz * scale; - vec2 derivative = fwidth(coord); - vec2 grid = abs(fract(coord - 0.5) - 0.5) / derivative; - float line = min(grid.x, grid.y); - float minimumz = min(derivative.y, 1); - float minimumx = min(derivative.x, 1); - vec4 color = vec4(0.2, 0.2, 0.2, 1.0 - min(line, 1.0)); - // z axis - if(fragPos3D.x > -0.1 * minimumx && fragPos3D.x < 0.1 * minimumx) - color.z = 1.0; - // x axis - if(fragPos3D.z > -0.1 * minimumz && fragPos3D.z < 0.1 * minimumz) - color.x = 1.0; - return color; -} -float computeDepth(vec3 pos) { - vec4 clip_space_pos = fragProj * fragView * vec4(pos.xyz, 1.0); - return (clip_space_pos.z / clip_space_pos.w); -} -float computeLinearDepth(vec3 pos) { - vec4 clip_space_pos = fragProj * fragView * vec4(pos.xyz, 1.0); - float clip_space_depth = (clip_space_pos.z / clip_space_pos.w) * 2.0 - 1.0; // put back between -1 and 1 - float linearDepth = (2.0 * near * far) / (far + near - clip_space_depth * (far - near)); // get linear value between 0.01 and 100 - return linearDepth / far; // normalize -} -void main() { - float t = -nearPoint.y / (farPoint.y - nearPoint.y); - vec3 fragPos3D = nearPoint + t * (farPoint - nearPoint); - - gl_FragDepth = computeDepth(fragPos3D); - - float linearDepth = computeLinearDepth(fragPos3D); - float fading = max(0, (0.5 - linearDepth)); - - FragColor = (grid(fragPos3D, 10, true) + grid(fragPos3D, 1, true))* float(t > 0); // adding multiple resolution for the grid - FragColor.a *= fading; -}
\ No newline at end of file diff --git a/assets/shaders/grid.vert b/assets/shaders/grid.vert deleted file mode 100644 index 592cbfc..0000000 --- a/assets/shaders/grid.vert +++ /dev/null @@ -1,42 +0,0 @@ -#version 410 core - -uniform Camera { - mat4 view; - mat4 proj; - vec4 viewPos; -} cam; - -out vec3 nearPoint; -out vec3 farPoint; -out float near; -out float far; -out mat4 fragView; -out mat4 fragProj; - -// Grid position are in xy clipped space -vec3 gridPlane[6] = vec3[]( - vec3(1, 1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0), - vec3(-1, -1, 0), vec3(1, 1, 0), vec3(1, -1, 0) -); - -vec3 UnprojectPoint(float x, float y, float z, mat4 view, mat4 projection) { - mat4 viewInv = inverse(view); - mat4 projInv = inverse(projection); - vec4 unprojectedPoint = viewInv * projInv * vec4(x, y, z, 1.0); - return unprojectedPoint.xyz / unprojectedPoint.w; -} - -// normal vertex projection -void main() { - // gl_Position = cam.proj * cam.view * vec4(gridPlane[gl_VertexID].xyz, 1.0); - vec3 p = gridPlane[gl_VertexID].xyz; - nearPoint = UnprojectPoint(p.x, p.y, -1.0, cam.view, cam.proj).xyz; // unprojecting on the near plane - farPoint = UnprojectPoint(p.x, p.y, 1.0, cam.view, cam.proj).xyz; // unprojecting on the far plane - - fragView = cam.view; - fragProj = cam.proj; - near = 0.01; - far = 100.0; - - gl_Position = vec4(p, 1.0); // using directly the clipped coordinates -}
\ No newline at end of file diff --git a/assets/shaders/immdraw.frag b/assets/shaders/immdraw.frag deleted file mode 100644 index 9cb214f..0000000 --- a/assets/shaders/immdraw.frag +++ /dev/null @@ -1,9 +0,0 @@ -#version 410 core - -out vec4 FragColor; - -in vec4 aColour; - -void main() { - FragColor = aColour; -} diff --git a/assets/shaders/immdraw.vert b/assets/shaders/immdraw.vert deleted file mode 100644 index ee9e7ca..0000000 --- a/assets/shaders/immdraw.vert +++ /dev/null @@ -1,23 +0,0 @@ -#version 410 core - -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec3 inNormal; -layout(location = 2) in vec2 inTexCoords; - -uniform Camera { - mat4 view; - mat4 proj; - vec4 viewPos; -} cam; - -uniform ImmUniforms { - mat4 model; - vec4 colour; -} imm; - -out vec4 aColour; - -void main() { - aColour = imm.colour; - gl_Position = cam.proj * cam.view * imm.model * vec4(inPosition, 1.0); -} diff --git a/assets/shaders/object.frag b/assets/shaders/object.frag deleted file mode 100644 index fa50fcf..0000000 --- a/assets/shaders/object.frag +++ /dev/null @@ -1,15 +0,0 @@ -#version 450 -#extension GL_ARB_separate_shader_objects : enable - -layout(location = 0) in vec3 in_position; -layout(location = 1) in vec3 in_normal; -layout(location = 2) in vec2 in_tex_coord; - -layout(set = 0, binding = 1) uniform sampler2D texSampler; - -layout(location = 0) out vec4 out_color; - -void main() { - // out_color = vec4(1.0); - out_color = texture(texSampler, in_tex_coord); -}
\ No newline at end of file diff --git a/assets/shaders/object.vert b/assets/shaders/object.vert deleted file mode 100644 index 23c0ffb..0000000 --- a/assets/shaders/object.vert +++ /dev/null @@ -1,29 +0,0 @@ -#version 450 -#extension GL_ARB_separate_shader_objects : enable - -layout(location = 0) in vec3 in_position; -layout(location = 1) in vec3 in_normal; -layout(location = 2) in vec2 in_tex_coord; - -layout(location = 0) out vec3 out_position; -layout(location = 1) out vec3 out_normal; -layout(location = 2) out vec2 out_tex_coord; - -layout(set = 0, binding = 0) uniform global_object_uniform { - mat4 projection; - mat4 view; -} -global_ubo; - -layout(push_constant) uniform push_constants { - mat4 model; // 64 bytes -} -u_push_constants; - -void main() { - gl_Position = global_ubo.projection * global_ubo.view * u_push_constants.model * - vec4(in_position.x, in_position.y, in_position.z, 1.0); - out_position = in_position; - out_normal = in_normal; - out_tex_coord = in_tex_coord; -}
\ No newline at end of file diff --git a/assets/shaders/pbr_params.frag b/assets/shaders/pbr_params.frag deleted file mode 100644 index 7dbdc9d..0000000 --- a/assets/shaders/pbr_params.frag +++ /dev/null @@ -1,126 +0,0 @@ -#version 410 core - -out vec4 FragColor; - -layout(location = 0) in vec3 fragWorldPos; -layout(location = 1) in vec3 fragNormal; -layout(location = 2) in vec2 fragTexCoords; - -struct PointLight { - vec4 position; - vec4 color; -}; - -// --- Uniforms -// Material properties -uniform PBR_Params { - uniform vec3 albedo; - uniform float metallic; - uniform float roughness; - uniform float ao; -} pbr; -// Lights data -#define NUM_POINT_LIGHTS 4 -uniform Scene_Lights { - PointLight pointLights[NUM_POINT_LIGHTS]; - vec4 viewPos; -} scene; - -const float PI = 3.14; - -// Forward declarations -vec3 fresnelSchlick(float cosTheta, vec3 F0); -float DistributionGGX(vec3 N, vec3 H, float roughness); -float GeometrySchlickGGX(float NdotV, float roughness); -float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness); - -void main() { - vec3 norm = normalize(fragNormal); // N - vec3 N = norm; - vec3 viewDir = normalize(vec3(scene.viewPos) - fragWorldPos); // V - vec3 V = viewDir; - - vec3 F0 = vec3(0.04); - F0 = mix(F0, pbr.albedo, pbr.metallic); - - vec3 Lo = vec3(0.0); - for (int i = 0; i < 4; ++i) { - vec3 lightVec = normalize(vec3(scene.pointLights[i].position) - fragWorldPos); // L - vec3 L = lightVec; - vec3 halfway = normalize(viewDir + lightVec); // H - vec3 H = halfway; - float distance = length(vec3(scene.pointLights[i].position) - fragWorldPos); - float attenuation = 1.0 / (distance * distance); - vec3 radiance = vec3(scene.pointLights[i].color) * attenuation; - - // cook-torrance brdf - float NDF = DistributionGGX(norm, halfway, pbr.roughness); - float G = GeometrySmith(norm, viewDir, lightVec, pbr.roughness); - // vec3 F = fresnelSchlick(max(dot(halfway, viewDir), 0.0), F0); - vec3 F = fresnelSchlick(clamp(dot(H, V), 0.0, 1.0), F0); - - vec3 numerator = NDF * G * F; - float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.0001; - vec3 specular = numerator / denominator; - - vec3 kS = F; - - vec3 kD = vec3(1.0) - kS; - kD *= 1.0 - pbr.metallic; - - // add to outgoing radiance Lo - float NdotL = max(dot(N, L), 0.0); - Lo += (kD * pbr.albedo / PI + specular) * radiance * NdotL; - // Lo += radiance; - } - - vec3 ambient = vec3(0.03) * pbr.albedo * pbr.ao; - vec3 color = ambient + Lo; //ambient + Lo; - - color = color / (color + vec3(1.0)); - color = pow(color, vec3(1.0/2.2)); - - FragColor = vec4(color, 1.0); - // FragColor = vec4(scene.pointLights[0].position); - //FragColor = vec4(fragNormal, 1.0); - // FragColor = vec4(pbr.metallic, pbr.roughness, pbr.ao, 1.0); - // FragColor = scene.viewPos; -} - -/* The below are from https://learnopengl.com/PBR/Lighting */ - -vec3 fresnelSchlick(float cosTheta, vec3 F0) { - return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0); -} -float DistributionGGX(vec3 N, vec3 H, float roughness) { - float a = roughness*roughness; - 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 roughness) -{ - float r = (roughness + 1.0); - float k = (r*r) / 8.0; - - float num = NdotV; - float denom = NdotV * (1.0 - k) + k; - - return num / denom; -} -float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) -{ - float NdotV = max(dot(N, V), 0.0); - float NdotL = max(dot(N, L), 0.0); - float ggx2 = GeometrySchlickGGX(NdotV, roughness); - float ggx1 = GeometrySchlickGGX(NdotL, roughness); - - return ggx1 * ggx2; -} diff --git a/assets/shaders/pbr_params.vert b/assets/shaders/pbr_params.vert deleted file mode 100644 index 01d0cfe..0000000 --- a/assets/shaders/pbr_params.vert +++ /dev/null @@ -1,27 +0,0 @@ -#version 410 core - -// Vertex attributes -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec3 inNormal; -layout(location = 2) in vec2 inTexCoords; - -// Uniforms -uniform MVP_Matrices { - mat4 model; // TODO: make model a push constant/raw uniform - mat4 view; - mat4 proj; -} mvp; - -// Outputs -layout(location = 0) out vec3 fragWorldPos; -layout(location = 1) out vec3 fragNormal; -layout(location = 2) out vec2 fragTexCoords; - -void main() { - fragWorldPos = vec3(mvp.model * vec4(inPosition, 1.0)); - fragNormal = mat3(transpose(inverse(mvp.model))) * inNormal; - - fragTexCoords = inTexCoords; - - gl_Position = mvp.proj * mvp.view * mvp.model * vec4(inPosition, 1.0); -} diff --git a/assets/shaders/pbr_textured.frag b/assets/shaders/pbr_textured.frag deleted file mode 100644 index 0c801f8..0000000 --- a/assets/shaders/pbr_textured.frag +++ /dev/null @@ -1,159 +0,0 @@ -#version 410 core - -out vec4 FragColor; - -in vec3 fragWorldPos; -in vec3 fragNormal; -in vec2 fragTexCoords; - -in vec4 viewPos; - -struct PointLight { - vec4 position; - vec4 color; -}; - -// --- Uniforms - -// Lights data -#define NUM_POINT_LIGHTS 4 -uniform Lights { - PointLight pointLights[NUM_POINT_LIGHTS]; -} scene; - -uniform PBR_Params { - vec3 albedo; - float metallic; - float roughness; - float ao; -} params; - -// Material Textures -uniform sampler2D albedoMap; -uniform sampler2D metallicRoughnessMap; -uniform sampler2D aoMap; -uniform sampler2D normalMap; - -const float PI = 3.14; - -// Forward declarations -vec3 fresnelSchlick(float cosTheta, vec3 F0); -float DistributionGGX(vec3 N, vec3 H, float roughness); -float GeometrySchlickGGX(float NdotV, float roughness); -float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness); - -vec3 getNormalFromMap() -{ - vec3 tangentNormal = texture(normalMap, fragTexCoords).xyz * 2.0 - 1.0; - - vec3 Q1 = dFdx(fragWorldPos); - vec3 Q2 = dFdy(fragWorldPos); - vec2 st1 = dFdx(fragTexCoords); - vec2 st2 = dFdy(fragTexCoords); - - vec3 N = normalize(fragNormal); - vec3 T = normalize(Q1 * st2.t - Q2 * st1.t); - vec3 B = -normalize(cross(N, T)); - mat3 TBN = mat3(T, B, N); - - return normalize(TBN * tangentNormal); -} - -void main() { - // vec3 albedo = pow(texture(albedoMap, fragTexCoords).rgb, vec3(2.2)); - vec3 albedo = params.albedo * texture(albedoMap, fragTexCoords).rgb; - float metallic = params.metallic * texture(metallicRoughnessMap, fragTexCoords).b; - float roughness = params.roughness * texture(metallicRoughnessMap, fragTexCoords).g; - float ao = texture(aoMap, fragTexCoords).r; - - // vec3 norm = normalize(fragNormal); // N - vec3 norm = getNormalFromMap(); - vec3 N = norm; - vec3 viewDir = normalize(vec3(viewPos) - fragWorldPos); // V - vec3 V = viewDir; - - vec3 F0 = vec3(0.04); - F0 = mix(F0, albedo, metallic); - - vec3 Lo = vec3(0.0); - for (int i = 0; i < 4; ++i) { - vec3 lightVec = normalize(vec3(scene.pointLights[i].position) - fragWorldPos); // L - vec3 L = lightVec; - vec3 halfway = normalize(viewDir + lightVec); // H - vec3 H = halfway; - float distance = length(vec3(scene.pointLights[i].position) - fragWorldPos); - float attenuation = 1.0 / (distance * distance); - vec3 radiance = vec3(scene.pointLights[i].color) * attenuation; - - // cook-torrance brdf - float NDF = DistributionGGX(norm, halfway, roughness); - float G = GeometrySmith(norm, viewDir, lightVec, roughness); - // vec3 F = fresnelSchlick(max(dot(halfway, viewDir), 0.0), F0); - vec3 F = fresnelSchlick(clamp(dot(H, V), 0.0, 1.0), F0); - - vec3 numerator = NDF * G * F; - float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.0001; - vec3 specular = numerator / denominator; - - vec3 kS = F; - - vec3 kD = vec3(1.0) - kS; - kD *= 1.0 - metallic; - - // add to outgoing radiance Lo - float NdotL = max(dot(N, L), 0.0); - Lo += (kD * albedo / PI + specular) * radiance * NdotL; - // Lo += radiance; - } - - vec3 ambient = vec3(0.03) * albedo * ao; - vec3 color = ambient + Lo; //ambient + Lo; - - color = color / (color + vec3(1.0)); - color = pow(color, vec3(1.0 / 2.2)); - - FragColor = vec4(color, 1.0); - FragColor = vec4(1.0); - // FragColor = vec4(scene.pointLights[0].position); - // FragColor = vec4(albedo, 1.0); - // FragColor = vec4(pbr.metallic, pbr.roughness, pbr.ao, 1.0); - // FragColor = vec4(fragTexCoords, 0.0, 1.0); -} - -/* The below are from https://learnopengl.com/PBR/Lighting */ - -vec3 fresnelSchlick(float cosTheta, vec3 F0) { - return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0); -} -float DistributionGGX(vec3 N, vec3 H, float roughness) { - float a = roughness * roughness; - 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 roughness) -{ - float r = (roughness + 1.0); - float k = (r * r) / 8.0; - - float num = NdotV; - float denom = NdotV * (1.0 - k) + k; - - return num / denom; -} -float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) -{ - float NdotV = max(dot(N, V), 0.0); - float NdotL = max(dot(N, L), 0.0); - float ggx2 = GeometrySchlickGGX(NdotV, roughness); - float ggx1 = GeometrySchlickGGX(NdotL, roughness); - - return ggx1 * ggx2; -} diff --git a/assets/shaders/shadows.frag b/assets/shaders/shadows.frag deleted file mode 100644 index 0876b66..0000000 --- a/assets/shaders/shadows.frag +++ /dev/null @@ -1,5 +0,0 @@ -#version 410 core - -void main() { - gl_FragDepth = gl_FragCoord.z; -}
\ No newline at end of file diff --git a/assets/shaders/shadows.vert b/assets/shaders/shadows.vert deleted file mode 100644 index 65ff169..0000000 --- a/assets/shaders/shadows.vert +++ /dev/null @@ -1,16 +0,0 @@ -#version 410 core - -// Vertex attributes -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec3 inNormal; -layout(location = 2) in vec2 inTexCoords; - -// Uniforms -uniform ShadowUniforms { - mat4 model; - mat4 lightSpace; -} uniforms; - -void main() { - gl_Position = uniforms.lightSpace * uniforms.model * vec4(inPosition, 1.0); -} diff --git a/assets/shaders/skinned.vert b/assets/shaders/skinned.vert deleted file mode 100644 index cb2ca85..0000000 --- a/assets/shaders/skinned.vert +++ /dev/null @@ -1,59 +0,0 @@ -#version 410 core -// Inputs -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inTexCoords; -layout (location = 3) in ivec4 inBoneIndices; -layout (location = 4) in vec4 inWeights; - -uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; -uniform mat4 lightSpaceMatrix; - -const int MAX_BONES = 100; -const int MAX_BONE_INFLUENCES = 4; -uniform mat4 boneMatrices[MAX_BONES]; // TODO! - -// Output -out VS_OUT { - vec3 FragPos; - vec3 Normal; - vec2 TexCoords; - vec4 FragPosLightSpace; - vec4 Color; -} vs_out; - -void main() { - // vec4 totalPosition = vec4(0.0f); - // for(int i = 0 ; i < MAX_BONE_INFLUENCES ; i++) { - // if(inBoneIndices[i] == 0) - // continue; - // if(inBoneIndices[i] >=MAX_BONES) - // { - // totalPosition = vec4(inPos,1.0f); - // break; - // } - // vec4 localPosition = finalBoneMatrices[inBoneIndices[i]] * vec4(inPos,1.0f); - // totalPosition += localPosition * inWeights[i]; - // vec3 localNormal = mat3(finalBoneMatrices[inBoneIndices[i]]) * inNormal; - // vs_out.Normal = localNormal; - // } - - - mat4 skinMatrix = // mat4(1.0) - // boneMatrices[int(inBoneIndices.z)]; // should just be the identtiy - inWeights.x * boneMatrices[int(inBoneIndices.x)] + - inWeights.y * boneMatrices[int(inBoneIndices.y)] + - inWeights.z * boneMatrices[int(inBoneIndices.z)] + - inWeights.w * boneMatrices[int(inBoneIndices.w)]; - - vec4 totalPosition = skinMatrix * vec4(inPos, 1.0); - - vs_out.FragPos = vec3(model * totalPosition); - // vs_out.Normal = inNormal; - vs_out.TexCoords = inTexCoords; - vs_out.FragPosLightSpace = lightSpaceMatrix * vec4(vs_out.FragPos, 1.0); - vs_out.Color = inWeights; - gl_Position = projection * view * model * totalPosition; -}
\ No newline at end of file diff --git a/assets/shaders/skinned_geometry.vert b/assets/shaders/skinned_geometry.vert deleted file mode 100644 index a610442..0000000 --- a/assets/shaders/skinned_geometry.vert +++ /dev/null @@ -1,52 +0,0 @@ -#version 410 core - -// Vertex attributes -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec3 inNormal; -layout(location = 2) in vec2 inTexCoords; -layout(location = 3) in ivec4 inBoneIndices; -layout(location = 4) in vec4 inWeights; - -const int MAX_BONES = 100; -const int MAX_BONE_INFLUENCES = 4; - -uniform AnimData { - mat4 boneMatrices[MAX_BONES]; -} anim; - -uniform Camera { - mat4 view; - mat4 proj; - vec4 viewPos; -} cam; - -uniform Model { - mat4 inner; -} model; - -// Outputs -layout(location = 0) out vec3 fragWorldPos; -layout(location = 1) out vec3 fragNormal; -layout(location = 2) out vec2 fragTexCoords; - -out vec4 viewPos; -// out vec4 dbgcolor; - -void main() { - mat4 skinMatrix = - inWeights.x * anim.boneMatrices[int(inBoneIndices.x)] + - inWeights.y * anim.boneMatrices[int(inBoneIndices.y)] + - inWeights.z * anim.boneMatrices[int(inBoneIndices.z)] + - inWeights.w * anim.boneMatrices[int(inBoneIndices.w)]; - - vec4 totalPosition = skinMatrix * vec4(inPosition, 1.0); - - fragWorldPos = vec3(model.inner * totalPosition); - fragNormal = mat3(transpose(inverse(model.inner))) * inNormal; // world-space normal - fragTexCoords = inTexCoords; - - viewPos = cam.viewPos; - - gl_Position = cam.proj * cam.view * model.inner * vec4(inPosition, 1.0); - // gl_Position = cam.proj * cam.view * model.inner * totalPosition; -} diff --git a/assets/shaders/skybox.frag b/assets/shaders/skybox.frag deleted file mode 100644 index d2f3844..0000000 --- a/assets/shaders/skybox.frag +++ /dev/null @@ -1,12 +0,0 @@ -#version 410 core - -out vec4 FragColor; - -in vec3 TexCoords; - -uniform samplerCube cubeMap; - -void main() { - FragColor = texture(cubeMap, TexCoords); - // FragColor = vec4(1.0, 0.0, 0.0, 1.0); -} diff --git a/assets/shaders/skybox.vert b/assets/shaders/skybox.vert deleted file mode 100644 index 6b56527..0000000 --- a/assets/shaders/skybox.vert +++ /dev/null @@ -1,19 +0,0 @@ -#version 410 core - -layout(location = 0) in vec3 inPosition; -// layout(location = 1) in vec3 inNormal; -// layout(location = 2) in vec2 inTexCoords; - -uniform Camera { - mat4 view; - mat4 proj; - vec4 viewPos; -} cam; - -out vec3 TexCoords; - -void main() { - TexCoords = inPosition; - vec4 pos = cam.proj * cam.view * vec4(inPosition, 1.0); - gl_Position = pos.xyww; -} diff --git a/assets/shaders/static_geometry.vert b/assets/shaders/static_geometry.vert deleted file mode 100644 index 2021691..0000000 --- a/assets/shaders/static_geometry.vert +++ /dev/null @@ -1,33 +0,0 @@ -#version 410 core - -// Vertex attributes -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec3 inNormal; -layout(location = 2) in vec2 inTexCoords; - -uniform Camera { - mat4 view; - mat4 proj; - vec4 viewPos; -} cam; - -uniform Model { - mat4 inner; -} model; - -// Outputs -layout(location = 0) out vec3 fragWorldPos; -layout(location = 1) out vec3 fragNormal; -layout(location = 2) out vec2 fragTexCoords; - -out vec4 viewPos; - -void main() { - fragWorldPos = vec3(model.inner * vec4(inPosition, 1.0)); - fragNormal = mat3(transpose(inverse(model.inner))) * inNormal; // world-space normal - fragTexCoords = inTexCoords; - - viewPos = cam.viewPos; - - gl_Position = cam.proj * cam.view * model.inner * vec4(inPosition, 1.0); -} diff --git a/assets/shaders/terrain.frag b/assets/shaders/terrain.frag deleted file mode 100644 index 0cc76c8..0000000 --- a/assets/shaders/terrain.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 410 core - -out vec4 FragColor; - -in vec4 Color; -in vec2 TexCoord; - -uniform sampler2D TextureSlot1; - -void main() { - vec4 tex_color = texture(TextureSlot1, TexCoord); - FragColor = Color * tex_color; -}
\ No newline at end of file diff --git a/assets/shaders/terrain.vert b/assets/shaders/terrain.vert deleted file mode 100644 index 40f2b3e..0000000 --- a/assets/shaders/terrain.vert +++ /dev/null @@ -1,22 +0,0 @@ -#version 410 core - -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec3 inNormal; -layout(location = 2) in vec2 inTexCoords; - -uniform Camera { - mat4 view; - mat4 proj; - vec4 viewPos; -} cam; - -out vec4 Color; -out vec2 TexCoord; - -void main() { - vec3 position = vec3(inPosition.x, inPosition.y / 2.0, inPosition.z); - gl_Position = cam.proj * cam.view * vec4(position, 1.0); - - Color = vec4(inPosition.y / 100.0); - TexCoord = inTexCoords; -}
\ No newline at end of file diff --git a/assets/shaders/triangle.frag b/assets/shaders/triangle.frag deleted file mode 100644 index 3ae1fc4..0000000 --- a/assets/shaders/triangle.frag +++ /dev/null @@ -1,6 +0,0 @@ -#version 410 - -layout(location = 0) in vec3 fragColor; -layout(location = 0) out vec4 outColor; - -void main() { outColor = vec4(fragColor, 0.0); } diff --git a/assets/shaders/triangle.metal b/assets/shaders/triangle.metal index 6522360..ccb7ca7 100644 --- a/assets/shaders/triangle.metal +++ b/assets/shaders/triangle.metal @@ -1,17 +1,40 @@ #include <metal_stdlib> using namespace metal; -vertex float4 +struct VertexData { + float4 position; + float2 texCoords; +}; + +struct VertexOut { + // The [[position]] attribute of this member indicates that this value + // is the clip space position of the vertex when this structure is + // returned from the vertex function. + float4 position [[position]]; + + // Since this member does not have a special attribute, the rasterizer + // interpolates its value with the values of the other triangle vertices + // and then passes the interpolated value to the fragment shader for each + // fragment in the triangle. + float2 textureCoordinate; +}; + +vertex VertexOut vertexShader(uint vertexID [[vertex_id]], - constant simd::float3* vertexPositions) + constant VertexData* vertexData) { - float4 vertexOutPositions = float4(vertexPositions[vertexID][0], - vertexPositions[vertexID][1], - vertexPositions[vertexID][2], - 1.0f); - return vertexOutPositions; + VertexOut out; + out.position = vertexData[vertexID].position; + out.textureCoordinate = vertexData[vertexID].texCoords; + return out; } -fragment float4 fragmentShader(float4 vertexOutPositions [[stage_in]]) { - return float4(182.0f/255.0f, 240.0f/255.0f, 228.0f/255.0f, 1.0f); +fragment float4 fragmentShader(VertexOut in [[stage_in]], + texture2d<float> colorTexture [[texture(0)]]) { + + constexpr sampler textureSampler (mag_filter::linear, + min_filter::linear); + // Sample the texture to obtain a color + const float4 colorSample = colorTexture.sample(textureSampler, in.textureCoordinate); + return colorSample; }
\ No newline at end of file diff --git a/assets/shaders/triangle.vert b/assets/shaders/triangle.vert deleted file mode 100644 index 45b4907..0000000 --- a/assets/shaders/triangle.vert +++ /dev/null @@ -1,11 +0,0 @@ -#version 410 - -layout(location = 0) in vec2 inPos; -layout(location = 1) in vec3 inColor; - -layout(location = 0) out vec3 fragColor; - -void main() { - gl_Position = vec4(inPos, 0.0, 1.0); - fragColor = inColor; -} diff --git a/assets/shaders/ui_rect.frag b/assets/shaders/ui_rect.frag deleted file mode 100644 index fce0a2e..0000000 --- a/assets/shaders/ui_rect.frag +++ /dev/null @@ -1,9 +0,0 @@ -#version 410 core -out vec4 FragColor; - -in vec3 outColor; - -void main() -{ - FragColor = vec4(outColor, 1.0f); -} diff --git a/assets/shaders/ui_rect.vert b/assets/shaders/ui_rect.vert deleted file mode 100644 index 060fdcb..0000000 --- a/assets/shaders/ui_rect.vert +++ /dev/null @@ -1,13 +0,0 @@ -#version 410 core -layout (location = 0) in vec2 aPos; -layout (location = 1) in vec3 color; - -out vec3 outColor; - -// uniform mat4 projection; - -void main() -{ - gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0); - outColor = color; -} |