-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified the naming of the shaders and loading of the SPIR-V binaries
- Loading branch information
Showing
9 changed files
with
89 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,55 @@ | ||
#version 450 | ||
#extension GL_ARB_separate_shader_objects : enable | ||
|
||
layout(binding = 0) uniform Camera { | ||
mat4 model; | ||
mat4 view; | ||
mat4 projection; | ||
vec3 position; | ||
} cam; | ||
|
||
layout(binding = 1) uniform Light { | ||
vec3 position; | ||
vec3 emissiveColor; | ||
} light; | ||
|
||
layout(binding = 2) uniform sampler2D texSampler; | ||
|
||
layout(location = 0) in vec3 fragPosition; | ||
layout(location = 1) in vec3 fragNormal; | ||
layout(location = 2) in vec2 fragTexCoord; | ||
|
||
layout(location = 0) out vec4 outColor; | ||
|
||
vec3 diffuse(in vec3 materialDiffuse, in vec3 normal) { | ||
vec3 L = normalize(light.position - fragPosition); | ||
float nDotL = max(0.0, dot(normal, L)); | ||
|
||
return materialDiffuse * light.emissiveColor * nDotL; | ||
} | ||
|
||
vec3 specular(in vec3 materialSpecular, in vec3 normal) { | ||
vec3 matSpec = vec3(1.0); | ||
vec3 eyePos = normalize(cam.position); | ||
|
||
vec3 L = normalize(light.position - fragPosition); | ||
vec3 V = normalize(eyePos - fragPosition); | ||
vec3 B = normalize(L + V); | ||
|
||
float nDotB = max(0.0, dot(normal, B)); | ||
|
||
return materialSpecular * pow(nDotB, 100); | ||
} | ||
|
||
void main() { | ||
vec4 matAlbedo = texture(texSampler, fragTexCoord); | ||
vec3 diff = diffuse(matAlbedo.rgb, fragNormal); | ||
vec3 spec = specular(matAlbedo.rgb, fragNormal); | ||
|
||
vec3 distanceToLight = light.position - fragPosition; | ||
float d = length(distanceToLight); | ||
float attenuation = clamp(10.0 / d, 0.0, 1.0); | ||
|
||
vec3 finalColor = attenuation * clamp(diff + spec, 0.0, 1.0); | ||
outColor = vec4(finalColor, 1.0); // Ignore the alpha component for now | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
#version 450 | ||
#extension GL_ARB_separate_shader_objects : enable | ||
|
||
layout(binding = 0) uniform Camera { | ||
mat4 model; | ||
mat4 view; | ||
mat4 projection; | ||
vec3 position; | ||
} cam; | ||
|
||
layout(location = 0) in vec3 inPosition; | ||
layout(location = 1) in vec3 inNormal; | ||
layout(location = 2) in vec2 inTexCoord; | ||
|
||
layout(location = 0) out vec3 fragPosition; | ||
layout(location = 1) out vec3 fragNormal; | ||
layout(location = 2) out vec2 fragTexCoord; | ||
|
||
void main() { | ||
gl_Position = vec4(vec3(0.0), 1.0); | ||
} | ||
gl_Position = cam.projection * cam.view * cam.model * vec4(inPosition, 1.0f); | ||
fragPosition = inPosition; | ||
fragNormal = (transpose(inverse(cam.model)) * vec4(inNormal, 1.0f)).xyz; | ||
fragTexCoord = inTexCoord; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#version 450 | ||
#extension GL_ARB_separate_shader_objects : enable | ||
|
||
void main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#version 450 | ||
#extension GL_ARB_separate_shader_objects : enable | ||
|
||
void main() { | ||
gl_Position = vec4(vec3(0.0), 1.0); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters