mirror of
https://github.com/aap/librw.git
synced 2025-12-20 01:19:51 +00:00
hardcoded gl3 shaders; extended Image; bmp writer
This commit is contained in:
@@ -420,7 +420,8 @@ initializeRender(void)
|
||||
engine->zNear = -1.0f;
|
||||
engine->zFar = 1.0f;
|
||||
|
||||
simpleShader = Shader::fromFiles("simple.vert", "simple.frag");
|
||||
#include "shaders/simple_gl3.inc"
|
||||
simpleShader = Shader::fromStrings(simple_vert_src, simple_frag_src);
|
||||
|
||||
glClearColor(0.25, 0.25, 0.25, 1.0);
|
||||
|
||||
|
||||
@@ -32,8 +32,9 @@ Shader *envShader;
|
||||
static void*
|
||||
matfxOpen(void *o, int32, int32)
|
||||
{
|
||||
#include "shaders/matfx_gl3.inc"
|
||||
matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline();
|
||||
envShader = Shader::fromFiles("matfx_env.vert", "matfx_env.frag");
|
||||
envShader = Shader::fromStrings(matfx_env_vert_src, matfx_env_frag_src);
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -235,8 +236,10 @@ Shader *skinShader;
|
||||
static void*
|
||||
skinOpen(void *o, int32, int32)
|
||||
{
|
||||
#include "shaders/simple_gl3.inc"
|
||||
#include "shaders/skin_gl3.inc"
|
||||
skinGlobals.pipelines[PLATFORM_GL3] = makeSkinPipeline();
|
||||
skinShader = Shader::fromFiles("skin.vert", "simple.frag");
|
||||
skinShader = Shader::fromStrings(skin_vert_src, simple_frag_src);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,22 +134,18 @@ linkprogram(GLint vs, GLint fs, GLuint *program)
|
||||
}
|
||||
|
||||
Shader*
|
||||
Shader::fromFiles(const char *vspath, const char *fspath)
|
||||
Shader::fromStrings(const char *vsrc, const char *fsrc)
|
||||
{
|
||||
GLuint vs, fs, program;
|
||||
int i;
|
||||
char *src;
|
||||
int fail;
|
||||
|
||||
src = loadfile(vspath);
|
||||
fail = compileshader(GL_VERTEX_SHADER, src, &vs);
|
||||
free(src);
|
||||
fail = compileshader(GL_VERTEX_SHADER, vsrc, &vs);
|
||||
if(fail)
|
||||
return nil;
|
||||
|
||||
src = loadfile(fspath);
|
||||
fail = compileshader(GL_FRAGMENT_SHADER, src, &fs);
|
||||
free(src);
|
||||
fail = compileshader(GL_FRAGMENT_SHADER, fsrc, &fs);
|
||||
if(fail)
|
||||
return nil;
|
||||
|
||||
@@ -179,6 +175,18 @@ Shader::fromFiles(const char *vspath, const char *fspath)
|
||||
return sh;
|
||||
}
|
||||
|
||||
Shader*
|
||||
Shader::fromFiles(const char *vspath, const char *fspath)
|
||||
{
|
||||
char *vsrc, *fsrc;
|
||||
vsrc = loadfile(vspath);
|
||||
fsrc = loadfile(fspath);
|
||||
Shader *s = fromStrings(vsrc, fsrc);
|
||||
free(vsrc);
|
||||
free(fsrc);
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
Shader::use(void)
|
||||
{
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
GLint *uniformLocations;
|
||||
|
||||
static Shader *fromFiles(const char *vs, const char *fs);
|
||||
static Shader *fromStrings(const char *vsrc, const char *fsrc);
|
||||
void use(void);
|
||||
};
|
||||
|
||||
|
||||
23
src/gl/shaders/Makefile
Normal file
23
src/gl/shaders/Makefile
Normal file
@@ -0,0 +1,23 @@
|
||||
all: simple_gl3.inc matfx_gl3.inc skin_gl3.inc
|
||||
|
||||
simple_gl3.inc: simple.frag simple.vert
|
||||
(echo 'const char *simple_vert_src =';\
|
||||
sed 's/..*/"&\\n"/' simple.vert;\
|
||||
echo ';';\
|
||||
echo 'const char *simple_frag_src =';\
|
||||
sed 's/..*/"&\\n"/' simple.frag;\
|
||||
echo ';') >simple_gl3.inc
|
||||
|
||||
matfx_gl3.inc: matfx_env.frag matfx_env.vert
|
||||
(echo 'const char *matfx_env_vert_src =';\
|
||||
sed 's/..*/"&\\n"/' matfx_env.vert;\
|
||||
echo ';';\
|
||||
echo 'const char *matfx_env_frag_src =';\
|
||||
sed 's/..*/"&\\n"/' matfx_env.frag;\
|
||||
echo ';') >matfx_gl3.inc
|
||||
|
||||
skin_gl3.inc: skin.vert
|
||||
(echo 'const char *skin_vert_src =';\
|
||||
sed 's/..*/"&\\n"/' skin.vert;\
|
||||
echo ';') >skin_gl3.inc
|
||||
|
||||
34
src/gl/shaders/matfx_env.frag
Normal file
34
src/gl/shaders/matfx_env.frag
Normal file
@@ -0,0 +1,34 @@
|
||||
#version 330
|
||||
|
||||
layout(std140) uniform State
|
||||
{
|
||||
int u_alphaTest;
|
||||
float u_alphaRef;
|
||||
// fog etc.
|
||||
};
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
in vec4 v_color;
|
||||
in vec2 v_tex0;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
color = v_color*texture2D(tex, vec2(v_tex0.x, v_tex0.y));
|
||||
switch(u_alphaTest){
|
||||
default:
|
||||
case 0: break;
|
||||
case 1:
|
||||
if(color.a < u_alphaRef)
|
||||
discard;
|
||||
break;
|
||||
case 2:
|
||||
if(color.a >= u_alphaRef)
|
||||
discard;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
58
src/gl/shaders/matfx_env.vert
Normal file
58
src/gl/shaders/matfx_env.vert
Normal file
@@ -0,0 +1,58 @@
|
||||
#version 330
|
||||
|
||||
layout(std140) uniform Scene
|
||||
{
|
||||
mat4 u_proj;
|
||||
mat4 u_view;
|
||||
};
|
||||
|
||||
#define MAX_LIGHTS 8
|
||||
struct Light {
|
||||
vec4 position;
|
||||
vec4 direction;
|
||||
vec4 color;
|
||||
float radius;
|
||||
float minusCosAngle;
|
||||
};
|
||||
|
||||
layout(std140) uniform Object
|
||||
{
|
||||
mat4 u_world;
|
||||
vec4 u_ambLight;
|
||||
int u_numLights;
|
||||
Light u_lights[MAX_LIGHTS];
|
||||
};
|
||||
|
||||
uniform vec4 u_matColor;
|
||||
uniform vec4 u_surfaceProps; // amb, spec, diff, extra
|
||||
|
||||
uniform mat4 u_texMatrix;
|
||||
uniform float u_coefficient;
|
||||
|
||||
layout(location = 0) in vec3 in_pos;
|
||||
layout(location = 1) in vec3 in_normal;
|
||||
layout(location = 2) in vec4 in_color;
|
||||
layout(location = 3) in vec2 in_tex0;
|
||||
|
||||
out vec4 v_color;
|
||||
out vec2 v_tex0;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
vec4 V = u_world * vec4(in_pos, 1.0);
|
||||
gl_Position = u_proj * u_view * V;
|
||||
vec3 N = mat3(u_world) * in_normal;
|
||||
|
||||
v_color = in_color;
|
||||
for(int i = 0; i < u_numLights; i++){
|
||||
float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));
|
||||
v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;
|
||||
}
|
||||
v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;
|
||||
v_color *= u_matColor;
|
||||
|
||||
v_color *= u_coefficient;
|
||||
vec3 cN = mat3(u_view) * in_normal;
|
||||
v_tex0 = (u_texMatrix * vec4(cN, 1.0)).xy;
|
||||
}
|
||||
96
src/gl/shaders/matfx_gl3.inc
Normal file
96
src/gl/shaders/matfx_gl3.inc
Normal file
@@ -0,0 +1,96 @@
|
||||
const char *matfx_env_vert_src =
|
||||
"#version 330\n"
|
||||
|
||||
"layout(std140) uniform Scene\n"
|
||||
"{\n"
|
||||
" mat4 u_proj;\n"
|
||||
" mat4 u_view;\n"
|
||||
"};\n"
|
||||
|
||||
"#define MAX_LIGHTS 8\n"
|
||||
"struct Light {\n"
|
||||
" vec4 position;\n"
|
||||
" vec4 direction;\n"
|
||||
" vec4 color;\n"
|
||||
" float radius;\n"
|
||||
" float minusCosAngle;\n"
|
||||
"};\n"
|
||||
|
||||
"layout(std140) uniform Object\n"
|
||||
"{\n"
|
||||
" mat4 u_world;\n"
|
||||
" vec4 u_ambLight;\n"
|
||||
" int u_numLights;\n"
|
||||
" Light u_lights[MAX_LIGHTS];\n"
|
||||
"};\n"
|
||||
|
||||
"uniform vec4 u_matColor;\n"
|
||||
"uniform vec4 u_surfaceProps; // amb, spec, diff, extra\n"
|
||||
|
||||
"uniform mat4 u_texMatrix;\n"
|
||||
"uniform float u_coefficient;\n"
|
||||
|
||||
"layout(location = 0) in vec3 in_pos;\n"
|
||||
"layout(location = 1) in vec3 in_normal;\n"
|
||||
"layout(location = 2) in vec4 in_color;\n"
|
||||
"layout(location = 3) in vec2 in_tex0;\n"
|
||||
|
||||
"out vec4 v_color;\n"
|
||||
"out vec2 v_tex0;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
|
||||
" gl_Position = u_proj * u_view * V;\n"
|
||||
" vec3 N = mat3(u_world) * in_normal;\n"
|
||||
|
||||
" v_color = in_color;\n"
|
||||
" for(int i = 0; i < u_numLights; i++){\n"
|
||||
" float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));\n"
|
||||
" v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;\n"
|
||||
" }\n"
|
||||
" v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;\n"
|
||||
" v_color *= u_matColor;\n"
|
||||
|
||||
" v_color *= u_coefficient;\n"
|
||||
" vec3 cN = mat3(u_view) * in_normal;\n"
|
||||
" v_tex0 = (u_texMatrix * vec4(cN, 1.0)).xy;\n"
|
||||
"}\n"
|
||||
;
|
||||
const char *matfx_env_frag_src =
|
||||
"#version 330\n"
|
||||
|
||||
"layout(std140) uniform State\n"
|
||||
"{\n"
|
||||
" int u_alphaTest;\n"
|
||||
" float u_alphaRef;\n"
|
||||
" // fog etc.\n"
|
||||
"};\n"
|
||||
|
||||
"uniform sampler2D tex;\n"
|
||||
|
||||
"in vec4 v_color;\n"
|
||||
"in vec2 v_tex0;\n"
|
||||
|
||||
"out vec4 color;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" color = v_color*texture2D(tex, vec2(v_tex0.x, v_tex0.y));\n"
|
||||
" switch(u_alphaTest){\n"
|
||||
" default:\n"
|
||||
" case 0: break;\n"
|
||||
" case 1:\n"
|
||||
" if(color.a < u_alphaRef)\n"
|
||||
" discard;\n"
|
||||
" break;\n"
|
||||
" case 2:\n"
|
||||
" if(color.a >= u_alphaRef)\n"
|
||||
" discard;\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
|
||||
;
|
||||
41
src/gl/shaders/simple.frag
Normal file
41
src/gl/shaders/simple.frag
Normal file
@@ -0,0 +1,41 @@
|
||||
#version 330
|
||||
|
||||
layout(std140) uniform State
|
||||
{
|
||||
int u_alphaTest;
|
||||
float u_alphaRef;
|
||||
|
||||
int u_fogEnable;
|
||||
float u_fogStart;
|
||||
float u_fogEnd;
|
||||
vec4 u_fogColor;
|
||||
};
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
in vec4 v_color;
|
||||
in vec2 v_tex0;
|
||||
in float v_fog;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
color = v_color*texture2D(tex, vec2(v_tex0.x, v_tex0.y));
|
||||
if(u_fogEnable != 0)
|
||||
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
|
||||
switch(u_alphaTest){
|
||||
default:
|
||||
case 0: break;
|
||||
case 1:
|
||||
if(color.a < u_alphaRef)
|
||||
discard;
|
||||
break;
|
||||
case 2:
|
||||
if(color.a >= u_alphaRef)
|
||||
discard;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
70
src/gl/shaders/simple.vert
Normal file
70
src/gl/shaders/simple.vert
Normal file
@@ -0,0 +1,70 @@
|
||||
#version 330
|
||||
|
||||
layout(std140) uniform State
|
||||
{
|
||||
int u_alphaTest;
|
||||
float u_alphaRef;
|
||||
|
||||
int u_fogEnable;
|
||||
float u_fogStart;
|
||||
float u_fogEnd;
|
||||
vec4 u_fogColor;
|
||||
};
|
||||
|
||||
layout(std140) uniform Scene
|
||||
{
|
||||
mat4 u_proj;
|
||||
mat4 u_view;
|
||||
};
|
||||
|
||||
#define MAX_LIGHTS 8
|
||||
struct Light {
|
||||
vec4 position;
|
||||
vec4 direction;
|
||||
vec4 color;
|
||||
float radius;
|
||||
float minusCosAngle;
|
||||
};
|
||||
|
||||
layout(std140) uniform Object
|
||||
{
|
||||
mat4 u_world;
|
||||
vec4 u_ambLight;
|
||||
int u_numLights;
|
||||
Light u_lights[MAX_LIGHTS];
|
||||
};
|
||||
|
||||
uniform vec4 u_matColor;
|
||||
uniform vec4 u_surfaceProps; // amb, spec, diff, extra
|
||||
|
||||
layout(location = 0) in vec3 in_pos;
|
||||
layout(location = 1) in vec3 in_normal;
|
||||
layout(location = 2) in vec4 in_color;
|
||||
layout(location = 3) in vec2 in_tex0;
|
||||
|
||||
out vec4 v_color;
|
||||
out vec2 v_tex0;
|
||||
out float v_fog;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
vec3 lightdir = vec3(1.0, 1.0, -1.0);
|
||||
|
||||
vec4 V = u_world * vec4(in_pos, 1.0);
|
||||
vec4 cV = u_view * V;
|
||||
gl_Position = u_proj * cV;
|
||||
vec3 N = mat3(u_world) * in_normal;
|
||||
|
||||
v_color = in_color;
|
||||
for(int i = 0; i < u_numLights; i++){
|
||||
float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));
|
||||
v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;
|
||||
}
|
||||
v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;
|
||||
v_color *= u_matColor;
|
||||
|
||||
v_tex0 = in_tex0;
|
||||
|
||||
v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
|
||||
}
|
||||
115
src/gl/shaders/simple_gl3.inc
Normal file
115
src/gl/shaders/simple_gl3.inc
Normal file
@@ -0,0 +1,115 @@
|
||||
const char *simple_vert_src =
|
||||
"#version 330\n"
|
||||
|
||||
"layout(std140) uniform State\n"
|
||||
"{\n"
|
||||
" int u_alphaTest;\n"
|
||||
" float u_alphaRef;\n"
|
||||
|
||||
" int u_fogEnable;\n"
|
||||
" float u_fogStart;\n"
|
||||
" float u_fogEnd;\n"
|
||||
" vec4 u_fogColor;\n"
|
||||
"};\n"
|
||||
|
||||
"layout(std140) uniform Scene\n"
|
||||
"{\n"
|
||||
" mat4 u_proj;\n"
|
||||
" mat4 u_view;\n"
|
||||
"};\n"
|
||||
|
||||
"#define MAX_LIGHTS 8\n"
|
||||
"struct Light {\n"
|
||||
" vec4 position;\n"
|
||||
" vec4 direction;\n"
|
||||
" vec4 color;\n"
|
||||
" float radius;\n"
|
||||
" float minusCosAngle;\n"
|
||||
"};\n"
|
||||
|
||||
"layout(std140) uniform Object\n"
|
||||
"{\n"
|
||||
" mat4 u_world;\n"
|
||||
" vec4 u_ambLight;\n"
|
||||
" int u_numLights;\n"
|
||||
" Light u_lights[MAX_LIGHTS];\n"
|
||||
"};\n"
|
||||
|
||||
"uniform vec4 u_matColor;\n"
|
||||
"uniform vec4 u_surfaceProps; // amb, spec, diff, extra\n"
|
||||
|
||||
"layout(location = 0) in vec3 in_pos;\n"
|
||||
"layout(location = 1) in vec3 in_normal;\n"
|
||||
"layout(location = 2) in vec4 in_color;\n"
|
||||
"layout(location = 3) in vec2 in_tex0;\n"
|
||||
|
||||
"out vec4 v_color;\n"
|
||||
"out vec2 v_tex0;\n"
|
||||
"out float v_fog;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" vec3 lightdir = vec3(1.0, 1.0, -1.0);\n"
|
||||
|
||||
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
|
||||
" vec4 cV = u_view * V; \n"
|
||||
" gl_Position = u_proj * cV;\n"
|
||||
" vec3 N = mat3(u_world) * in_normal;\n"
|
||||
|
||||
" v_color = in_color;\n"
|
||||
" for(int i = 0; i < u_numLights; i++){\n"
|
||||
" float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));\n"
|
||||
" v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;\n"
|
||||
" }\n"
|
||||
" v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;\n"
|
||||
" v_color *= u_matColor;\n"
|
||||
|
||||
" v_tex0 = in_tex0;\n"
|
||||
|
||||
" v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
|
||||
"}\n"
|
||||
;
|
||||
const char *simple_frag_src =
|
||||
"#version 330\n"
|
||||
|
||||
"layout(std140) uniform State\n"
|
||||
"{\n"
|
||||
" int u_alphaTest;\n"
|
||||
" float u_alphaRef;\n"
|
||||
|
||||
" int u_fogEnable;\n"
|
||||
" float u_fogStart;\n"
|
||||
" float u_fogEnd;\n"
|
||||
" vec4 u_fogColor;\n"
|
||||
"};\n"
|
||||
|
||||
"uniform sampler2D tex;\n"
|
||||
|
||||
"in vec4 v_color;\n"
|
||||
"in vec2 v_tex0;\n"
|
||||
"in float v_fog;\n"
|
||||
|
||||
"out vec4 color;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" color = v_color*texture2D(tex, vec2(v_tex0.x, v_tex0.y));\n"
|
||||
" if(u_fogEnable != 0)\n"
|
||||
" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n"
|
||||
" switch(u_alphaTest){\n"
|
||||
" default:\n"
|
||||
" case 0: break;\n"
|
||||
" case 1:\n"
|
||||
" if(color.a < u_alphaRef)\n"
|
||||
" discard;\n"
|
||||
" break;\n"
|
||||
" case 2:\n"
|
||||
" if(color.a >= u_alphaRef)\n"
|
||||
" discard;\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
|
||||
;
|
||||
78
src/gl/shaders/skin.vert
Normal file
78
src/gl/shaders/skin.vert
Normal file
@@ -0,0 +1,78 @@
|
||||
#version 330
|
||||
|
||||
layout(std140) uniform State
|
||||
{
|
||||
int u_alphaTest;
|
||||
float u_alphaRef;
|
||||
|
||||
int u_fogEnable;
|
||||
float u_fogStart;
|
||||
float u_fogEnd;
|
||||
vec4 u_fogColor;
|
||||
};
|
||||
|
||||
layout(std140) uniform Scene
|
||||
{
|
||||
mat4 u_proj;
|
||||
mat4 u_view;
|
||||
};
|
||||
|
||||
#define MAX_LIGHTS 8
|
||||
struct Light {
|
||||
vec4 position;
|
||||
vec4 direction;
|
||||
vec4 color;
|
||||
float radius;
|
||||
float minusCosAngle;
|
||||
};
|
||||
|
||||
layout(std140) uniform Object
|
||||
{
|
||||
mat4 u_world;
|
||||
vec4 u_ambLight;
|
||||
int u_numLights;
|
||||
Light u_lights[MAX_LIGHTS];
|
||||
};
|
||||
|
||||
uniform vec4 u_matColor;
|
||||
uniform vec4 u_surfaceProps; // amb, spec, diff, extra
|
||||
|
||||
layout(location = 0) in vec3 in_pos;
|
||||
layout(location = 1) in vec3 in_normal;
|
||||
layout(location = 2) in vec4 in_color;
|
||||
layout(location = 3) in vec2 in_tex0;
|
||||
layout(location = 11) in vec4 in_weights;
|
||||
layout(location = 12) in vec4 in_indices;
|
||||
|
||||
uniform mat4 u_boneMatrices[64];
|
||||
|
||||
out vec4 v_color;
|
||||
out vec2 v_tex0;
|
||||
out float v_fog;
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
mat4 m = u_boneMatrices[int(in_indices[0])] * in_weights[0];
|
||||
m += u_boneMatrices[int(in_indices[1])] * in_weights[1];
|
||||
m += u_boneMatrices[int(in_indices[2])] * in_weights[2];
|
||||
m += u_boneMatrices[int(in_indices[3])] * in_weights[3];
|
||||
mat4 world = u_world * m;
|
||||
|
||||
vec4 V = world * vec4(in_pos, 1.0);
|
||||
vec4 cV = u_view * V;
|
||||
gl_Position = u_proj * cV;
|
||||
vec3 N = mat3(world) * in_normal;
|
||||
|
||||
v_color = in_color;
|
||||
for(int i = 0; i < u_numLights; i++){
|
||||
float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));
|
||||
v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;
|
||||
}
|
||||
v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;
|
||||
v_color *= u_matColor;
|
||||
|
||||
v_tex0 = in_tex0;
|
||||
|
||||
v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
|
||||
}
|
||||
80
src/gl/shaders/skin_gl3.inc
Normal file
80
src/gl/shaders/skin_gl3.inc
Normal file
@@ -0,0 +1,80 @@
|
||||
const char *skin_vert_src =
|
||||
"#version 330\n"
|
||||
|
||||
"layout(std140) uniform State\n"
|
||||
"{\n"
|
||||
" int u_alphaTest;\n"
|
||||
" float u_alphaRef;\n"
|
||||
|
||||
" int u_fogEnable;\n"
|
||||
" float u_fogStart;\n"
|
||||
" float u_fogEnd;\n"
|
||||
" vec4 u_fogColor;\n"
|
||||
"};\n"
|
||||
|
||||
"layout(std140) uniform Scene\n"
|
||||
"{\n"
|
||||
" mat4 u_proj;\n"
|
||||
" mat4 u_view;\n"
|
||||
"};\n"
|
||||
|
||||
"#define MAX_LIGHTS 8\n"
|
||||
"struct Light {\n"
|
||||
" vec4 position;\n"
|
||||
" vec4 direction;\n"
|
||||
" vec4 color;\n"
|
||||
" float radius;\n"
|
||||
" float minusCosAngle;\n"
|
||||
"};\n"
|
||||
|
||||
"layout(std140) uniform Object\n"
|
||||
"{\n"
|
||||
" mat4 u_world;\n"
|
||||
" vec4 u_ambLight;\n"
|
||||
" int u_numLights;\n"
|
||||
" Light u_lights[MAX_LIGHTS];\n"
|
||||
"};\n"
|
||||
|
||||
"uniform vec4 u_matColor;\n"
|
||||
"uniform vec4 u_surfaceProps; // amb, spec, diff, extra\n"
|
||||
|
||||
"layout(location = 0) in vec3 in_pos;\n"
|
||||
"layout(location = 1) in vec3 in_normal;\n"
|
||||
"layout(location = 2) in vec4 in_color;\n"
|
||||
"layout(location = 3) in vec2 in_tex0;\n"
|
||||
"layout(location = 11) in vec4 in_weights;\n"
|
||||
"layout(location = 12) in vec4 in_indices;\n"
|
||||
|
||||
"uniform mat4 u_boneMatrices[64];\n"
|
||||
|
||||
"out vec4 v_color;\n"
|
||||
"out vec2 v_tex0;\n"
|
||||
"out float v_fog;\n"
|
||||
|
||||
"void\n"
|
||||
"main(void)\n"
|
||||
"{\n"
|
||||
" mat4 m = u_boneMatrices[int(in_indices[0])] * in_weights[0];\n"
|
||||
" m += u_boneMatrices[int(in_indices[1])] * in_weights[1];\n"
|
||||
" m += u_boneMatrices[int(in_indices[2])] * in_weights[2];\n"
|
||||
" m += u_boneMatrices[int(in_indices[3])] * in_weights[3];\n"
|
||||
" mat4 world = u_world * m;\n"
|
||||
|
||||
" vec4 V = world * vec4(in_pos, 1.0);\n"
|
||||
" vec4 cV = u_view * V; \n"
|
||||
" gl_Position = u_proj * cV;\n"
|
||||
" vec3 N = mat3(world) * in_normal;\n"
|
||||
|
||||
" v_color = in_color;\n"
|
||||
" for(int i = 0; i < u_numLights; i++){\n"
|
||||
" float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));\n"
|
||||
" v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;\n"
|
||||
" }\n"
|
||||
" v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;\n"
|
||||
" v_color *= u_matColor;\n"
|
||||
|
||||
" v_tex0 = in_tex0;\n"
|
||||
|
||||
" v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
|
||||
"}\n"
|
||||
;
|
||||
Reference in New Issue
Block a user