- 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>
33 lines
789 B
Metal
33 lines
789 B
Metal
#include <metal_stdlib>
|
|
using namespace metal;
|
|
|
|
struct VertexOut {
|
|
float4 position [[position]];
|
|
float4 color;
|
|
};
|
|
|
|
vertex VertexOut triangle_vertex_main(uint vertexID [[vertex_id]]) {
|
|
VertexOut out;
|
|
|
|
// Triángulo simple en coordenadas normalized device coordinates
|
|
float2 positions[3] = {
|
|
float2( 0.0, 0.5), // Top
|
|
float2(-0.5, -0.5), // Bottom left
|
|
float2( 0.5, -0.5) // Bottom right
|
|
};
|
|
|
|
float4 colors[3] = {
|
|
float4(1, 0, 0, 1), // Red
|
|
float4(0, 1, 0, 1), // Green
|
|
float4(0, 0, 1, 1) // Blue
|
|
};
|
|
|
|
out.position = float4(positions[vertexID], 0.0, 1.0);
|
|
out.color = colors[vertexID];
|
|
|
|
return out;
|
|
}
|
|
|
|
fragment float4 triangle_fragment_main(VertexOut in [[stage_in]]) {
|
|
return in.color;
|
|
} |