Shaders and data files for the irrlicht example

This commit is contained in:
Lucas Baudin 2016-02-25 16:44:55 +01:00
parent 2c9f2c84c5
commit 3a663f8e71
12 changed files with 457 additions and 0 deletions

View File

@ -0,0 +1,142 @@
precision mediump float;
/* Definitions */
#define Solid 0
#define Solid2Layer 1
#define LightMap 2
#define DetailMap 3
#define SphereMap 4
#define Reflection2Layer 5
#define TransparentAlphaChannel 6
#define TransparentAlphaChannelRef 7
#define TransparentVertexAlpha 8
#define TransparentReflection2Layer 9
/* Uniforms */
uniform int uMaterialType;
uniform bool uTextureUsage0;
uniform bool uTextureUsage1;
uniform sampler2D uTextureUnit0;
uniform sampler2D uTextureUnit1;
/* Varyings */
varying vec2 varTexCoord0;
varying vec2 varTexCoord1;
varying vec4 varVertexColor;
varying float varEyeDist;
vec4 renderSolid()
{
vec4 Color = varVertexColor;
if(uTextureUsage0)
Color *= texture2D(uTextureUnit0, varTexCoord0);
Color.a = 1.0;
return Color;
}
vec4 render2LayerSolid()
{
float BlendFactor = varVertexColor.a;
vec4 Texel0 = texture2D(uTextureUnit0, varTexCoord0);
vec4 Texel1 = texture2D(uTextureUnit1, varTexCoord1);
vec4 Color = Texel0 * BlendFactor + Texel1 * (1.0 - BlendFactor);
return Color;
}
vec4 renderLightMap()
{
vec4 Texel0 = texture2D(uTextureUnit0, varTexCoord0);
vec4 Texel1 = texture2D(uTextureUnit1, varTexCoord1);
vec4 Color = Texel0 * Texel1 * 4.0;
Color.a = Texel0.a * Texel0.a;
return Color;
}
vec4 renderDetailMap()
{
vec4 Texel0 = texture2D(uTextureUnit0, varTexCoord0);
vec4 Texel1 = texture2D(uTextureUnit1, varTexCoord1);
vec4 Color = Texel0;
Color += Texel1 - 0.5;
return Color;
}
vec4 renderReflection2Layer()
{
vec4 Color = varVertexColor;
vec4 Texel0 = texture2D(uTextureUnit0, varTexCoord0);
vec4 Texel1 = texture2D(uTextureUnit1, varTexCoord1);
Color *= Texel0 * Texel1;
return Color;
}
vec4 renderTransparent()
{
vec4 Color = vec4(1.0, 1.0, 1.0, 1.0);
if(uTextureUsage0)
Color *= texture2D(uTextureUnit0, varTexCoord0);
return Color;
}
void main ()
{
if (uMaterialType == Solid)
gl_FragColor = renderSolid();
else if(uMaterialType == Solid2Layer)
gl_FragColor = render2LayerSolid();
else if(uMaterialType == LightMap)
gl_FragColor = renderLightMap();
else if(uMaterialType == DetailMap)
gl_FragColor = renderDetailMap();
else if(uMaterialType == SphereMap)
gl_FragColor = renderSolid();
else if(uMaterialType == Reflection2Layer)
gl_FragColor = renderReflection2Layer();
else if(uMaterialType == TransparentAlphaChannel)
gl_FragColor = renderTransparent();
else if(uMaterialType == TransparentAlphaChannelRef)
{
vec4 Color = renderTransparent();
if (Color.a < 0.5)
discard;
gl_FragColor = Color;
}
else if(uMaterialType == TransparentVertexAlpha)
{
vec4 Color = renderTransparent();
Color.a = varVertexColor.a;
gl_FragColor = Color;
}
else if(uMaterialType == TransparentReflection2Layer)
{
vec4 Color = renderReflection2Layer();
Color.a = varVertexColor.a;
gl_FragColor = Color;
}
else
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}

View File

@ -0,0 +1,36 @@
/* Attributes */
attribute vec3 inVertexPosition;
attribute vec3 inVertexNormal;
attribute vec4 inVertexColor;
attribute vec2 inTexCoord0;
attribute vec2 inTexCoord1;
/* Uniforms */
uniform int uMaterialType;
uniform mat4 uMvpMatrix;
uniform mat4 uTextureMatrix0;
uniform mat4 uTextureMatrix1;
/* Varyings */
varying vec2 varTexCoord0;
varying vec2 varTexCoord1;
varying vec4 varVertexColor;
varying float varEyeDist;
void main(void)
{
gl_Position = uMvpMatrix * vec4(inVertexPosition,1.0);
vec4 TexCoord0 = vec4(inTexCoord0.x, inTexCoord0.y, 0.0, 0.0);
varTexCoord0 = vec4(uTextureMatrix0 * TexCoord0).xy;
vec4 TexCoord1 = vec4(inTexCoord1.x, inTexCoord1.y, 0.0, 0.0);
varTexCoord1 = vec4(uTextureMatrix1 * TexCoord1).xy;
varVertexColor = inVertexColor.zyxw;
}

View File

@ -0,0 +1,36 @@
// Copyright (C) 2009-2010 Amundis
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// and OpenGL ES driver implemented by Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#define MAX_LIGHTS 2
precision mediump float;
uniform sampler2D texture0;
uniform sampler2D texture1;
varying vec4 varTexCoord;
varying vec3 varLightVector[MAX_LIGHTS];
varying vec4 varLightColor[MAX_LIGHTS];
varying vec4 debug;
void main(void)
{
// fetch color and normal map
vec4 normalMap = texture2D(texture1, varTexCoord.xy) * 2.0 - 1.0;
vec4 colorMap = texture2D(texture0, varTexCoord.xy);
// calculate color of light 0
vec4 color = clamp(varLightColor[0], 0.0, 1.0) * dot(normalMap.xyz, normalize(varLightVector[0].xyz));
// calculate color of light 1
color += clamp(varLightColor[1], 0.0, 1.0) * dot(normalMap.xyz, normalize(varLightVector[1].xyz));
//luminance * base color
color *= colorMap;
color.a = varLightColor[0].a;
gl_FragColor = color;
}

View File

@ -0,0 +1,69 @@
// Copyright (C) 2009-2010 Amundis
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// and OpenGL ES driver implemented by Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#define MAX_LIGHTS 2
attribute vec4 inVertexPosition;
attribute vec4 inVertexColor;
attribute vec4 inTexCoord0;
attribute vec3 inVertexNormal;
attribute vec3 inVertexTangent;
attribute vec3 inVertexBinormal;
uniform mat4 uMvpMatrix;
uniform vec4 uLightPos[MAX_LIGHTS];
uniform vec4 uLightColor[MAX_LIGHTS];
varying vec4 varTexCoord;
varying vec3 varLightVector[MAX_LIGHTS];
varying vec4 varLightColor[MAX_LIGHTS];
varying vec4 debug;
void main(void)
{
debug = vec4(inVertexNormal, 1.0);
// transform position to clip space
gl_Position = uMvpMatrix * inVertexPosition;
// vertex - lightpositions
vec4 tempLightVector0 = uLightPos[0] - inVertexPosition;
vec4 tempLightVector1 = uLightPos[1] - inVertexPosition;
// transform the light vector 1 with U, V, W
varLightVector[0].x = dot(inVertexTangent, tempLightVector0.xyz);
varLightVector[0].y = dot(inVertexBinormal, tempLightVector0.xyz);
varLightVector[0].z = dot(inVertexNormal, tempLightVector0.xyz);
// transform the light vector 2 with U, V, W
varLightVector[1].x = dot(inVertexTangent, tempLightVector1.xyz);
varLightVector[1].y = dot(inVertexBinormal, tempLightVector1.xyz);
varLightVector[1].z = dot(inVertexNormal, tempLightVector1.xyz);
// calculate attenuation of light 0
varLightColor[0].w = 0.0;
varLightColor[0].x = dot(tempLightVector0, tempLightVector0);
varLightColor[0].x *= uLightColor[0].w;
varLightColor[0] = vec4(inversesqrt(varLightColor[0].x));
varLightColor[0] *= uLightColor[0];
// normalize light vector 0
varLightVector[0] = normalize(varLightVector[0]);
// calculate attenuation of light 1
varLightColor[1].w = 0.0;
varLightColor[1].x = dot(tempLightVector1, tempLightVector1);
varLightColor[1].x *= uLightColor[1].w;
varLightColor[1] = vec4(inversesqrt(varLightColor[1].x));
varLightColor[1] *= uLightColor[1];
// normalize light vector 1
varLightVector[1] = normalize(varLightVector[1]);
// move out texture coordinates and original alpha value
varTexCoord = inTexCoord0;
varLightColor[0].a = inVertexColor.a;
}

View File

@ -0,0 +1,49 @@
// Copyright (C) 2009-2010 Amundis
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// and OpenGL ES driver implemented by Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#define MAX_LIGHTS 2
precision mediump float;
uniform sampler2D texture0;
uniform sampler2D texture1;
//uniform vec4 uLightDiffuse[MAX_LIGHTS];
uniform float uHeightScale;
varying vec4 varTexCoord;
varying vec3 varLightVector[MAX_LIGHTS];
varying vec4 varLightColor[MAX_LIGHTS];
varying vec3 varEyeVector;
varying vec4 debug;
void main(void)
{
// fetch color and normal map
vec4 normalMap = texture2D(texture1, varTexCoord.xy) * 2.0 - 1.0;
// height = height * scale
normalMap *= uHeightScale;
// calculate new texture coord: height * eye + oldTexCoord
vec2 offset = varEyeVector.xy * normalMap.w + varTexCoord.xy;
// fetch new textures
vec4 colorMap = texture2D(texture0, offset);
normalMap = normalize(texture2D(texture1, offset) * 2.0 - 1.0);
// calculate color of light 0
vec4 color = clamp(varLightColor[0], 0.0, 1.0) * dot(normalMap.xyz, normalize(varLightVector[0].xyz));
// calculate color of light 1
color += clamp(varLightColor[1], 0.0, 1.0) * dot(normalMap.xyz, normalize(varLightVector[1].xyz));
//luminance * base color
color *= colorMap;
color.a = varLightColor[0].a;
gl_FragColor = color;
}

View File

@ -0,0 +1,81 @@
// Copyright (C) 2009-2010 Amundis
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// and OpenGL ES driver implemented by Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
#define MAX_LIGHTS 2
attribute vec4 inVertexPosition;
attribute vec4 inVertexColor;
attribute vec4 inTexCoord0;
attribute vec3 inVertexNormal;
attribute vec3 inVertexTangent;
attribute vec3 inVertexBinormal;
uniform mat4 uMvpMatrix;
uniform vec4 uLightPos[MAX_LIGHTS];
uniform vec4 uLightColor[MAX_LIGHTS];
uniform vec3 uEyePos;
varying vec4 varTexCoord;
varying vec3 varLightVector[MAX_LIGHTS];
varying vec4 varLightColor[MAX_LIGHTS];
varying vec3 varEyeVector;
varying vec4 debug;
void main(void)
{
debug = vec4(inVertexNormal, 1.0);
// transform position to clip space
gl_Position = uMvpMatrix * inVertexPosition;
// vertex - lightpositions
vec4 tempLightVector0 = uLightPos[0] - inVertexPosition;
vec4 tempLightVector1 = uLightPos[1] - inVertexPosition;
// eye vector
vec4 Temp = vec4(uEyePos, 1.0) - inVertexPosition;
// transform the light vector 1 with U, V, W
varLightVector[0].x = dot(inVertexTangent, tempLightVector0.xyz);
varLightVector[0].y = dot(inVertexBinormal, tempLightVector0.xyz);
varLightVector[0].z = dot(inVertexNormal, tempLightVector0.xyz);
// transform the light vector 2 with U, V, W
varLightVector[1].x = dot(inVertexTangent, tempLightVector1.xyz);
varLightVector[1].y = dot(inVertexBinormal, tempLightVector1.xyz);
varLightVector[1].z = dot(inVertexNormal, tempLightVector1.xyz);
// transform the eye vector with U, V, W
varEyeVector.x = dot(inVertexTangent, Temp.xyz);
varEyeVector.y = dot(inVertexBinormal, Temp.xyz);
varEyeVector.z = dot(inVertexNormal, Temp.xyz);
varEyeVector *= vec3(1.0,-1.0, -1.0);
varEyeVector = normalize(varEyeVector);
// calculate attenuation of light 0
varLightColor[0].w = 0.0;
varLightColor[0].x = dot(tempLightVector0, tempLightVector0);
varLightColor[0].x *= uLightColor[0].w;
varLightColor[0] = vec4(inversesqrt(varLightColor[0].x));
varLightColor[0] *= uLightColor[0];
// normalize light vector 0
varLightVector[0] = normalize(varLightVector[0]);
// calculate attenuation of light 1
varLightColor[1].w = 0.0;
varLightColor[1].x = dot(tempLightVector1, tempLightVector1);
varLightColor[1].x *= uLightColor[1].w;
varLightColor[1] = vec4(inversesqrt(varLightColor[1].x));
varLightColor[1] *= uLightColor[1];
// normalize light vector 1
varLightVector[1] = normalize(varLightVector[1]);
// move out texture coordinates and original alpha value
varTexCoord = inTexCoord0;
varLightColor[0].a = inVertexColor.a;
}

View File

@ -0,0 +1,23 @@
// Copyright (C) 2009-2010 Amundis
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// and OpenGL ES driver implemented by Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
precision mediump float;
uniform bool uUseTexture;
uniform sampler2D uTextureUnit;
varying vec4 vVertexColor;
varying vec2 vTexCoord;
void main(void)
{
vec4 Color = vVertexColor;
if(uUseTexture)
Color *= texture2D(uTextureUnit, vTexCoord);
gl_FragColor = Color;
}

View File

@ -0,0 +1,21 @@
// Copyright (C) 2009-2010 Amundis
// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
// and OpenGL ES driver implemented by Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in Irrlicht.h
attribute vec4 inVertexPosition;
attribute vec4 inVertexColor;
attribute vec2 inTexCoord0;
uniform mat4 uOrthoMatrix;
varying vec4 vVertexColor;
varying vec2 vTexCoord;
void main(void)
{
gl_Position = uOrthoMatrix * inVertexPosition;
vVertexColor = inVertexColor.bgra;
vTexCoord = inTexCoord0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB