WIP: Metal shader backend para macOS
- Shaders MSL portados desde GLSL (vertex + fragment) - Estructura básica de MetalShader class - Device, command queue, pipeline y buffers creados - CMakeLists.txt actualizado con Metal frameworks - assets.txt incluye shaders .metal como opcionales PENDIENTE: - Implementar render() loop completo - Obtener MTLTexture desde SDL_Texture - Crear sampler state - Testing en macOS real Ver METAL_BACKEND_NOTES.md para detalles de implementación.
This commit is contained in:
46
data/shaders/crtpi_vertex.metal
Normal file
46
data/shaders/crtpi_vertex.metal
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// CRT-Pi Vertex Shader - Metal Shading Language
|
||||
// Portado desde GLSL a MSL para macOS
|
||||
//
|
||||
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
|
||||
// Estructura de entrada del vertex shader (desde el buffer de vértices)
|
||||
struct VertexIn {
|
||||
float2 position [[attribute(0)]]; // Posición del vértice
|
||||
float2 texCoord [[attribute(1)]]; // Coordenadas de textura
|
||||
};
|
||||
|
||||
// Estructura de salida del vertex shader (entrada al fragment shader)
|
||||
struct VertexOut {
|
||||
float4 position [[position]]; // Posición en clip space
|
||||
float2 texCoord; // Coordenadas de textura
|
||||
float filterWidth; // Ancho del filtro calculado
|
||||
// float2 screenScale; // Solo si CURVATURE está activo
|
||||
};
|
||||
|
||||
// Uniforms (constantes del shader)
|
||||
struct Uniforms {
|
||||
float2 textureSize; // Tamaño de la textura (width, height)
|
||||
};
|
||||
|
||||
// Entry point del vertex shader
|
||||
vertex VertexOut vertex_main(VertexIn in [[stage_in]],
|
||||
constant Uniforms& uniforms [[buffer(1)]]) {
|
||||
VertexOut out;
|
||||
|
||||
// Posición del vértice (ya está en espacio de clip [-1, 1])
|
||||
out.position = float4(in.position, 0.0, 1.0);
|
||||
|
||||
// Pasar coordenadas de textura (invertir Y para SDL, igual que en GLSL)
|
||||
out.texCoord = float2(in.texCoord.x, 1.0 - in.texCoord.y) * 1.0001;
|
||||
|
||||
// Calcular filterWidth dinámicamente basándose en la altura de la textura
|
||||
out.filterWidth = (768.0 / uniforms.textureSize.y) / 3.0;
|
||||
|
||||
// Si CURVATURE estuviera activo:
|
||||
// out.screenScale = float2(1.0, 1.0);
|
||||
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user