diff --git a/components/raylib/raylibConstShader.swift b/components/raylib/raylibConstShader.swift index 7ce3514..99af6a9 100644 --- a/components/raylib/raylibConstShader.swift +++ b/components/raylib/raylibConstShader.swift @@ -1,25 +1,25 @@ let RAYLIB_SHADER_MAIN_VS = """ - "#version 330\n" - "layout(location = 0) in vec3 vertexPosition;\n" - "layout(location = 1) in vec2 vertexTexCoord;\n" - "layout(location = 2) in vec3 vertexNormal;\n" - "\n" - "uniform mat4 mvp;\n" - "uniform mat4 matModel;\n" - "uniform mat4 u_lightMVP;\n" - "\n" - "out vec3 vWorldPos;\n" - "out vec3 vNormal;\n" - "out vec2 vTexCoord;\n" - "out vec4 vLightClip;\n" - "\n" - "void main()\n" - "{\n" - " vec4 worldPos = matModel * vec4(vertexPosition, 1.0);\n" - " vWorldPos = worldPos.xyz;\n" - " vNormal = normalize(mat3(matModel) * vertexNormal);\n" - " vTexCoord = vertexTexCoord;\n" - " vLightClip = u_lightMVP * vec4(vertexPosition, 1.0);\n" - " gl_Position = mvp * vec4(vertexPosition, 1.0);\n" - "}\n"; +#version 330 +layout(location = 0) in vec3 vertexPosition; +layout(location = 1) in vec2 vertexTexCoord; +layout(location = 2) in vec3 vertexNormal; + +uniform mat4 mvp; +uniform mat4 matModel; +uniform mat4 u_lightMVP; + +out vec3 vWorldPos; +out vec3 vNormal; +out vec2 vTexCoord; +out vec4 vLightClip; + +void main() +{ + vec4 worldPos = matModel * vec4(vertexPosition, 1.0); + vWorldPos = worldPos.xyz; + vNormal = normalize(mat3(matModel) * vertexNormal); + vTexCoord = vertexTexCoord; + vLightClip = u_lightMVP * vec4(vertexPosition, 1.0); + gl_Position = mvp * vec4(vertexPosition, 1.0); +} """ diff --git a/components/root/mac/view/RaylibGLView.swift b/components/root/mac/view/RaylibGLView.swift index 68d2019..acebf62 100644 --- a/components/root/mac/view/RaylibGLView.swift +++ b/components/root/mac/view/RaylibGLView.swift @@ -57,7 +57,7 @@ final class RaylibGLNSView: NSOpenGLView { context.setValues(&swapInterval, for: .swapInterval) updatePixelSize() - sr_init(pixelWidth, pixelHeight) + sr_init(pixelWidth, pixelHeight, RAYLIB_SHADER_MAIN_VS) loadModel() startTime = CACurrentMediaTime() ready = true diff --git a/game/ver-mac/bridge/include/raylib_bridge.h b/game/ver-mac/bridge/include/raylib_bridge.h index fcaf199..7b1b2f4 100644 --- a/game/ver-mac/bridge/include/raylib_bridge.h +++ b/game/ver-mac/bridge/include/raylib_bridge.h @@ -6,7 +6,8 @@ extern "C" { #endif // Initialise the OpenGL-backed raylib scene (no raylib window is created). -void sr_init(int width, int height); +// main_vs is the main vertex shader source (see raylibConstShader.swift). +void sr_init(int width, int height, const char *main_vs); // Load the textured cube glTF model. void sr_load_model(const char *gltf_path); diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index cf0a6ef..5f3af20 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -88,30 +88,6 @@ static Matrix sr_transform(Vector3 pos, float scale, float rx, float ry, float r return MatrixMultiply(MatrixMultiply(mat_scale, mat_rotation), mat_translation); } -static const char *SR_MAIN_VS = - "#version 330\n" - "layout(location = 0) in vec3 vertexPosition;\n" - "layout(location = 1) in vec2 vertexTexCoord;\n" - "layout(location = 2) in vec3 vertexNormal;\n" - "\n" - "uniform mat4 mvp;\n" - "uniform mat4 matModel;\n" - "uniform mat4 u_lightMVP;\n" - "\n" - "out vec3 vWorldPos;\n" - "out vec3 vNormal;\n" - "out vec2 vTexCoord;\n" - "out vec4 vLightClip;\n" - "\n" - "void main()\n" - "{\n" - " vec4 worldPos = matModel * vec4(vertexPosition, 1.0);\n" - " vWorldPos = worldPos.xyz;\n" - " vNormal = normalize(mat3(matModel) * vertexNormal);\n" - " vTexCoord = vertexTexCoord;\n" - " vLightClip = u_lightMVP * vec4(vertexPosition, 1.0);\n" - " gl_Position = mvp * vec4(vertexPosition, 1.0);\n" - "}\n"; static const char *SR_MAIN_FS = "#version 330\n" @@ -224,9 +200,9 @@ static const char *SR_SHADOW_FS = " finalColor = vec4(1.0);\n" "}\n"; -static void sr_load_shaders(void) +static void sr_load_shaders(const char *main_vs) { - sr_main_shader = LoadShaderFromMemory(SR_MAIN_VS, SR_MAIN_FS); + sr_main_shader = LoadShaderFromMemory(main_vs, SR_MAIN_FS); sr_shadow_shader = LoadShaderFromMemory(SR_SHADOW_VS, SR_SHADOW_FS); loc_light_pos = GetShaderLocation(sr_main_shader, "u_lightPos"); @@ -270,7 +246,7 @@ static void sr_build_ground(void) sr_ground_shadow_material.shader = sr_shadow_shader; } -void sr_init(int width, int height) +void sr_init(int width, int height, const char *main_vs) { if (width > 0) sr_width = width; if (height > 0) sr_height = height; @@ -278,7 +254,7 @@ void sr_init(int width, int height) rlLoadExtensions(sr_gl_loader); rlglInit(sr_width, sr_height); - sr_load_shaders(); + sr_load_shaders(main_vs); sr_build_ground(); sr_ready = 1; diff --git a/game/ver-mac/src/raylib/raylibConstShader.swift b/game/ver-mac/src/raylib/raylibConstShader.swift new file mode 120000 index 0000000..f8a6bf6 --- /dev/null +++ b/game/ver-mac/src/raylib/raylibConstShader.swift @@ -0,0 +1 @@ +../../../../components/raylib/raylibConstShader.swift \ No newline at end of file