diff --git a/projects/voxelization/resources/shaders/shader.frag b/projects/voxelization/resources/shaders/shader.frag index 8653ae5958ce3b42eac6b1eaa6813f85b6ed589c..24f4673b0d751b7ca8fb4617e885bed60a5692fe 100644 --- a/projects/voxelization/resources/shaders/shader.frag +++ b/projects/voxelization/resources/shaders/shader.frag @@ -9,6 +9,7 @@ layout(location = 0) in vec3 passNormal; layout(location = 1) in vec2 passUV; layout(location = 2) in vec3 passPos; +layout(location = 3) in vec4 passTangent; layout(location = 0) out vec3 outColor; @@ -19,10 +20,22 @@ layout(set=0, binding=1) uniform texture2D shadowMap; layout(set=0, binding=2) uniform sampler shadowMapSampler; void main() { - vec3 N = normalize(passNormal); + + vec3 albedoTexel = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb; + vec3 normalTexel = texture(sampler2D(normalTexture, textureSampler), passUV).rgb; + vec3 specularTexel = texture(sampler2D(specularTexture, textureSampler), passUV).rgb; + + vec3 albedo = albedoTexel; + + vec3 T = normalize(passTangent.xyz); + vec3 N_geo = normalize(passNormal); + vec3 B = cross(N_geo, T) * passTangent.w; + mat3 TBN = mat3(T, B, N_geo); + normalTexel = normalTexel * 2 - 1; + + vec3 N = TBN * normalTexel; vec3 sun = lightInfo.sunStrength * lightInfo.sunColor * clamp(dot(N, lightInfo.L), 0, 1); sun *= shadowTest(passPos, lightInfo, shadowMap, shadowMapSampler); vec3 ambient = vec3(0.05); - vec3 albedo = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb; - outColor = albedo * (sun + ambient); + outColor = albedo * (sun + ambient); } \ No newline at end of file diff --git a/projects/voxelization/resources/shaders/shader.vert b/projects/voxelization/resources/shaders/shader.vert index 926f86af2860cb57c44d2d5ee78712b6ae155e5c..e3873f98a308347592725e794d6b7102cbbe3e5c 100644 --- a/projects/voxelization/resources/shaders/shader.vert +++ b/projects/voxelization/resources/shaders/shader.vert @@ -4,10 +4,12 @@ layout(location = 0) in vec3 inPosition; layout(location = 1) in vec3 inNormal; layout(location = 2) in vec2 inUV; +layout(location = 3) in vec4 inTangent; layout(location = 0) out vec3 passNormal; layout(location = 1) out vec2 passUV; layout(location = 2) out vec3 passPos; +layout(location = 3) out vec4 passTangent; layout( push_constant ) uniform constants{ mat4 mvp; @@ -19,4 +21,5 @@ void main() { passNormal = mat3(model) * inNormal; // assuming no weird stuff like shearing or non-uniform scaling passUV = inUV; passPos = (model * vec4(inPosition, 1)).xyz; + passTangent = vec4(mat3(model) * inTangent.xyz, inTangent.w); } \ No newline at end of file diff --git a/projects/voxelization/src/main.cpp b/projects/voxelization/src/main.cpp index f679a3456d3f51035106dd3012f1257490ae56eb..33b6cc20f970f2b14a6fda62a53ebe01c6cd28c4 100644 --- a/projects/voxelization/src/main.cpp +++ b/projects/voxelization/src/main.cpp @@ -217,14 +217,14 @@ int main(int argc, const char** argv) { const vkcv::ImageHandle albedoHandle = sceneImages.back().getHandle(); // normal texture - sceneImages.push_back(core.createImage(vk::Format::eR8G8B8A8Srgb, normalTexture.w, normalTexture.h, 1, true)); + sceneImages.push_back(core.createImage(vk::Format::eR8G8B8A8Unorm, normalTexture.w, normalTexture.h, 1, true)); sceneImages.back().fill(normalTexture.data.data()); sceneImages.back().generateMipChainImmediate(); sceneImages.back().switchLayout(vk::ImageLayout::eShaderReadOnlyOptimal); const vkcv::ImageHandle normalHandle = sceneImages.back().getHandle(); // specular texture - sceneImages.push_back(core.createImage(vk::Format::eR8G8B8A8Srgb, specularTexture.w, specularTexture.h, 1, true)); + sceneImages.push_back(core.createImage(vk::Format::eR8G8B8A8Unorm, specularTexture.w, specularTexture.h, 1, true)); sceneImages.back().fill(specularTexture.data.data()); sceneImages.back().generateMipChainImmediate(); sceneImages.back().switchLayout(vk::ImageLayout::eShaderReadOnlyOptimal); diff --git a/src/vkcv/ImageManager.cpp b/src/vkcv/ImageManager.cpp index a3364ce0dfd6f59dc78c85b43570eea25cfc052d..98a8dfcf3dc5aa06024546e204518a3c0fa56af4 100644 --- a/src/vkcv/ImageManager.cpp +++ b/src/vkcv/ImageManager.cpp @@ -352,8 +352,10 @@ namespace vkcv { return 1; case vk::Format::eR8G8B8A8Srgb: return 4; + case vk::Format::eR8G8B8A8Unorm: + return 4; default: - std::cerr << "Check format instead of guessing, please!" << std::endl; + std::cerr << "Unknown image format" << std::endl; return 4; } }