-
Notifications
You must be signed in to change notification settings - Fork 0
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
241 additions
and
5 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
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,25 @@ | ||
#version 450 | ||
#extension GL_EXT_nonuniform_qualifier : enable | ||
|
||
layout(set = 0, binding = 0) uniform UniformBufferObject { | ||
mat4 view; | ||
mat4 proj; | ||
mat4 projView; | ||
vec4 ambientLightColor; // w is intensity | ||
vec4 lightPosition; // w is ignored | ||
vec4 lightColor; // w is intensity | ||
} ubo; | ||
|
||
layout(set = 1, binding = 0) uniform sampler2D texSampler[]; | ||
|
||
layout(location = 0) in vec3 fragColor; | ||
layout(location = 1) in vec2 fragTexCoord; | ||
layout(location = 2) in flat uint materialIndex; | ||
layout(location = 3) in vec3 fragPosWorld; | ||
layout(location = 4) in vec3 fragNormalWorld; | ||
|
||
layout(location = 0) out vec4 outColor; | ||
|
||
void main() { | ||
outColor = vec4(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,42 @@ | ||
#version 450 | ||
|
||
layout(set = 0, binding = 0) uniform UniformBufferObject { | ||
mat4 view; | ||
mat4 proj; | ||
mat4 projView; | ||
vec4 ambientLightColor; // w is intensity | ||
vec4 lightPosition; // w is ignored | ||
vec4 lightColor; // w is intensity | ||
} ubo; | ||
|
||
layout (push_constant) uniform constants { | ||
mat4 modelMatrix; | ||
} pushConstants; | ||
|
||
layout(location = 0) in vec3 inPosition; | ||
layout(location = 1) in vec3 inColor; | ||
layout(location = 2) in vec3 inNormal; | ||
layout(location = 3) in vec2 inTexCoord; | ||
layout(location = 4) in uint inMaterialIndex; | ||
|
||
|
||
layout(location = 0) out vec3 fragColor; | ||
layout(location = 1) out vec2 fragTexCoord; | ||
layout(location = 2) out uint materialIndex; | ||
layout(location = 3) out vec3 fragPosWorld; | ||
layout(location = 4) out vec3 fragNormalWorld; | ||
|
||
void main() { | ||
vec4 positionWorld = pushConstants.modelMatrix * vec4(inPosition, 1.0); | ||
|
||
gl_Position = ubo.projView * positionWorld; | ||
fragColor = inColor; | ||
fragTexCoord = inTexCoord; | ||
materialIndex = inMaterialIndex; | ||
fragPosWorld = positionWorld.xyz; | ||
// Diffuse shading does not work correctly if model is scaled non Uniformly | ||
// https://paroj.github.io/gltut/Illumination/Tut09%20Normal%20Transformation.html | ||
// TODO: Fix this if it becomes necessary | ||
// Can be done by computing the value on the CPU and sending it as a Push Constant | ||
fragNormalWorld = normalize((pushConstants.modelMatrix * vec4(inNormal, 0.0)).xyz); | ||
} |