- Crear directorio data/shaders/ para organizar todos los shaders MSL - Extraer shaders embebidos a archivos individuales: * background.metal - Shader de fondo degradado * triangle.metal - Shader de triángulo multicolor * sprite.metal - Shader de sprites con vertex color tinting * crt.metal - Shader CRT post-processing completo - Modificar main.cpp para cargar shaders desde archivos: * Usar stringWithContentsOfFile para leer código fuente * Compilar dinámicamente con newLibraryWithSource * Manejo robusto de errores de lectura y compilación - Eliminar 351 líneas de strings embebidos de main.cpp - Mantener funcionalidad completa: CRT + sprites + fondo + triángulo Beneficios: - Shaders editables sin recompilar ejecutable - Mejor organización y mantenimiento del código - Syntax highlighting completo en editores - Reutilización de shaders en otros proyectos - Desarrollo más ágil de efectos visuales 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
40 lines
1.2 KiB
Metal
40 lines
1.2 KiB
Metal
#include <metal_stdlib>
|
|
using namespace metal;
|
|
|
|
struct VertexOut {
|
|
float4 position [[position]];
|
|
float4 color;
|
|
};
|
|
|
|
vertex VertexOut background_vertex_main(uint vertexID [[vertex_id]]) {
|
|
VertexOut out;
|
|
|
|
// Quad de pantalla completa en coordenadas NDC
|
|
float2 positions[6] = {
|
|
float2(-1.0, -1.0), // Bottom left
|
|
float2( 1.0, -1.0), // Bottom right
|
|
float2(-1.0, 1.0), // Top left
|
|
float2( 1.0, -1.0), // Bottom right
|
|
float2( 1.0, 1.0), // Top right
|
|
float2(-1.0, 1.0) // Top left
|
|
};
|
|
|
|
// Gradiente de púrpura oscuro arriba a azul cyan abajo
|
|
float4 colors[6] = {
|
|
float4(0.2, 0.6, 0.8, 1.0), // Bottom left - cyan claro
|
|
float4(0.2, 0.6, 0.8, 1.0), // Bottom right - cyan claro
|
|
float4(0.3, 0.1, 0.5, 1.0), // Top left - púrpura oscuro
|
|
float4(0.2, 0.6, 0.8, 1.0), // Bottom right - cyan claro
|
|
float4(0.3, 0.1, 0.5, 1.0), // Top right - púrpura oscuro
|
|
float4(0.3, 0.1, 0.5, 1.0) // Top left - púrpura oscuro
|
|
};
|
|
|
|
out.position = float4(positions[vertexID], 0.0, 1.0);
|
|
out.color = colors[vertexID];
|
|
|
|
return out;
|
|
}
|
|
|
|
fragment float4 background_fragment_main(VertexOut in [[stage_in]]) {
|
|
return in.color;
|
|
} |