summaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-12 00:16:51 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-12 00:16:51 +1000
commit26fb1fcafa552c600a70b2680c868f7355b138e4 (patch)
tree2fb77c8b14a5610584a316e57fd8db2795847a0f /assets
parent76216f91aee936bc57d7e1a1b2c2b63a03ce976a (diff)
wip: uvsphere mesh gen and pbr shader first pass
Diffstat (limited to 'assets')
-rw-r--r--assets/shaders/pbr_params.frag85
1 files changed, 85 insertions, 0 deletions
diff --git a/assets/shaders/pbr_params.frag b/assets/shaders/pbr_params.frag
new file mode 100644
index 0000000..06e0f7e
--- /dev/null
+++ b/assets/shaders/pbr_params.frag
@@ -0,0 +1,85 @@
+#version 410
+
+out vec4 FragColor;
+
+in vec3 WorldPos;
+in vec3 Normal;
+in vec2 TexCoords;
+
+struct PointLight {
+ vec3 position;
+ vec3 color;
+};
+
+// --- Uniforms
+uniform vec3 viewPos;
+// Lights data
+#define NUM_POINT_LIGHTS 4
+uniform PointLight pointLights[NUM_POINT_LIGHTS];
+// Material properties
+uniform vec3 albedo;
+uniform float metallic;
+uniform float roughness;
+uniform float ao;
+
+// 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(Normal);
+ vec3 viewDir = normalize(viewPos - WorldPos);
+
+ vec3 radiance = vec3(0.0); // denoted L in the radiance equation
+ for (int i = 0; i < 4; i++) {
+ vec3 lightVec = normalize(pointLights[i].position - WorldPos);
+ vec3 halfway = normalize(Normal + lightVec);
+ float distance = length(pointLights[i].position - WorldPos);
+ float attenuation = 1.0 / (distance * distance);
+ vec3 radiance = pointLights[i].color * attenuation;
+
+ vec3 F0 = vec3(0.04);
+ F0 = mix(F0, albedo, metallic);
+ vec3 F = fresnelSchlick(max(dot(halfway, lightVec), 0.0), F0);
+ }
+}
+
+/* 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;
+} \ No newline at end of file