-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
151 additions
and
14 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 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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#version 450 | ||
|
||
layout(location = 0) in vec3 fragColor; | ||
layout(location = 1) in vec3 fragPosWorld; | ||
layout(location = 2) in vec3 fragNormalWorld; | ||
|
||
layout(location = 0) out vec4 outColor; | ||
|
||
|
||
struct PointLight { | ||
vec4 position; // ignore w | ||
vec4 color; // w is intensity | ||
}; | ||
|
||
layout(set = 0, binding = 0) uniform GlobalUbo | ||
{ | ||
mat4 projection; | ||
mat4 view; | ||
vec4 front; | ||
vec4 ambientColor; | ||
int numLights; | ||
int padding1; | ||
int padding2; | ||
int padding3; | ||
PointLight pointLights[10]; | ||
} ubo; | ||
|
||
layout(push_constant) uniform Push | ||
{ | ||
mat4 modelMatrix; | ||
mat4 normalMatrix; | ||
} push; | ||
|
||
|
||
|
||
void main() { | ||
vec3 diffuseLight = ubo.ambientColor.xyz * ubo.ambientColor.w; | ||
vec3 specularLight = vec3(0.0); | ||
vec3 surfaceNormal = normalize(fragNormalWorld); | ||
|
||
// already had front vec in camera | ||
vec3 viewDirection = -ubo.front.xyz; | ||
|
||
for (int i = 0; i < ubo.numLights; i++) | ||
{ | ||
|
||
PointLight light = ubo.pointLights[i]; | ||
vec3 directionToLight = light.position.xyz - fragPosWorld; | ||
float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared | ||
directionToLight = normalize(directionToLight); | ||
|
||
float cosAngIncidence = max(dot(surfaceNormal, directionToLight), 0); | ||
vec3 intensity = light.color.xyz * light.color.w * attenuation; | ||
|
||
diffuseLight += intensity * cosAngIncidence; | ||
|
||
// specular lighting | ||
vec3 halfAngle = normalize(directionToLight + viewDirection); | ||
float blinnTerm = dot(surfaceNormal, halfAngle); | ||
blinnTerm = clamp(blinnTerm, 0, 1); | ||
blinnTerm = pow(blinnTerm, 64.0); | ||
specularLight += intensity * blinnTerm; | ||
} | ||
|
||
outColor = vec4(diffuseLight * fragColor + specularLight * fragColor, 1.0); | ||
} |
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,47 @@ | ||
#version 450 | ||
|
||
layout(location = 0) in vec3 position; | ||
layout(location = 1) in vec3 color; | ||
layout(location = 2) in vec3 normal; | ||
layout(location = 3) in vec2 uv; | ||
|
||
layout(location = 0) out vec3 fragColor; | ||
layout(location = 1) out vec3 fragPosWorld; | ||
layout(location = 2) out vec3 fragNormalWorld; | ||
|
||
struct PointLight { | ||
vec4 position; // ignore w | ||
vec4 color; // w is intensity | ||
}; | ||
|
||
layout(set = 0, binding = 0) uniform GlobalUbo | ||
{ | ||
mat4 projection; | ||
mat4 view; | ||
vec4 front; | ||
vec4 ambientColor; | ||
int numLights; | ||
int padding1; | ||
int padding2; | ||
int padding3; | ||
PointLight pointLights[10]; | ||
} ubo; | ||
|
||
layout(push_constant) uniform Push | ||
{ | ||
mat4 modelMatrix; | ||
mat4 normalMatrix; | ||
} push; | ||
|
||
|
||
void main() { | ||
vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); | ||
gl_Position = ubo.projection * ubo.view * positionWorld; | ||
|
||
fragNormalWorld = normalize(mat3(push.normalMatrix) * normal); | ||
fragPosWorld = positionWorld.xyz; | ||
fragColor = color; | ||
} | ||
|
||
|
||
//#extension GL_KHR_vulkan_glsl:enable |