feat: render and manage textures :3

This commit is contained in:
zack 2025-04-05 20:54:38 -04:00
parent 2501390225
commit 74a1be796f
No known key found for this signature in database
GPG key ID: EE8A2B709E2401D1
21 changed files with 2908 additions and 320 deletions

View file

@ -1,16 +1,34 @@
#version 450
// Input from vertex shader
layout(location = 0) in vec3 fragColor;
// layout(location = 1) in vec2 fragTexCoord; // If using textures
layout(location = 0) in vec3 fragNormal; // Receive normal
layout(location = 1) in vec2 fragTexCoord; // Receive texture coordinates
// Output color
layout(location = 0) out vec4 outColor;
// layout(binding = 1) uniform sampler2D texSampler; // If using textures
// Descriptor set for material properties (Set 1)
layout(set = 1, binding = 0) uniform sampler2D baseColorSampler;
// Optional: Pass material factors via another UBO or Push Constants if needed
// layout(set = 1, binding = 1) uniform MaterialFactors {
// vec4 baseColorFactor;
// } materialFactors;
void main() {
// Use interpolated color
outColor = vec4(fragColor, 1.0);
// outColor = texture(texSampler, fragTexCoord); // If using textures
// Sample the texture
vec4 texColor = texture(baseColorSampler, fragTexCoord);
// Use the texture color
// You might multiply by baseColorFactor here if you pass it
// outColor = texColor * materialFactors.baseColorFactor;
outColor = texColor;
// Basic fallback if texture alpha is zero (or use baseColorFactor)
if (outColor.a == 0.0) {
outColor = vec4(0.8, 0.8, 0.8, 1.0); // Default grey
}
// You could add basic lighting using fragNormal here later
}

View file

@ -1,26 +1,38 @@
#version 450
// Matches Vertex struct attribute descriptions
// INPUTS from Vertex Buffer (matching Vertex struct)
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;
// layout(location = 2) in vec2 inTexCoord; // If you add texture coords
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec2 inTexCoord; // <<< MUST be vec2
// Matches UniformBufferObject struct and descriptor set layout binding
layout(binding = 0) uniform UniformBufferObject {
mat4 model;
// UNIFORMS (Set 0)
layout(set = 0, binding = 0) uniform UniformBufferObject {
mat4 view;
mat4 proj;
} ubo;
// Output to fragment shader
layout(location = 0) out vec3 fragColor;
// layout(location = 1) out vec2 fragTexCoord; // If you add texture coords
// PUSH CONSTANTS
layout(push_constant) uniform PushConstants {
mat4 model;
} pushConstants;
// OUTPUTS to Fragment Shader
layout(location = 0) out vec3 fragNormal; // Location 0 for Normal
layout(location = 1) out vec2 fragTexCoord; // Location 1 for TexCoord
void main() {
// Transform position: Model -> World -> View -> Clip space
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
vec4 worldPos = pushConstants.model * vec4(inPosition, 1.0);
// Pass color (and other attributes) through
fragColor = inColor;
// fragTexCoord = inTexCoord;
// Calculate final position
gl_Position = ubo.proj * ubo.view * worldPos;
// --- Pass attributes to Fragment Shader ---
// Pass world-space normal (adjust calculation if needed)
// Ensure fragNormal is assigned a vec3
fragNormal = normalize(mat3(transpose(inverse(pushConstants.model))) * inNormal);
// Pass texture coordinates (ensure inTexCoord is vec2)
// Ensure fragTexCoord is assigned a vec2
fragTexCoord = inTexCoord;
}