From e1c7efd68ca44836a0db15254b4c21ce6db646df Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 5 Jan 2018 16:45:33 +0800 Subject: [PATCH] Add sam's formula for pbr --- data/shaders/combine_diffuse_color.frag | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/data/shaders/combine_diffuse_color.frag b/data/shaders/combine_diffuse_color.frag index c1b7b8eb7..f2dee049c 100644 --- a/data/shaders/combine_diffuse_color.frag +++ b/data/shaders/combine_diffuse_color.frag @@ -14,15 +14,18 @@ void main() vec2 tc = gl_FragCoord.xy / u_screen; vec4 diffuseMatColor = texture(diffuse_color, tc); - // Gloss map here is stored in red and green for spec and emit map + // Gloss map here is stored in red and green for metallic and emit map // Real gloss channel is stored in normal and depth framebuffer .z - float specMapValue = texture(gloss_map, tc).x; + float metallicMapValue = texture(gloss_map, tc).x; float emitMapValue = texture(gloss_map, tc).y; float ao = texture(ssao_tex, tc).x; vec3 DiffuseComponent = texture(diffuse_map, tc).xyz; vec3 SpecularComponent = texture(specular_map, tc).xyz; - vec3 tmp = diffuseMatColor.xyz * DiffuseComponent * (1. - specMapValue) + SpecularComponent * specMapValue; + + vec3 metallicMatColor = mix(vec3(0.04), diffuseMatColor.xyz * 4, metallicMapValue); + vec3 tmp = DiffuseComponent * mix(diffuseMatColor.xyz, vec3(0.0), metallicMapValue) + (metallicMatColor * SpecularComponent); + vec3 emitCol = diffuseMatColor.xyz * diffuseMatColor.xyz * diffuseMatColor.xyz * 15.; vec4 color_1 = vec4(tmp * ao + (emitMapValue * emitCol), diffuseMatColor.a);