- 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>
29 lines
918 B
Metal
29 lines
918 B
Metal
#include <metal_stdlib>
|
|
using namespace metal;
|
|
|
|
struct SpriteVertexIn {
|
|
float2 position [[attribute(0)]];
|
|
float4 color [[attribute(1)]];
|
|
float2 texCoord [[attribute(2)]];
|
|
};
|
|
|
|
struct SpriteVertexOut {
|
|
float4 position [[position]];
|
|
float4 color;
|
|
float2 texCoord;
|
|
};
|
|
|
|
vertex SpriteVertexOut sprite_vertex_main(SpriteVertexIn in [[stage_in]]) {
|
|
SpriteVertexOut out;
|
|
out.position = float4(in.position, 0.0, 1.0);
|
|
out.color = in.color;
|
|
out.texCoord = in.texCoord;
|
|
return out;
|
|
}
|
|
|
|
fragment float4 sprite_fragment_main(SpriteVertexOut in [[stage_in]],
|
|
texture2d<float> spriteTexture [[texture(0)]],
|
|
sampler textureSampler [[sampler(0)]]) {
|
|
float4 textureColor = spriteTexture.sample(textureSampler, in.texCoord);
|
|
return textureColor * in.color; // Multiplicar textura por color de vértice para tinting
|
|
} |