Spherical billboards

This commit is contained in:
Lubos Lenco 2016-01-25 20:43:11 +01:00
parent 7d233231fd
commit 0358c3122f
201 changed files with 26690 additions and 9681 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,37 +0,0 @@
{
"shader_resources": [
{
"contexts": [
{
"blend_destination": "blend_zero",
"blend_source": "blend_one",
"compare_mode": "always",
"constants": [],
"cull_mode": "none",
"depth_write": false,
"fragment_shader": "deferred_pass.frag",
"id": "deferred_pass",
"texture_units": [
{
"id": "gbuffer0"
},
{
"id": "gbuffer1"
},
{
"id": "gbuffer2"
}
],
"vertex_shader": "deferred_pass.vert"
}
],
"id": "deferred_pass",
"vertex_structure": [
{
"name": "pos",
"size": 2
}
]
}
]
}

View file

@ -1,42 +0,0 @@
{
"shader_resources": [
{
"contexts": [
{
"blend_destination": "blend_zero",
"blend_source": "blend_one",
"compare_mode": "always",
"constants": [
{
"id": "V",
"link": "_viewMatrix",
"type": "mat4"
},
{
"id": "P",
"link": "_projectionMatrix",
"type": "mat4"
}
],
"cull_mode": "none",
"depth_write": false,
"fragment_shader": "env_map.frag",
"id": "env_map",
"texture_units": [
{
"id": "envmap"
}
],
"vertex_shader": "env_map.vert"
}
],
"id": "env_map",
"vertex_structure": [
{
"name": "pos",
"size": 2
}
]
}
]
}

File diff suppressed because it is too large Load diff

View file

@ -2040,6 +2040,10 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
def cb_export_camera(self, object, o):
#return
o.frustum_culling = object.frustum_culling
if object.sort_front_to_back:
o.draw_calls_sort = 'front_to_back'
else:
o.draw_calls_sort = 'none'
o.pipeline = object.pipeline_path
if 'Background' in bpy.data.worlds[0].node_tree.nodes: # TODO: parse node tree
@ -2143,6 +2147,10 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
# GPU Skinning
if ob.find_armature():
defs.append('_Skinning')
# Billboarding
if len(ob.constraints) > 0 and ob.constraints[0].target != None and \
ob.constraints[0].target.type == 'CAMERA' and ob.constraints[0].mute == False:
defs.append('_Billboard')
# Whether objects should export tangent data
if material.export_tangents != normalMapping:

View file

@ -12,22 +12,23 @@ def cb_scene_update(context):
def initProperties():
# For object
bpy.types.Object.geometry_cached = bpy.props.BoolProperty(name="Geometry cached", default=False) # TODO: move to mesh type
bpy.types.Object.instanced_children = bpy.props.BoolProperty(name="Instanced children", default=False)
bpy.types.Object.custom_material = bpy.props.BoolProperty(name="Custom material", default=False)
bpy.types.Object.geometry_cached = bpy.props.BoolProperty(name="Geometry Cached", default=False) # TODO: move to mesh type
bpy.types.Object.instanced_children = bpy.props.BoolProperty(name="Instanced Children", default=False)
bpy.types.Object.custom_material = bpy.props.BoolProperty(name="Custom Material", default=False)
bpy.types.Object.custom_material_name = bpy.props.StringProperty(name="Name", default="")
# For geometry
bpy.types.Mesh.static_usage = bpy.props.BoolProperty(name="Static usage", default=True)
bpy.types.Mesh.static_usage = bpy.props.BoolProperty(name="Static Usage", default=True)
# For camera
bpy.types.Camera.frustum_culling = bpy.props.BoolProperty(name="Frustum Culling", default=False)
bpy.types.Camera.sort_front_to_back = bpy.props.BoolProperty(name="Sort Front to Back", default=False)
bpy.types.Camera.pipeline_path = bpy.props.StringProperty(name="Pipeline Path", default="pipeline_resource/forward_pipeline")
bpy.types.Camera.pipeline_pass = bpy.props.StringProperty(name="Pipeline Pass", default="forward")
# For material
bpy.types.Material.receive_shadow = bpy.props.BoolProperty(name="Receive shadow", default=True)
bpy.types.Material.alpha_test = bpy.props.BoolProperty(name="Alpha test", default=False)
bpy.types.Material.custom_shader = bpy.props.BoolProperty(name="Custom shader", default=False)
bpy.types.Material.receive_shadow = bpy.props.BoolProperty(name="Receive Shadow", default=True)
bpy.types.Material.alpha_test = bpy.props.BoolProperty(name="Alpha Test", default=False)
bpy.types.Material.custom_shader = bpy.props.BoolProperty(name="Custom Shader", default=False)
bpy.types.Material.custom_shader_name = bpy.props.StringProperty(name="Name", default="")
bpy.types.Material.export_tangents = bpy.props.BoolProperty(name="Export tangents", default=False)
bpy.types.Material.export_tangents = bpy.props.BoolProperty(name="Export Tangents", default=False)
# Menu in object region
class ObjectPropsPanel(bpy.types.Panel):
@ -59,6 +60,7 @@ class DataPropsPanel(bpy.types.Panel):
if obj.type == 'CAMERA':
layout.prop(obj.data, 'frustum_culling')
layout.prop(obj.data, 'sort_front_to_back')
layout.prop(obj.data, 'pipeline_path')
layout.prop(obj.data, 'pipeline_pass')
elif obj.type == 'MESH':

View file

@ -18,6 +18,7 @@ project.addAssets('Assets/**');
project.addLibrary('cyclesgame');
project.addAssets('Libraries/cyclesgame/Assets/**');
project.addAssets('Libraries/cyclesgame/compiled/Assets/**');
""")
for ref in shader_references:

File diff suppressed because it is too large Load diff

View file

@ -99,10 +99,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -100,10 +100,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -0,0 +1,149 @@
#define _AlphaTest
#define _Billboard
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,150 @@
#define _AlphaTest
#define _Billboard
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,150 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Skinning
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Skinning
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Skinning
#define _Texturing
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,154 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Skinning
#define _Texturing
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,154 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Skinning
#define _Texturing
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,155 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Skinning
#define _Texturing
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Skinning
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,154 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Skinning
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Texturing
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Texturing
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Texturing
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,154 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _Texturing
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _NormalMapping
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Skinning
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Skinning
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Skinning
#define _Texturing
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Skinning
#define _Texturing
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Skinning
#define _Texturing
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,154 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Skinning
#define _Texturing
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Skinning
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Skinning
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Texturing
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Texturing
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Texturing
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _Texturing
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Instancing
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,150 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Skinning
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Skinning
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Skinning
#define _Texturing
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Skinning
#define _Texturing
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Skinning
#define _Texturing
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,154 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Skinning
#define _Texturing
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Skinning
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Skinning
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Texturing
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Texturing
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Texturing
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _Texturing
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _NormalMapping
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,150 @@
#define _AlphaTest
#define _Billboard
#define _Skinning
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Skinning
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Skinning
#define _Texturing
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Skinning
#define _Texturing
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Skinning
#define _Texturing
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,153 @@
#define _AlphaTest
#define _Billboard
#define _Skinning
#define _Texturing
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Skinning
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Skinning
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,150 @@
#define _AlphaTest
#define _Billboard
#define _Texturing
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Texturing
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _Texturing
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,152 @@
#define _AlphaTest
#define _Billboard
#define _Texturing
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -0,0 +1,150 @@
#define _AlphaTest
#define _Billboard
#define _VCols
#ifdef GL_ES
precision mediump float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
#ifdef _Texturing
uniform sampler2D stex;
#endif
uniform sampler2D shadowMap;
#ifdef _NormalMapping
uniform sampler2D normalMap;
#endif
uniform bool lighting;
uniform bool receiveShadow;
uniform float roughness;
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
float shadowSimple(vec4 lPos) {
vec4 lPosH = lPos / lPos.w;
lPosH.x = (lPosH.x + 1.0) / 2.0;
lPosH.y = 1.0 - ((-lPosH.y + 1.0) / (2.0));
vec4 packedZValue = texture2D(shadowMap, lPosH.st);
float distanceFromLight = packedZValue.z;
//float bias = clamp(0.005*tan(acos(dotNL)), 0, 0.01);
float bias = 0.0;//0.0005;
// 1.0 = not in shadow, 0.0 = in shadow
return float(distanceFromLight > lPosH.z - bias);
}
vec2 LightingFuncGGX_FV(float dotLH, float roughness) {
float alpha = roughness*roughness;
// F
float F_a, F_b;
float dotLH5 = pow(1.0 - dotLH, 5.0);
F_a = 1.0;
F_b = dotLH5;
// V
float vis;
float k = alpha / 2.0;
float k2 = k * k;
float invK2 = 1.0 - k2;
//vis = rcp(dotLH * dotLH * invK2 + k2);
vis = inversesqrt(dotLH * dotLH * invK2 + k2);
return vec2(F_a * vis, F_b * vis);
}
float LightingFuncGGX_D(float dotNH, float roughness) {
float alpha = roughness * roughness;
float alphaSqr = alpha * alpha;
float pi = 3.14159;
float denom = dotNH * dotNH * (alphaSqr - 1.0) + 1.0;
float D = alphaSqr / (pi * denom * denom);
return D;
}
// John Hable - Optimizing GGX Shaders
// http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/
float LightingFuncGGX_OPT3(vec3 N, vec3 V, vec3 L, float roughness, float F0) {
vec3 H = normalize(V + L);
float dotNL = clamp(dot(N, L), 0.0, 1.0);
float dotLH = clamp(dot(L, H), 0.0, 1.0);
float dotNH = clamp(dot(N, H), 0.0, 1.0);
float D = LightingFuncGGX_D(dotNH, roughness);
vec2 FV_helper = LightingFuncGGX_FV(dotLH, roughness);
float FV = F0 * FV_helper.x + (1.0 - F0) * FV_helper.y;
float specular = dotNL * D * FV;
return specular;
}
void main() {
float visibility = 1.0;
// if (receiveShadow && lPos.w > 0.0) {
// visibility = shadowSimple(lPos);
// visibility = (visibility * 0.8) + 0.2;
// }
vec4 outColor;
vec3 t = pow(matColor.rgb, vec3(2.2));
if (lighting) {
float specular = 0.1;
vec3 n = normalize(normal);
vec3 l = lightDir;
vec3 v = eyeDir;
float dotNL = 0.0;
#ifdef _NormalMapping
vec3 tn = normalize(texture2D(normalMap, texCoord).rgb * 2.0 - 1.0);
dotNL = clamp(dot(tn, l), 0.0, 1.0);
#else
dotNL = clamp(dot(n, l), 0.0, 1.0);
#endif
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
vec3 rgb = spec + t * dotNL;
outColor = vec4(vec3(rgb * visibility), 1.0);
}
else {
outColor = vec4(t * visibility, 1.0);
}
#ifdef _Texturing
vec4 texel = texture2D(stex, texCoord);
#ifdef _AlphaTest
if(texel.a < 0.4)
discard;
#endif
outColor = vec4(texel * outColor);
#else
outColor = vec4(outColor.rgb, 1.0);
#endif
gl_FragColor = vec4(pow(outColor.rgb, vec3(1.0 / 2.2)), outColor.a);
}

View file

@ -0,0 +1,151 @@
#define _AlphaTest
#define _Billboard
#define _VCols
#ifdef GL_ES
precision highp float;
#endif
#ifdef _NormalMapping
#define _Texturing
#endif
attribute vec3 pos;
attribute vec3 nor;
#ifdef _Texturing
attribute vec2 tex;
#endif
#ifdef _VCols
attribute vec4 col;
#endif
#ifdef _NormalMapping
attribute vec3 tan;
#endif
#ifdef _Skinning
attribute vec4 bone;
attribute vec4 weight;
#endif
#ifdef _Instancing
attribute vec3 off;
#endif
uniform mat4 M;
uniform mat4 NM;
uniform mat4 V;
uniform mat4 P;
uniform mat4 lightMVP;
uniform vec4 diffuseColor;
uniform vec3 light;
uniform vec3 eye;
#ifdef _Skinning
uniform float skinBones[50 * 12];
#endif
varying vec3 position;
#ifdef _Texturing
varying vec2 texCoord;
#endif
varying vec3 normal;
varying vec4 lPos;
varying vec4 matColor;
varying vec3 lightDir;
varying vec3 eyeDir;
#ifdef _NormalMapping
mat3 transpose(mat3 m) {
return mat3(m[0][0], m[1][0], m[2][0],
m[0][1], m[1][1], m[2][1],
m[0][2], m[1][2], m[2][2]);
}
#endif
#ifdef _Skinning
mat4 getBoneMat(const int boneIndex) {
vec4 v0 = vec4(skinBones[boneIndex * 12 + 0],
skinBones[boneIndex * 12 + 1],
skinBones[boneIndex * 12 + 2],
skinBones[boneIndex * 12 + 3]);
vec4 v1 = vec4(skinBones[boneIndex * 12 + 4],
skinBones[boneIndex * 12 + 5],
skinBones[boneIndex * 12 + 6],
skinBones[boneIndex * 12 + 7]);
vec4 v2 = vec4(skinBones[boneIndex * 12 + 8],
skinBones[boneIndex * 12 + 9],
skinBones[boneIndex * 12 + 10],
skinBones[boneIndex * 12 + 11]);
return mat4(v0.x, v0.y, v0.z, v0.w,
v1.x, v1.y, v1.z, v1.w,
v2.x, v2.y, v2.z, v2.w,
0, 0, 0, 1);
}
mat4 getSkinningMat() {
return weight.x * getBoneMat(int(bone.x)) +
weight.y * getBoneMat(int(bone.y)) +
weight.z * getBoneMat(int(bone.z)) +
weight.w * getBoneMat(int(bone.w));
}
mat3 getSkinningMatVec(const mat4 skinningMat) {
return mat3(skinningMat[0].xyz, skinningMat[1].xyz, skinningMat[2].xyz);
}
#endif
void main() {
#ifdef _Instancing
vec4 sPos = (vec4(pos + off, 1.0));
#else
vec4 sPos = (vec4(pos, 1.0));
#endif
#ifdef _Skinning
mat4 skinningMat = getSkinningMat();
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
lPos = lightMVP * sPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing
texCoord = tex;
#endif
#ifdef _Skinning
normal = normalize(mat3(NM) * (nor * skinningMatVec));
#else
normal = normalize(mat3(NM) * nor);
#endif
matColor = diffuseColor;
#ifdef _VCols
matColor *= col;
#endif
#ifdef _NormalMapping
vec3 vtan = (tan);
vec3 vbitan = cross(normal, vtan) * 1.0;//tangent.w;
mat3 TBN = transpose(mat3(vtan, vbitan, normal));
lightDir = normalize(TBN * lightDir);
eyeDir = normalize(TBN * eyeDir);
#else
lightDir = normalize(light - position);
eyeDir = normalize(eye - position);
#endif
}

View file

@ -101,10 +101,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -102,10 +102,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -103,10 +103,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -104,10 +104,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -105,10 +105,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -104,10 +104,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -103,10 +103,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -104,10 +104,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -103,10 +103,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -102,10 +102,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -103,10 +103,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -104,10 +104,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -103,10 +103,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -102,10 +102,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -103,10 +103,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -102,10 +102,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -101,10 +101,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -102,10 +102,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -103,10 +103,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -104,10 +104,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -103,10 +103,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -102,10 +102,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -103,10 +103,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -102,10 +102,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -101,10 +101,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

View file

@ -102,10 +102,23 @@ void main() {
mat3 skinningMatVec = getSkinningMatVec(skinningMat);
sPos = sPos * skinningMat;
#endif
vec4 mPos = M * sPos;
lPos = lightMVP * sPos;
gl_Position = P * V * mPos;
mat4 VM = V * M;
#ifdef _Billboard
// Spherical
VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
VM[1][0] = 0.0; VM[1][1] = 1.0; VM[1][2] = 0.0;
VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
// Cylindrical
//VM[0][0] = 1.0; VM[0][1] = 0.0; VM[0][2] = 0.0;
//VM[2][0] = 0.0; VM[2][1] = 0.0; VM[2][2] = 1.0;
#endif
gl_Position = P * VM * sPos;
vec4 mPos = M * sPos;
position = mPos.xyz / mPos.w;
#ifdef _Texturing

Some files were not shown because too many files have changed in this diff Show more