diff --git a/projects/first_scene/assets/shaders/shader.frag b/projects/first_scene/assets/shaders/shader.frag index b5494bea7d6497e2e3dcd8559606864a71adb74e..cf96b4c20327fa3f1b1545cba7cebfdfaaf1ba7c 100644 --- a/projects/first_scene/assets/shaders/shader.frag +++ b/projects/first_scene/assets/shaders/shader.frag @@ -4,12 +4,28 @@ layout(location = 0) in vec3 passNormal; layout(location = 1) in vec2 passUV; -layout(location = 0) out vec3 outColor; +layout(location = 0) out vec4 outColor; layout(set=0, binding=0) uniform texture2D meshTexture; layout(set=0, binding=1) uniform sampler textureSampler; void main() { - outColor = texture(sampler2D(meshTexture, textureSampler), passUV).rgb; - //outColor = passNormal * 0.5 + 0.5; + vec3 lightDirection = normalize(vec3(0.1f, -0.9f, 0.1f)); + + float ambient = 0.35f; + float diffuse = max(0.0f, -dot(passNormal, lightDirection)); + float specular = pow(diffuse, 6.0f); + + float brightness = sqrt( + (ambient + diffuse + specular) / + (2.0f + ambient) + ); + + vec4 color = texture(sampler2D(meshTexture, textureSampler), passUV); + + if (color.a <= 0.0f) { + discard; + } + + outColor = vec4(color.rgb * brightness, color.a); } \ No newline at end of file diff --git a/projects/first_scene/src/main.cpp b/projects/first_scene/src/main.cpp index 7867bc6ef2cb711c949d24a2827460b1de1b4729..9fb7247ec6da805acd2312c3889c45e4a95a3d48 100644 --- a/projects/first_scene/src/main.cpp +++ b/projects/first_scene/src/main.cpp @@ -4,7 +4,6 @@ #include <GLFW/glfw3.h> #include <vkcv/camera/CameraManager.hpp> #include <vkcv/gui/GUI.hpp> -#include <chrono> #include <vkcv/asset/asset_loader.hpp> #include <vkcv/shader/GLSLCompiler.hpp> #include <vkcv/scene/Scene.hpp> @@ -18,12 +17,6 @@ int main(int argc, const char** argv) { vkcv::Features features; features.requireExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME); - features.requireExtensionFeature<vk::PhysicalDeviceDescriptorIndexingFeatures>( - VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, - [](vk::PhysicalDeviceDescriptorIndexingFeatures& features) { - features.setDescriptorBindingPartiallyBound(true); - } - ); vkcv::Core core = vkcv::Core::create( applicationName, @@ -31,6 +24,7 @@ int main(int argc, const char** argv) { {vk::QueueFlagBits::eTransfer, vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eCompute}, features ); + vkcv::WindowHandle windowHandle = core.createWindow(applicationName, windowWidth, windowHeight, true); vkcv::Window& window = core.getWindow(windowHandle); vkcv::camera::CameraManager cameraManager(window);