From 8045b8ba04aae39a4cf9733e72413f648b6ebe2b Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 18 Sep 2022 21:20:51 -0400 Subject: stanford dragon rendering --- res/shaders/simple_shader.frag | 19 +++++++++++++++++++ res/shaders/simple_shader.frag.spv | Bin 0 -> 1112 bytes res/shaders/simple_shader.vert | 30 ++++++++++++++++++++++++++++++ res/shaders/simple_shader.vert.spv | Bin 0 -> 2520 bytes 4 files changed, 49 insertions(+) create mode 100755 res/shaders/simple_shader.frag create mode 100644 res/shaders/simple_shader.frag.spv create mode 100755 res/shaders/simple_shader.vert create mode 100644 res/shaders/simple_shader.vert.spv (limited to 'res/shaders') diff --git a/res/shaders/simple_shader.frag b/res/shaders/simple_shader.frag new file mode 100755 index 0000000..b11a5a8 --- /dev/null +++ b/res/shaders/simple_shader.frag @@ -0,0 +1,19 @@ +#version 450 + +layout (location = 0) in vec3 fragColor; + +layout (location = 0) out vec4 outColor; + +layout(set = 0, binding = 0) uniform GlobalUbo { + mat4 projectionViewMatrix; + vec3 directionToLight; +} ubo; + +layout(push_constant) uniform Push { + mat4 transform; + mat4 normalMatrix; +} push; + +void main() { + outColor = vec4(fragColor, 1.0); +} \ No newline at end of file diff --git a/res/shaders/simple_shader.frag.spv b/res/shaders/simple_shader.frag.spv new file mode 100644 index 0000000..ff80cc6 Binary files /dev/null and b/res/shaders/simple_shader.frag.spv differ diff --git a/res/shaders/simple_shader.vert b/res/shaders/simple_shader.vert new file mode 100755 index 0000000..be802f7 --- /dev/null +++ b/res/shaders/simple_shader.vert @@ -0,0 +1,30 @@ +#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(set = 0, binding = 0) uniform GlobalUbo { + mat4 projectionViewMatrix; + vec3 directionToLight; +} ubo; + +layout(push_constant) uniform Push { + mat4 modelMatrix; + mat4 normalMatrix; +} push; + +const float AMBIENT = 0.02; + +void main() { + gl_Position = ubo.projectionViewMatrix * push.modelMatrix * vec4(position, 1.0); + + vec3 normalWorldSpace = normalize(mat3(push.normalMatrix) * normal); + + float lightIntensity = AMBIENT + max(dot(normalWorldSpace, ubo.directionToLight), 0); + + fragColor = lightIntensity * color; +} \ No newline at end of file diff --git a/res/shaders/simple_shader.vert.spv b/res/shaders/simple_shader.vert.spv new file mode 100644 index 0000000..7b4a820 Binary files /dev/null and b/res/shaders/simple_shader.vert.spv differ -- cgit v1.2.3-freya