Moved shader code to separate files.

This commit is contained in:
Leonardo Zide 2018-11-22 16:13:02 -08:00
parent 71b5797038
commit 19680a199b
16 changed files with 262 additions and 225 deletions

View file

@ -65,245 +65,105 @@ lcContext::~lcContext()
void lcContext::CreateShaderPrograms() void lcContext::CreateShaderPrograms()
{ {
const char* ShaderPrefix =
{
#ifndef LC_OPENGLES #ifndef LC_OPENGLES
#define LC_SHADER_VERSION "#version 110\n#define mediump\n" "#version 110\n"
#define LC_VERTEX_INPUT "attribute " "#define mediump\n"
#define LC_VERTEX_OUTPUT "varying " "#define LC_VERTEX_INPUT attribute\n"
#define LC_PIXEL_INPUT "varying " "#define LC_VERTEX_OUTPUT varying\n"
#define LC_PIXEL_OUTPUT "#define LC_PIXEL_INPUT varying\n"
#define LC_SHADER_PRECISION "#define LC_PIXEL_OUTPUT\n"
"#define LC_SHADER_PRECISION\n"
#else #else
#define LC_SHADER_VERSION "#version 300 es\n#define texture2D texture\n" "#version 300 es\n"
#define LC_VERTEX_INPUT "in " "#define texture2D texture\n"
#define LC_VERTEX_OUTPUT "out " "#define LC_VERTEX_INPUT in\n"
#define LC_PIXEL_INPUT "in mediump " "#define LC_VERTEX_OUTPUT out\n"
#define LC_PIXEL_OUTPUT "#define gl_FragColor FragColor\nout mediump vec4 gl_FragColor;\n" "#define LC_PIXEL_INPUT in mediump\n"
#define LC_SHADER_PRECISION "mediump " "#define gl_FragColor FragColor\n"
"#define LC_PIXEL_OUTPUT out mediump vec4 gl_FragColor;\n"
"#define LC_SHADER_PRECISION mediump\n"
#endif #endif
#define LC_PIXEL_FAKE_LIGHTING \
LC_SHADER_PRECISION " vec3 Normal = normalize(PixelNormal);\n" \ "#define LC_PIXEL_FAKE_LIGHTING \\\n"
LC_SHADER_PRECISION " vec3 LightDirection = normalize(PixelPosition - LightPosition);" \ " LC_SHADER_PRECISION vec3 Normal = normalize(PixelNormal); \\\n"
LC_SHADER_PRECISION " vec3 VertexToEye = normalize(EyePosition - PixelPosition);\n" \ " LC_SHADER_PRECISION vec3 LightDirection = normalize(PixelPosition - LightPosition); \\\n"
LC_SHADER_PRECISION " vec3 LightReflect = normalize(reflect(-LightDirection, Normal));\n" \ " LC_SHADER_PRECISION vec3 VertexToEye = normalize(EyePosition - PixelPosition); \\\n"
LC_SHADER_PRECISION " float Specular = abs(dot(VertexToEye, LightReflect));\n" \ " LC_SHADER_PRECISION vec3 LightReflect = normalize(reflect(-LightDirection, Normal)); \\\n"
" Specular = min(pow(Specular, 8.0), 1.0) * 0.25;\n" \ " LC_SHADER_PRECISION float Specular = abs(dot(VertexToEye, LightReflect)); \\\n"
LC_SHADER_PRECISION " vec3 SpecularColor = vec3(Specular, Specular, Specular);\n" \ " Specular = min(pow(Specular, 8.0), 1.0) * 0.25; \\\n"
LC_SHADER_PRECISION " float Diffuse = min(abs(dot(Normal, LightDirection)) * 0.6 + 0.65, 1.0);\n" " LC_SHADER_PRECISION vec3 SpecularColor = vec3(Specular, Specular, Specular); \\\n"
" LC_SHADER_PRECISION float Diffuse = min(abs(dot(Normal, LightDirection)) * 0.6 + 0.65, 1.0);\n"
};
const char* VertexShaders[LC_NUM_MATERIALS] = const char* VertexShaders[LC_NUM_MATERIALS] =
{ {
// LC_MATERIAL_UNLIT_COLOR ":/resources/shaders/unlit_color_vs.glsl", // LC_MATERIAL_UNLIT_COLOR
LC_SHADER_VERSION ":/resources/shaders/unlit_texture_modulate_vs.glsl", // LC_MATERIAL_UNLIT_TEXTURE_MODULATE
LC_VERTEX_INPUT "vec3 VertexPosition;\n" ":/resources/shaders/unlit_texture_decal_vs.glsl", // LC_MATERIAL_UNLIT_TEXTURE_DECAL
"uniform mat4 WorldViewProjectionMatrix;\n" ":/resources/shaders/unlit_vertex_color_vs.glsl", // LC_MATERIAL_UNLIT_VERTEX_COLOR
"void main()\n" ":/resources/shaders/unlit_view_sphere_vs.glsl", // LC_MATERIAL_UNLIT_VIEW_SPHERE
"{\n" ":/resources/shaders/fakelit_color_vs.glsl", // LC_MATERIAL_FAKELIT_COLOR
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n" ":/resources/shaders/fakelit_texture_decal_vs.glsl" // LC_MATERIAL_FAKELIT_TEXTURE_DECAL
"}\n",
// LC_MATERIAL_UNLIT_TEXTURE_MODULATE
LC_SHADER_VERSION
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
LC_VERTEX_INPUT "vec2 VertexTexCoord;\n"
LC_VERTEX_OUTPUT "vec2 PixelTexCoord;\n"
"uniform mat4 WorldViewProjectionMatrix;\n"
"void main()\n"
"{\n"
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
" PixelTexCoord = VertexTexCoord;\n"
"}\n",
// LC_MATERIAL_UNLIT_TEXTURE_DECAL
LC_SHADER_VERSION
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
LC_VERTEX_INPUT "vec2 VertexTexCoord;\n"
LC_VERTEX_OUTPUT "vec2 PixelTexCoord;\n"
"uniform mat4 WorldViewProjectionMatrix;\n"
"void main()\n"
"{\n"
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
" PixelTexCoord = VertexTexCoord;\n"
"}\n",
// LC_MATERIAL_UNLIT_VERTEX_COLOR
LC_SHADER_VERSION
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
LC_VERTEX_INPUT "vec4 VertexColor;\n"
LC_VERTEX_OUTPUT "vec4 PixelColor;\n"
"uniform mat4 WorldViewProjectionMatrix;\n"
"void main()\n"
"{\n"
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
" PixelColor = VertexColor;\n"
"}\n",
// LC_MATERIAL_UNLIT_VIEW_SPHERE
LC_SHADER_VERSION
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
LC_VERTEX_OUTPUT "vec3 PixelNormal;\n"
"uniform mat4 WorldViewProjectionMatrix;\n"
"void main()\n"
"{\n"
" PixelNormal = normalize(VertexPosition);\n"
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
"}\n",
// LC_MATERIAL_FAKELIT_COLOR
LC_SHADER_VERSION
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
LC_VERTEX_INPUT "vec3 VertexNormal;\n"
LC_VERTEX_OUTPUT "vec3 PixelPosition;\n"
LC_VERTEX_OUTPUT "vec3 PixelNormal;\n"
"uniform mat4 WorldViewProjectionMatrix;\n"
"uniform mat4 WorldMatrix;\n"
"void main()\n"
"{\n"
" PixelPosition = (WorldMatrix * vec4(VertexPosition, 1.0)).xyz;\n"
" PixelNormal = (WorldMatrix * vec4(VertexNormal, 0.0)).xyz;\n"
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
"}\n",
// LC_MATERIAL_FAKELIT_TEXTURE_DECAL
LC_SHADER_VERSION
LC_VERTEX_INPUT "vec3 VertexPosition;\n"
LC_VERTEX_INPUT "vec3 VertexNormal;\n"
LC_VERTEX_INPUT "vec2 VertexTexCoord;\n"
LC_VERTEX_OUTPUT "vec3 PixelPosition;\n"
LC_VERTEX_OUTPUT "vec3 PixelNormal;\n"
LC_VERTEX_OUTPUT "vec2 PixelTexCoord;\n"
"uniform mat4 WorldViewProjectionMatrix;\n"
"uniform mat4 WorldMatrix;\n"
"void main()\n"
"{\n"
" PixelPosition = (WorldMatrix * vec4(VertexPosition, 1.0)).xyz;\n"
" PixelNormal = (WorldMatrix * vec4(VertexNormal, 0.0)).xyz;\n"
" gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
" PixelTexCoord = VertexTexCoord;\n"
"}\n"
}; };
const char* FragmentShaders[LC_NUM_MATERIALS] = const char* FragmentShaders[LC_NUM_MATERIALS] =
{ {
// LC_MATERIAL_UNLIT_COLOR ":/resources/shaders/unlit_color_ps.glsl", // LC_MATERIAL_UNLIT_COLOR
LC_SHADER_VERSION ":/resources/shaders/unlit_texture_modulate_ps.glsl", // LC_MATERIAL_UNLIT_TEXTURE_MODULATE
LC_PIXEL_OUTPUT ":/resources/shaders/unlit_texture_decal_ps.glsl", // LC_MATERIAL_UNLIT_TEXTURE_DECAL
"uniform mediump vec4 MaterialColor;\n" ":/resources/shaders/unlit_vertex_color_ps.glsl", // LC_MATERIAL_UNLIT_VERTEX_COLOR
"void main()\n" ":/resources/shaders/unlit_view_sphere_ps.glsl", // LC_MATERIAL_UNLIT_VIEW_SPHERE
"{\n" ":/resources/shaders/fakelit_color_ps.glsl", // LC_MATERIAL_FAKELIT_COLOR
" gl_FragColor = MaterialColor;\n" ":/resources/shaders/fakelit_texture_decal_ps.glsl" // LC_MATERIAL_FAKELIT_TEXTURE_DECAL
"}\n", };
// LC_MATERIAL_UNLIT_TEXTURE_MODULATE
LC_SHADER_VERSION auto LoadShader = [ShaderPrefix](const char* FileName, GLuint ShaderType) -> GLuint
LC_PIXEL_INPUT "vec2 PixelTexCoord;\n" {
LC_PIXEL_OUTPUT QResource Resource(FileName);
"uniform mediump vec4 MaterialColor;\n"
"uniform sampler2D Texture;\n" if (!Resource.isValid())
"void main()\n" return 0;
"{\n"
LC_SHADER_PRECISION " vec4 TexelColor = texture2D(Texture, PixelTexCoord);\n" QByteArray Data;
" gl_FragColor = vec4(MaterialColor.rgb, TexelColor.a * MaterialColor.a);\n"
"}\n", if (Resource.isCompressed())
// LC_MATERIAL_UNLIT_TEXTURE_DECAL Data = qUncompress(Resource.data(), Resource.size());
LC_SHADER_VERSION else
LC_PIXEL_INPUT "vec2 PixelTexCoord;\n" Data = QByteArray::fromRawData((const char*)Resource.data(), Resource.size());
LC_PIXEL_OUTPUT
"uniform mediump vec4 MaterialColor;\n" Data = ShaderPrefix + Data;
"uniform sampler2D Texture;\n" const char* Source = Data.constData();
"void main()\n"
"{\n" GLuint Shader = glCreateShader(ShaderType);
LC_SHADER_PRECISION " vec4 TexelColor = texture2D(Texture, PixelTexCoord);\n" glShaderSource(Shader, 1, &Source, nullptr);
" gl_FragColor = mix(MaterialColor, TexelColor, TexelColor.a);\n" glCompileShader(Shader);
"}\n",
// LC_MATERIAL_UNLIT_VERTEX_COLOR #ifndef QT_NO_DEBUG
LC_SHADER_VERSION GLint ShaderCompiled = 0;
LC_PIXEL_INPUT "vec4 PixelColor;\n" glGetShaderiv(Shader, GL_COMPILE_STATUS, &ShaderCompiled);
LC_PIXEL_OUTPUT
"void main()\n" if (ShaderCompiled == GL_FALSE)
"{\n" {
" gl_FragColor = PixelColor;\n" GLint Length = 0;
"}\n", glGetShaderiv(Shader, GL_INFO_LOG_LENGTH, &Length);
// LC_MATERIAL_UNLIT_VIEW_SPHERE
LC_SHADER_VERSION QByteArray InfoLog;
LC_PIXEL_INPUT "vec3 PixelNormal;\n" InfoLog.resize(Length);
LC_PIXEL_OUTPUT glGetShaderInfoLog(Shader, Length, &Length, InfoLog.data());
"uniform mediump vec4 MaterialColor;\n"
"uniform mediump vec4 HighlightColor;\n" qDebug() << InfoLog;
"uniform samplerCube Texture;\n" }
"void main()\n" #endif
"{\n"
" float TexelAlpha = textureCube(Texture, PixelNormal).a;\n" return Shader;
" gl_FragColor = mix(MaterialColor, HighlightColor, TexelAlpha);\n"
"}\n",
// LC_MATERIAL_FAKELIT_COLOR
LC_SHADER_VERSION
LC_PIXEL_INPUT "vec3 PixelPosition;\n"
LC_PIXEL_INPUT "vec3 PixelNormal;\n"
LC_PIXEL_OUTPUT
"uniform mediump vec4 MaterialColor;\n"
"uniform mediump vec3 LightPosition;\n"
"uniform mediump vec3 EyePosition;\n"
"void main()\n"
"{\n"
LC_PIXEL_FAKE_LIGHTING
LC_SHADER_PRECISION " vec3 DiffuseColor = MaterialColor.rgb * Diffuse;\n"
" gl_FragColor = vec4(DiffuseColor + SpecularColor, MaterialColor.a);\n"
"}\n",
// LC_MATERIAL_FAKELIT_TEXTURE_DECAL
LC_SHADER_VERSION
LC_PIXEL_INPUT "vec3 PixelPosition;\n"
LC_PIXEL_INPUT "vec3 PixelNormal;\n"
LC_PIXEL_INPUT "vec2 PixelTexCoord;\n"
LC_PIXEL_OUTPUT
"uniform mediump vec4 MaterialColor;\n"
"uniform mediump vec3 LightPosition;\n"
"uniform mediump vec3 EyePosition;\n"
"uniform sampler2D Texture;\n"
"void main()\n"
"{\n"
LC_PIXEL_FAKE_LIGHTING
LC_SHADER_PRECISION " vec4 TexelColor = texture2D(Texture, PixelTexCoord);"
LC_SHADER_PRECISION " vec4 DiffuseColor = mix(MaterialColor, TexelColor, TexelColor.a);\n"
" gl_FragColor = vec4(vec3(DiffuseColor) * Diffuse + SpecularColor, DiffuseColor.a);\n"
"}\n"
}; };
for (int MaterialType = 0; MaterialType < LC_NUM_MATERIALS; MaterialType++) for (int MaterialType = 0; MaterialType < LC_NUM_MATERIALS; MaterialType++)
{ {
GLuint VertexShader = glCreateShader(GL_VERTEX_SHADER); GLuint VertexShader = LoadShader(VertexShaders[MaterialType], GL_VERTEX_SHADER);
glShaderSource(VertexShader, 1, &VertexShaders[MaterialType], nullptr); GLuint FragmentShader = LoadShader(FragmentShaders[MaterialType], GL_FRAGMENT_SHADER);
glCompileShader(VertexShader);
#ifndef QT_NO_DEBUG
GLint VertexShaderCompiled = 0;
glGetShaderiv(VertexShader, GL_COMPILE_STATUS, &VertexShaderCompiled);
if (VertexShaderCompiled == GL_FALSE)
{
GLint Length = 0;
glGetShaderiv(VertexShader, GL_INFO_LOG_LENGTH, &Length);
QByteArray InfoLog;
InfoLog.resize(Length);
glGetShaderInfoLog(VertexShader, Length, &Length, InfoLog.data());
qDebug() << InfoLog;
}
#endif
GLuint FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(FragmentShader, 1, &FragmentShaders[MaterialType], nullptr);
glCompileShader(FragmentShader);
#ifndef QT_NO_DEBUG
GLint FragmentShaderCompiled = 0;
glGetShaderiv(FragmentShader, GL_COMPILE_STATUS, &FragmentShaderCompiled);
if (FragmentShaderCompiled == GL_FALSE)
{
GLint Length = 0;
glGetShaderiv(FragmentShader, GL_INFO_LOG_LENGTH, &Length);
QByteArray InfoLog;
InfoLog.resize(Length);
glGetShaderInfoLog(FragmentShader, Length, &Length, InfoLog.data());
qDebug() << InfoLog;
}
#endif
GLuint Program = glCreateProgram(); GLuint Program = glCreateProgram();
@ -324,6 +184,7 @@ void lcContext::CreateShaderPrograms()
GLint IsLinked = 0; GLint IsLinked = 0;
glGetProgramiv(Program, GL_LINK_STATUS, &IsLinked); glGetProgramiv(Program, GL_LINK_STATUS, &IsLinked);
if (IsLinked == GL_FALSE) if (IsLinked == GL_FALSE)
{ {
GLint Length = 0; GLint Length = 0;

View file

@ -96,5 +96,19 @@
<file>resources/leocad_fr.qm</file> <file>resources/leocad_fr.qm</file>
<file>resources/leocad_pt.qm</file> <file>resources/leocad_pt.qm</file>
<file>resources/leocad_de.qm</file> <file>resources/leocad_de.qm</file>
<file>resources/shaders/fakelit_color_ps.glsl</file>
<file>resources/shaders/fakelit_color_vs.glsl</file>
<file>resources/shaders/fakelit_texture_decal_ps.glsl</file>
<file>resources/shaders/fakelit_texture_decal_vs.glsl</file>
<file>resources/shaders/unlit_color_ps.glsl</file>
<file>resources/shaders/unlit_color_vs.glsl</file>
<file>resources/shaders/unlit_texture_decal_ps.glsl</file>
<file>resources/shaders/unlit_texture_decal_vs.glsl</file>
<file>resources/shaders/unlit_texture_modulate_ps.glsl</file>
<file>resources/shaders/unlit_texture_modulate_vs.glsl</file>
<file>resources/shaders/unlit_vertex_color_ps.glsl</file>
<file>resources/shaders/unlit_vertex_color_vs.glsl</file>
<file>resources/shaders/unlit_view_sphere_ps.glsl</file>
<file>resources/shaders/unlit_view_sphere_vs.glsl</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -0,0 +1,14 @@
LC_PIXEL_INPUT vec3 PixelPosition;
LC_PIXEL_INPUT vec3 PixelNormal;
LC_PIXEL_OUTPUT
uniform mediump vec4 MaterialColor;
uniform mediump vec3 LightPosition;
uniform mediump vec3 EyePosition;
void main()
{
LC_PIXEL_FAKE_LIGHTING
LC_SHADER_PRECISION vec3 DiffuseColor = MaterialColor.rgb * Diffuse;
gl_FragColor = vec4(DiffuseColor + SpecularColor, MaterialColor.a);
}

View file

@ -0,0 +1,14 @@
LC_VERTEX_INPUT vec3 VertexPosition;
LC_VERTEX_INPUT vec3 VertexNormal;
LC_VERTEX_OUTPUT vec3 PixelPosition;
LC_VERTEX_OUTPUT vec3 PixelNormal;
uniform mat4 WorldViewProjectionMatrix;
uniform mat4 WorldMatrix;
void main()
{
PixelPosition = (WorldMatrix * vec4(VertexPosition, 1.0)).xyz;
PixelNormal = (WorldMatrix * vec4(VertexNormal, 0.0)).xyz;
gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);
}

View file

@ -0,0 +1,17 @@
LC_PIXEL_INPUT vec3 PixelPosition;
LC_PIXEL_INPUT vec3 PixelNormal;
LC_PIXEL_INPUT vec2 PixelTexCoord;
LC_PIXEL_OUTPUT
uniform mediump vec4 MaterialColor;
uniform mediump vec3 LightPosition;
uniform mediump vec3 EyePosition;
uniform sampler2D Texture;
void main()
{
LC_PIXEL_FAKE_LIGHTING
LC_SHADER_PRECISION vec4 TexelColor = texture2D(Texture, PixelTexCoord);
LC_SHADER_PRECISION vec4 DiffuseColor = mix(MaterialColor, TexelColor, TexelColor.a);
gl_FragColor = vec4(vec3(DiffuseColor) * Diffuse + SpecularColor, DiffuseColor.a);
}

View file

@ -0,0 +1,17 @@
LC_VERTEX_INPUT vec3 VertexPosition;
LC_VERTEX_INPUT vec3 VertexNormal;
LC_VERTEX_INPUT vec2 VertexTexCoord;
LC_VERTEX_OUTPUT vec3 PixelPosition;
LC_VERTEX_OUTPUT vec3 PixelNormal;
LC_VERTEX_OUTPUT vec2 PixelTexCoord;
uniform mat4 WorldViewProjectionMatrix;
uniform mat4 WorldMatrix;
void main()
{
PixelPosition = (WorldMatrix * vec4(VertexPosition, 1.0)).xyz;
PixelNormal = (WorldMatrix * vec4(VertexNormal, 0.0)).xyz;
gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);
PixelTexCoord = VertexTexCoord;
}

View file

@ -0,0 +1,8 @@
LC_PIXEL_OUTPUT
uniform mediump vec4 MaterialColor;
void main()
{
gl_FragColor = MaterialColor;
}

View file

@ -0,0 +1,8 @@
LC_VERTEX_INPUT vec3 VertexPosition;
uniform mat4 WorldViewProjectionMatrix;
void main()
{
gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);
}

View file

@ -0,0 +1,11 @@
LC_PIXEL_INPUT vec2 PixelTexCoord;
LC_PIXEL_OUTPUT
uniform mediump vec4 MaterialColor;
uniform sampler2D Texture;
void main()
{
LC_SHADER_PRECISION vec4 TexelColor = texture2D(Texture, PixelTexCoord);
gl_FragColor = mix(MaterialColor, TexelColor, TexelColor.a);
}

View file

@ -0,0 +1,11 @@
LC_VERTEX_INPUT vec3 VertexPosition;
LC_VERTEX_INPUT vec2 VertexTexCoord;
LC_VERTEX_OUTPUT vec2 PixelTexCoord;
uniform mat4 WorldViewProjectionMatrix;
void main()
{
gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);
PixelTexCoord = VertexTexCoord;
}

View file

@ -0,0 +1,11 @@
LC_PIXEL_INPUT vec2 PixelTexCoord;
LC_PIXEL_OUTPUT
uniform mediump vec4 MaterialColor;
uniform sampler2D Texture;
void main()
{
LC_SHADER_PRECISION vec4 TexelColor = texture2D(Texture, PixelTexCoord);
gl_FragColor = vec4(MaterialColor.rgb, TexelColor.a * MaterialColor.a);
}

View file

@ -0,0 +1,11 @@
LC_VERTEX_INPUT vec3 VertexPosition;
LC_VERTEX_INPUT vec2 VertexTexCoord;
LC_VERTEX_OUTPUT vec2 PixelTexCoord;
uniform mat4 WorldViewProjectionMatrix;
void main()
{
gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);
PixelTexCoord = VertexTexCoord;
}

View file

@ -0,0 +1,7 @@
LC_PIXEL_INPUT vec4 PixelColor;
LC_PIXEL_OUTPUT
void main()
{
gl_FragColor = PixelColor;
}

View file

@ -0,0 +1,11 @@
LC_VERTEX_INPUT vec3 VertexPosition;
LC_VERTEX_INPUT vec4 VertexColor;
LC_VERTEX_OUTPUT vec4 PixelColor;
uniform mat4 WorldViewProjectionMatrix;
void main()
{
gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);
PixelColor = VertexColor;
}

View file

@ -0,0 +1,12 @@
LC_PIXEL_INPUT vec3 PixelNormal;
LC_PIXEL_OUTPUT
uniform mediump vec4 MaterialColor;
uniform mediump vec4 HighlightColor;
uniform samplerCube Texture;
void main()
{
LC_SHADER_PRECISION float TexelAlpha = textureCube(Texture, PixelNormal).a;
gl_FragColor = mix(MaterialColor, HighlightColor, TexelAlpha);
}

View file

@ -0,0 +1,10 @@
LC_VERTEX_INPUT vec3 VertexPosition;
LC_VERTEX_OUTPUT vec3 PixelNormal;
uniform mat4 WorldViewProjectionMatrix;
void main()
{
PixelNormal = normalize(VertexPosition);
gl_Position = WorldViewProjectionMatrix * vec4(VertexPosition, 1.0);
}