main-vs
This commit is contained in:
1 parent
e37aa6edab
commit
127277e762
5 files changed
+31
-53
No files matched your search
@@ -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);
|
||||
}
|
||||
"""
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../../components/raylib/raylibConstShader.swift
|
||||
Reference in new issue
Block a user