From 91736e194171aafe0c532f093116ff6d397be394 Mon Sep 17 00:00:00 2001 From: samuncle Date: Sat, 22 Nov 2014 15:59:22 +0100 Subject: [PATCH] Add the support for emit map. For the moment it's only for solid objects --- data/shaders/detailledobject_pass2.frag | 4 ++-- data/shaders/grass_pass2.frag | 4 ++-- data/shaders/instanced_detailledobject_pass2.frag | 4 ++-- data/shaders/instanced_grass_pass2.frag | 4 ++-- data/shaders/instanced_object_pass2.frag | 7 +++++-- data/shaders/instanced_objectpass_spheremap.frag | 4 ++-- data/shaders/instanced_objectref_pass2.frag | 4 ++-- data/shaders/object_pass2.frag | 4 ++-- data/shaders/objectpass_spheremap.frag | 4 ++-- data/shaders/objectref_pass2.frag | 4 ++-- data/shaders/splatting.frag | 4 ++-- data/shaders/utils/getLightFactor.frag | 7 ++++--- 12 files changed, 29 insertions(+), 25 deletions(-) diff --git a/data/shaders/detailledobject_pass2.frag b/data/shaders/detailledobject_pass2.frag index 5b19966cc..cc26f70dd 100644 --- a/data/shaders/detailledobject_pass2.frag +++ b/data/shaders/detailledobject_pass2.frag @@ -18,7 +18,7 @@ varying vec2 uv_bis; #define FragColor gl_FragColor #endif -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main(void) { @@ -31,5 +31,5 @@ void main(void) vec4 detail = texture(Detail, uv_bis); color *= detail; float specmap = texture(SpecMap, uv).g; - FragColor = vec4(getLightFactor(color.xyz, vec3(1.), specmap), 1.); + FragColor = vec4(getLightFactor(color.xyz, vec3(1.), specmap, 0.), 1.); } diff --git a/data/shaders/grass_pass2.frag b/data/shaders/grass_pass2.frag index 6b677ceea..ac5586321 100644 --- a/data/shaders/grass_pass2.frag +++ b/data/shaders/grass_pass2.frag @@ -14,7 +14,7 @@ in vec3 nor; in vec2 uv; out vec4 FragColor; -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main(void) { @@ -42,6 +42,6 @@ void main(void) float scattering = mix(fPowEdotL, fLdotNBack, .5); float specmap = texture(SpecMap, uv).g; - vec3 LightFactor = color.xyz * (scattering * 0.3) + getLightFactor(color.xyz, vec3(1.), specmap); + vec3 LightFactor = color.xyz * (scattering * 0.3) + getLightFactor(color.xyz, vec3(1.), specmap, 0.); FragColor = vec4(color.xyz * LightFactor, 1.); } diff --git a/data/shaders/instanced_detailledobject_pass2.frag b/data/shaders/instanced_detailledobject_pass2.frag index 927a6a845..ea5f3cd4a 100644 --- a/data/shaders/instanced_detailledobject_pass2.frag +++ b/data/shaders/instanced_detailledobject_pass2.frag @@ -13,7 +13,7 @@ in vec2 uv; in vec2 uv_bis; out vec4 FragColor; -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main(void) { @@ -30,5 +30,5 @@ void main(void) float specmap = texture(SpecMap, uv).g; #endif color *= detail; - FragColor = vec4(getLightFactor(color.xyz, vec3(1.), specmap), 1.); + FragColor = vec4(getLightFactor(color.xyz, vec3(1.), specmap, 0.), 1.); } diff --git a/data/shaders/instanced_grass_pass2.frag b/data/shaders/instanced_grass_pass2.frag index 0a7787559..b06742743 100644 --- a/data/shaders/instanced_grass_pass2.frag +++ b/data/shaders/instanced_grass_pass2.frag @@ -16,7 +16,7 @@ in vec3 nor; in vec2 uv; out vec4 FragColor; -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main(void) { @@ -48,6 +48,6 @@ void main(void) float scattering = mix(fPowEdotL, fLdotNBack, .5); - vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap); + vec3 LightFactor = color.xyz * (scattering * 0.1) + getLightFactor(color.xyz, vec3(1.), specmap, 0.); FragColor = vec4(LightFactor, 1.); } diff --git a/data/shaders/instanced_object_pass2.frag b/data/shaders/instanced_object_pass2.frag index c260d7aab..982c795c1 100644 --- a/data/shaders/instanced_object_pass2.frag +++ b/data/shaders/instanced_object_pass2.frag @@ -11,20 +11,23 @@ in vec2 uv; in vec4 color; out vec4 FragColor; -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main(void) { #ifdef GL_ARB_bindless_texture vec4 col = texture(handle, uv); float specmap = texture(secondhandle, uv).g; + float emitmap = texture(secondhandle, uv).b; #ifdef SRGBBindlessFix col.xyz = pow(col.xyz, vec3(2.2)); #endif #else vec4 col = texture(Albedo, uv); float specmap = texture(SpecMap, uv).g; + float emitmap = texture(SpecMap, uv).b; #endif col.xyz *= pow(color.xyz, vec3(2.2)); - FragColor = vec4(getLightFactor(col.xyz, vec3(1.), specmap), 1.); + + FragColor = vec4(getLightFactor(col.xyz, vec3(1.), specmap, emitmap) , 1.); } diff --git a/data/shaders/instanced_objectpass_spheremap.frag b/data/shaders/instanced_objectpass_spheremap.frag index 21414ee31..3795e6c17 100644 --- a/data/shaders/instanced_objectpass_spheremap.frag +++ b/data/shaders/instanced_objectpass_spheremap.frag @@ -12,7 +12,7 @@ out vec4 FragColor; vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix); -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main() { vec3 texc = gl_FragCoord.xyz / vec3(screen, 1.); @@ -30,5 +30,5 @@ void main() { vec4 detail0 = texture(tex, r.xy / m + .5); #endif - FragColor = vec4(getLightFactor(detail0.xyz, vec3(1.), 0.), 1.); + FragColor = vec4(getLightFactor(detail0.xyz, vec3(1.), 0., 0.), 1.); } diff --git a/data/shaders/instanced_objectref_pass2.frag b/data/shaders/instanced_objectref_pass2.frag index 41f3dc34f..2a8e64172 100644 --- a/data/shaders/instanced_objectref_pass2.frag +++ b/data/shaders/instanced_objectref_pass2.frag @@ -11,7 +11,7 @@ in vec2 uv; in vec4 color; out vec4 FragColor; -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main(void) { @@ -27,5 +27,5 @@ void main(void) #endif col.xyz *= pow(color.xyz, vec3(2.2)); if (col.a * color.a < 0.5) discard; - FragColor = vec4(getLightFactor(col.xyz, vec3(1.), specmap), 1.); + FragColor = vec4(getLightFactor(col.xyz, vec3(1.), specmap, 0.), 1.); } diff --git a/data/shaders/object_pass2.frag b/data/shaders/object_pass2.frag index ba984f87d..25e463240 100644 --- a/data/shaders/object_pass2.frag +++ b/data/shaders/object_pass2.frag @@ -10,7 +10,7 @@ in vec2 uv; in vec4 color; out vec4 FragColor; -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main(void) { @@ -24,5 +24,5 @@ void main(void) #endif col.xyz *= pow(color.xyz, vec3(2.2)); float specmap = texture(SpecMap, uv).g; - FragColor = vec4(getLightFactor(col.xyz, vec3(1.), specmap), 1.); + FragColor = vec4(getLightFactor(col.xyz, vec3(1.), specmap, 0.), 1.); } diff --git a/data/shaders/objectpass_spheremap.frag b/data/shaders/objectpass_spheremap.frag index e5ed033d1..6d09b8294 100644 --- a/data/shaders/objectpass_spheremap.frag +++ b/data/shaders/objectpass_spheremap.frag @@ -15,7 +15,7 @@ varying vec3 nor; #endif vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix); -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main() { vec3 texc = gl_FragCoord.xyz / vec3(screen, 1.); @@ -31,5 +31,5 @@ void main() { #endif #endif - FragColor = vec4(getLightFactor(detail0.xyz, vec3(1.), 0.), 1.); + FragColor = vec4(getLightFactor(detail0.xyz, vec3(1.), 0., 0.), 1.); } diff --git a/data/shaders/objectref_pass2.frag b/data/shaders/objectref_pass2.frag index a7fd08dca..04b139d61 100644 --- a/data/shaders/objectref_pass2.frag +++ b/data/shaders/objectref_pass2.frag @@ -10,7 +10,7 @@ in vec2 uv; in vec4 color; out vec4 FragColor; -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main(void) { @@ -23,5 +23,5 @@ void main(void) col.xyz *= pow(color.xyz, vec3(2.2)); if (col.a * color.a < 0.5) discard; float specmap = texture(SpecMap, uv).g; - FragColor = vec4(getLightFactor(col.xyz, vec3(1.), specmap), 1.); + FragColor = vec4(getLightFactor(col.xyz, vec3(1.), specmap, 0.), 1.); } diff --git a/data/shaders/splatting.frag b/data/shaders/splatting.frag index acc6fabc3..e98e8ca25 100644 --- a/data/shaders/splatting.frag +++ b/data/shaders/splatting.frag @@ -22,7 +22,7 @@ varying vec2 uv_bis; #define FragColor gl_FragColor #endif -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue); +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue); void main() { // Splatting part @@ -46,5 +46,5 @@ void main() { splatting.b * detail2 + max(0., (1.0 - splatting.r - splatting.g - splatting.b)) * detail3; - FragColor = vec4(getLightFactor(splatted.xyz, vec3(1.), 0.), 1.); + FragColor = vec4(getLightFactor(splatted.xyz, vec3(1.), 0., 0.), 1.); } diff --git a/data/shaders/utils/getLightFactor.frag b/data/shaders/utils/getLightFactor.frag index 7d974d56d..bb63d53d6 100644 --- a/data/shaders/utils/getLightFactor.frag +++ b/data/shaders/utils/getLightFactor.frag @@ -8,12 +8,13 @@ uniform sampler2D SpecularMap; uniform sampler2D SSAO; #endif -vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue) +vec3 getLightFactor(vec3 diffuseMatColor, vec3 specularMatColor, float specMapValue, float emitMapValue) { vec2 tc = gl_FragCoord.xy / screen; vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz; vec3 SpecularComponent = texture(SpecularMap, tc).xyz; float ao = texture(SSAO, tc).x; vec3 tmp = diffuseMatColor * DiffuseComponent * (1. - specMapValue) + specularMatColor * SpecularComponent * specMapValue; - return tmp * ao; -} \ No newline at end of file + vec3 emitCol = diffuseMatColor.xyz * diffuseMatColor.xyz * diffuseMatColor.xyz * 15.; + return tmp * ao + (emitMapValue * emitCol); +}