Improve parallax mapping

Add AVG_MAP, BLACK_LEVEL, and WHITE_LEVEL defines to tonemap shader
Fix a bug in fragment shader tangent space calculations
This commit is contained in:
James Canete 2012-05-01 01:05:12 +00:00
parent 2a6d34b4b4
commit 0905e8eae7
2 changed files with 128 additions and 122 deletions

View file

@ -1,3 +1,6 @@
- Improve parallax mapping
- Add AVG_MAP, BLACK_LEVEL, and WHITE_LEVEL defines to tonemap shader
- Fix a bug in fragment shader tangent space calculations
- Fix a bug in new curves code
- System menu makes a bit more sense now (removed irrelevant options, added new presets)
- Change imagelist cmd to give more relevant information

View file

@ -325,111 +325,112 @@ static const char *fallbackLightallShader_fp =
"th position\r\n\tfloat depth = 0.0;\r\n\r\n\t// best match found (starts wi"
"th last position 1.0)\r\n\tfloat bestDepth = 1.0;\r\n\r\n\t// search front "
"to back for first point inside object\r\n\tfor(int i = 0; i < linearSearchS"
"teps - 1; ++i)\r\n\t{\r\n\t\tdepth += size;\r\n\t\t\r\n\t\tfloat t = Sample"
"Height(normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(bestDepth > 0.996)\t"
"\t// if no depth found yet\r\n\t\t\tif(depth >= t)\r\n\t\t\t\tbestDepth = d"
"epth;\t// store best depth\r\n\t}\r\n\r\n\tdepth = bestDepth;\r\n\t\r\n\t//"
" recurse around first point (depth) for closest match\r\n\tfor(int i = 0; i"
" < binarySearchSteps; ++i)\r\n\t{\r\n\t\tsize *= 0.5;\r\n\r\n\t\tfloat t = "
"SampleHeight(normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(depth >= t)\r\n"
"\t\t{\r\n\t\t\tbestDepth = depth;\r\n\t\t\tdepth -= 2.0 * size;\r\n\t\t}\r"
"\n\r\n\t\tdepth += size;\r\n\t}\r\n\r\n\treturn bestDepth;\r\n}\r\n#endif\r"
"\n\r\nfloat CalcDiffuse(vec3 N, vec3 L, vec3 E, float NE, float NL, float f"
"zero, float shininess)\r\n{\r\n #if defined(USE_OREN_NAYAR)\r\n\tfloat rou"
"ghness = sqrt(2.0 / max(shininess, EPSILON));\r\n\r\n\tfloat gamma = dot(E "
"- N * NE, L - N * NL);\r\n\tfloat r_sq = roughness * roughness;\r\n\r\n\tfl"
"oat A = 1.0 - 0.5 * (r_sq / (r_sq + 0.57));\r\n\tfloat B = 0.45 * (r_sq / ("
"r_sq + 0.09));\r\n\r\n\tfloat alpha = max(acos(NE), acos(NL));\r\n\tfloat b"
"eta = min(acos(NE), acos(NL));\r\n\r\n\tfloat C = sin(alpha) * tan(beta);"
"\r\n\r\n\treturn A + B * clamp(gamma, 0.0, 1.0) * C;\r\n #else\r\n\treturn"
" 1.0 - fzero;\r\n #endif\r\n}\r\n\r\n#if defined(USE_SPECULARMAP)\r\nfloat"
" CalcSpecular(float NH, float NL, float NE, float EH, float fzero, float sh"
"ininess)\r\n{\r\n #if defined(USE_BLINN) || defined(USE_TRIACE) || defined"
"(USE_TORRANCE_SPARROW)\r\n\tfloat blinn = pow(NH, shininess);\r\n #endif\r"
"\n\r\n #if defined(USE_BLINN)\r\n\treturn blinn;\r\n #endif\r\n\r\n #if "
"defined(USE_COOK_TORRANCE) || defined (USE_TRIACE) || defined (USE_TORRANCE"
"_SPARROW)\r\n\tfloat fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r"
"\n #endif\r\n\r\n #if defined(USE_COOK_TORRANCE) || defined(USE_TORRANCE_"
"SPARROW)\r\n\tfloat geo = 2.0 * NH * min(NE, NL);\r\n\tgeo /= max(EH, geo);"
"\r\n #endif \r\n\r\n #if defined(USE_COOK_TORRANCE)\r\n\tfloat m = sqrt("
"2.0 / max(shininess, EPSILON));\r\n\r\n\tfloat m_sq = m * m;\r\n\tfloat NH_"
"sq = NH * NH;\r\n\tfloat beckmann = exp((NH_sq - 1.0) / max(m_sq * NH_sq, E"
"PSILON)) / max(4.0 * m_sq * NH_sq * NH_sq, EPSILON);\r\n\r\n\treturn fresne"
"l * geo * beckmann / max(NE, EPSILON);\r\n #endif\r\n\r\n #if defined(USE"
"_TRIACE)\r\n\tfloat scale = 0.1248582 * shininess + 0.2691817;\r\n\r\n\tret"
"urn fresnel * scale * blinn / max(max(NL, NE), EPSILON);\r\n #endif\r\n "
"\r\n #if defined(USE_TORRANCE_SPARROW)\r\n\tfloat scale = 0.125 * shinines"
"s + 1.0;\r\n\r\n\treturn fresnel * geo * scale * blinn / max(NE, EPSILON);"
"\r\n #endif\r\n}\r\n#endif\r\n\r\nvoid main()\r\n{\r\n#if defined(USE_DELU"
"XEMAP)\r\n\tvec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_LightTex).xy"
"z - vec3(1.0);\r\n\t//worldLight += var_WorldLight * 0.0001;\r\n#elif defin"
"ed(USE_LIGHT)\r\n\tvec3 worldLight = var_WorldLight;\r\n#endif\r\n\r\n#if d"
"efined(USE_LIGHTMAP)\r\n\tvec4 lightSample = texture2D(u_LightMap, var_Ligh"
"tTex).rgba;\r\n #if defined(RGBE_LIGHTMAP)\r\n\tlightSample.rgb *= exp2(li"
"ghtSample.a * 255.0 - 128.0);\r\n #endif\r\n\tvec3 directedLight = lightSa"
"mple.rgb;\r\n#elif defined(USE_LIGHT_VECTOR)\r\n #if defined(USE_FAST_LIGH"
"T)\r\n\tvec3 directedLight = var_VectLight;\r\n #else\r\n #if defined(U"
"SE_INVSQRLIGHT)\r\n\tfloat intensity = 1.0 / dot(worldLight, worldLight);\r"
"\n #else\r\n\tfloat intensity = clamp((1.0 - dot(worldLight, worldLight)"
" / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);\r\n #endif\r\n "
" #if defined(USE_SHADOWMAP)\r\n \tvec3 dist3 = textureCube(u_ShadowMap, wo"
"rldLight).rgb;\r\n\tfloat dist = dot(dist3, vec3(1.0 / (256.0 * 256.0), 1.0"
" / 256.0, 1.0)) * u_LightRadius;\r\n\r\n\tintensity *= clamp(sign(dist - le"
"ngth(worldLight)), 0.0, 1.0);\r\n #endif\r\n\tvec3 directedLight = u_Dir"
"ectedLight * intensity;\r\n\tvec3 ambientLight = u_AmbientLight;\r\n #end"
"if\r\n#elif defined(USE_LIGHT_VERTEX)\r\n\tvec3 directedLight = var_Color.r"
"gb;\r\n#endif\r\n\t\r\n#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && "
"!defined(USE_FAST_LIGHT)\r\n\tvec3 SampleToView = normalize(var_SampleToVie"
"w);\r\n#endif\r\n\tvec2 tex = var_DiffuseTex;\r\n\r\n\tfloat ambientDiff = "
"1.0;\r\n\r\n#if defined(USE_NORMALMAP)\r\n #if defined(USE_VERT_TANGENT_SP"
"ACE)\r\n vec3 tangent = normalize(var_Tangent);\r\n\tvec3 bitangent = "
"normalize(var_Bitangent);\r\n #else\r\n\tvec3 q0 = dFdx(var_Position.xyz)"
";\r\n\tvec3 q1 = dFdy(var_Position.xyz);\r\n\tvec2 st0 = dFdx(tex);\r\n\tv"
"ec2 st1 = dFdy(tex);\r\n\r\n\tvec3 tangent = -normalize( q0 * st1.t - q1 "
"* st0.t);\r\n\tvec3 bitangent = -normalize(-q0 * st1.s + q1 * st0.s);\r\n "
"teps - 1; ++i)\r\n\t{\r\n\t\tdepth += size;\r\n\t\t\r\n\t\tfloat t = 1.0 - "
"SampleHeight(normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(bestDepth > 0.9"
"96)\t\t// if no depth found yet\r\n\t\t\tif(depth >= t)\r\n\t\t\t\tbestDept"
"h = depth;\t// store best depth\r\n\t}\r\n\r\n\tdepth = bestDepth;\r\n\t\r"
"\n\t// recurse around first point (depth) for closest match\r\n\tfor(int i "
"= 0; i < binarySearchSteps; ++i)\r\n\t{\r\n\t\tsize *= 0.5;\r\n\r\n\t\tfloa"
"t t = 1.0 - SampleHeight(normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(dep"
"th >= t)\r\n\t\t{\r\n\t\t\tbestDepth = depth;\r\n\t\t\tdepth -= 2.0 * size;"
"\r\n\t\t}\r\n\r\n\t\tdepth += size;\r\n\t}\r\n\r\n\treturn bestDepth;\r\n}"
"\r\n#endif\r\n\r\nfloat CalcDiffuse(vec3 N, vec3 L, vec3 E, float NE, float"
" NL, float fzero, float shininess)\r\n{\r\n #if defined(USE_OREN_NAYAR)\r"
"\n\tfloat roughness = sqrt(2.0 / max(shininess, EPSILON));\r\n\r\n\tfloat g"
"amma = dot(E - N * NE, L - N * NL);\r\n\tfloat r_sq = roughness * roughness"
";\r\n\r\n\tfloat A = 1.0 - 0.5 * (r_sq / (r_sq + 0.57));\r\n\tfloat B = 0.4"
"5 * (r_sq / (r_sq + 0.09));\r\n\r\n\tfloat alpha = max(acos(NE), acos(NL));"
"\r\n\tfloat beta = min(acos(NE), acos(NL));\r\n\r\n\tfloat C = sin(alpha) "
"* tan(beta);\r\n\r\n\treturn A + B * clamp(gamma, 0.0, 1.0) * C;\r\n #else"
"\r\n\treturn 1.0 - fzero;\r\n #endif\r\n}\r\n\r\n#if defined(USE_SPECULARM"
"AP)\r\nfloat CalcSpecular(float NH, float NL, float NE, float EH, float fze"
"ro, float shininess)\r\n{\r\n #if defined(USE_BLINN) || defined(USE_TRIACE"
") || defined(USE_TORRANCE_SPARROW)\r\n\tfloat blinn = pow(NH, shininess);\r"
"\n #endif\r\n\r\n #if defined(USE_BLINN)\r\n\treturn blinn;\r\n #endif\r"
"\n\r\n #if defined(USE_COOK_TORRANCE) || defined (USE_TRIACE) || defined ("
"USE_TORRANCE_SPARROW)\r\n\tfloat fresnel = fzero + (1.0 - fzero) * pow(1.0 "
"- EH, 5);\r\n #endif\r\n\r\n #if defined(USE_COOK_TORRANCE) || defined(US"
"E_TORRANCE_SPARROW)\r\n\tfloat geo = 2.0 * NH * min(NE, NL);\r\n\tgeo /= ma"
"x(EH, geo);\r\n #endif \r\n\r\n #if defined(USE_COOK_TORRANCE)\r\n\tfloa"
"t m = sqrt(2.0 / max(shininess, EPSILON));\r\n\r\n\tfloat m_sq = m * m;\r\n"
"\tfloat NH_sq = NH * NH;\r\n\tfloat beckmann = exp((NH_sq - 1.0) / max(m_sq"
" * NH_sq, EPSILON)) / max(4.0 * m_sq * NH_sq * NH_sq, EPSILON);\r\n\r\n\tre"
"turn fresnel * geo * beckmann / max(NE, EPSILON);\r\n #endif\r\n\r\n #if "
"defined(USE_TRIACE)\r\n\tfloat scale = 0.1248582 * shininess + 0.2691817;\r"
"\n\r\n\treturn fresnel * scale * blinn / max(max(NL, NE), EPSILON);\r\n #e"
"ndif\r\n \r\n #if defined(USE_TORRANCE_SPARROW)\r\n\tfloat scale = 0.125 "
"* shininess + 1.0;\r\n\r\n\treturn fresnel * geo * scale * blinn / max(NE, "
"EPSILON);\r\n #endif\r\n}\r\n#endif\r\n\r\nvoid main()\r\n{\r\n#if defined"
"(USE_DELUXEMAP)\r\n\tvec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_Lig"
"htTex).xyz - vec3(1.0);\r\n\t//worldLight += var_WorldLight * 0.0001;\r\n#e"
"lif defined(USE_LIGHT)\r\n\tvec3 worldLight = var_WorldLight;\r\n#endif\r\n"
"\r\n#if defined(USE_LIGHTMAP)\r\n\tvec4 lightSample = texture2D(u_LightMap,"
" var_LightTex).rgba;\r\n #if defined(RGBE_LIGHTMAP)\r\n\tlightSample.rgb *"
"= exp2(lightSample.a * 255.0 - 128.0);\r\n #endif\r\n\tvec3 directedLight "
"= lightSample.rgb;\r\n#elif defined(USE_LIGHT_VECTOR)\r\n #if defined(USE_"
"FAST_LIGHT)\r\n\tvec3 directedLight = var_VectLight;\r\n #else\r\n #if "
"defined(USE_INVSQRLIGHT)\r\n\tfloat intensity = 1.0 / dot(worldLight, world"
"Light);\r\n #else\r\n\tfloat intensity = clamp((1.0 - dot(worldLight, wo"
"rldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);\r\n #end"
"if\r\n #if defined(USE_SHADOWMAP)\r\n \tvec3 dist3 = textureCube(u_Shad"
"owMap, worldLight).rgb;\r\n\tfloat dist = dot(dist3, vec3(1.0 / (256.0 * 25"
"6.0), 1.0 / 256.0, 1.0)) * u_LightRadius;\r\n\r\n\tintensity *= clamp(sign("
"dist - length(worldLight)), 0.0, 1.0);\r\n #endif\r\n\tvec3 directedLigh"
"t = u_DirectedLight * intensity;\r\n\tvec3 ambientLight = u_AmbientLight;"
"\r\n #endif\r\n#elif defined(USE_LIGHT_VERTEX)\r\n\tvec3 directedLight = v"
"ar_Color.rgb;\r\n#endif\r\n\t\r\n#if defined(USE_NORMALMAP) || defined(USE_"
"LIGHT) && !defined(USE_FAST_LIGHT)\r\n\tvec3 SampleToView = normalize(var_S"
"ampleToView);\r\n#endif\r\n\tvec2 tex = var_DiffuseTex;\r\n\r\n\tfloat ambi"
"entDiff = 1.0;\r\n\r\n#if defined(USE_NORMALMAP)\r\n #if defined(USE_VERT_"
"TANGENT_SPACE)\r\n vec3 tangent = normalize(var_Tangent);\r\n\tvec3 bi"
"tangent = normalize(var_Bitangent);\r\n #else\r\n\tvec3 q0 = dFdx(var_Pos"
"ition.xyz);\r\n\tvec3 q1 = dFdy(var_Position.xyz);\r\n\tvec2 st0 = dFdx(te"
"x);\r\n\tvec2 st1 = dFdy(tex);\r\n\tfloat dir = sign(st1.t * st0.s - st0.t "
"* st1.s);\r\n\r\n\tvec3 tangent = normalize( q0 * st1.t - q1 * st0.t) * d"
"ir;\r\n\tvec3 bitangent = -normalize( q0 * st1.s - q1 * st0.s) * dir;\r\n "
"#endif\r\n\r\n\tmat3 tangentToWorld = mat3(tangent, bitangent, normalize(va"
"r_Normal.xyz));\r\n\r\n #if defined(USE_PARALLAXMAP)\r\n\tvec3 offsetDir ="
" normalize(SampleToView * tangentToWorld);\r\n #if 0\r\n float height"
" = SampleHeight(u_NormalMap, tex);\r\n\tfloat pdist = 0.05 * height - (0.05"
" / 2.0);\r\n #else\r\n\toffsetDir.xy *= 0.02 / offsetDir.z;\r\n\tfloat p"
"dist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_NormalMap);\r\n #end"
"if\t\r\n\ttex += offsetDir.xy * pdist;\r\n #endif\r\n #if defined(SWIZZLE"
"_NORMALMAP)\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).agb - 1.0;"
"\r\n #else\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).rgb - 1.0;"
"\r\n #endif\r\n\tnormal.z = sqrt(clamp(1.0 - dot(normal.xy, normal.xy), 0."
"0, 1.0));\r\n\tvec3 worldNormal = tangentToWorld * normal;\r\n #if defined"
"(r_normalAmbient)\r\n\tambientDiff = 0.781341 * normal.z + 0.218659;\r\n #"
"endif\r\n#else\r\n\tvec3 worldNormal = var_Normal;\r\n#endif\r\n\r\n\tvec4 "
"diffuse = texture2D(u_DiffuseMap, tex);\r\n\r\n#if defined(USE_LIGHT) && de"
"fined(USE_FAST_LIGHT)\r\n\tdiffuse.rgb *= directedLight;\r\n#elif defined(U"
"SE_LIGHT)\r\n\tworldNormal = normalize(worldNormal);\r\n\tworldLight = norm"
"alize(worldLight);\r\n\r\n #if defined(USE_LIGHTMAP) || defined(USE_LIGHT_"
"VERTEX)\r\n\tdirectedLight /= max(dot(normalize(var_Normal), worldLight), 0"
".004);\r\n\r\n #if defined(r_normalAmbient)\r\n\tvec3 ambientLight = dir"
"ectedLight * r_normalAmbient;\r\n\tdirectedLight -= ambientLight;\r\n #e"
"lse\r\n\tvec3 ambientLight = vec3(0);\r\n #endif\r\n #endif\r\n\r\n\tfl"
"oat NL = clamp(dot(worldNormal, worldLight), 0.0, 1.0);\r\n\tfloat NE = "
"clamp(dot(worldNormal, SampleToView), 0.0, 1.0);\r\n\t\r\n\tfloat fzero = "
"u_MaterialInfo.x;\r\n\tfloat shininess = u_MaterialInfo.y;\r\n #if defined"
"(USE_SPECULARMAP)\r\n\tvec4 specular = texture2D(u_SpecularMap, tex);\r\n\t"
"//specular.rgb = clamp(specular.rgb - diffuse.rgb, 0.0, 1.0);\r\n\tshinines"
"s *= specular.a;\r\n #endif\r\n\tfloat directedDiff = NL * CalcDiffuse(wor"
"ldNormal, worldLight, SampleToView, NE, NL, fzero, shininess);\r\n\tdiffuse"
".rgb *= directedLight * directedDiff + ambientDiff * ambientLight;\r\n \r"
"\n #if defined(USE_SPECULARMAP)\r\n\tvec3 halfAngle = normalize(worldLight"
" + SampleToView);\r\n\r\n\tfloat EH = clamp(dot(SampleToView, halfAngle), 0"
".0, 1.0);\r\n\tfloat NH = clamp(dot(worldNormal, halfAngle), 0.0, 1.0);\r"
"\n\r\n\tfloat directedSpec = NL * CalcSpecular(NH, NL, NE, EH, fzero, shini"
"ness);\r\n \r\n #if defined(r_normalAmbient)\r\n\tvec3 ambientHalf = no"
"rmalize(var_Normal + SampleToView);\r\n\tfloat ambientSpec = max(dot(ambien"
"tHalf, worldNormal) + 0.5, 0.0);\r\n\tambientSpec *= ambientSpec * 0.44;\r"
"\n\tambientSpec = pow(ambientSpec, shininess) * fzero;\r\n\tspecular.rgb *="
" directedSpec * directedLight + ambientSpec * ambientLight;\r\n #else\r"
"\n\tspecular.rgb *= directedSpec * directedLight;\r\n #endif\r\n #endif"
"\r\n#endif\r\n\r\n\tgl_FragColor = diffuse;\r\n\r\n#if defined(USE_SPECULAR"
"MAP) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)\r\n\tgl_FragColor.rg"
"b += specular.rgb;\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VERTEX)\r\n\tgl_"
"FragColor *= var_Color;\r\n#endif\r\n}\r\n";
" / 2.0);\r\n #else\r\n\toffsetDir.xy *= -0.05 / offsetDir.z;\r\n\tfloat "
"pdist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_NormalMap);\r\n #en"
"dif\t\r\n\ttex += offsetDir.xy * pdist;\r\n #endif\r\n #if defined(SWIZZL"
"E_NORMALMAP)\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).agb - 1.0"
";\r\n #else\r\n\tvec3 normal = 2.0 * texture2D(u_NormalMap, tex).rgb - 1.0"
";\r\n #endif\r\n\tnormal.z = sqrt(clamp(1.0 - dot(normal.xy, normal.xy), 0"
".0, 1.0));\r\n\tvec3 worldNormal = tangentToWorld * normal;\r\n #if define"
"d(r_normalAmbient)\r\n\tambientDiff = 0.781341 * normal.z + 0.218659;\r\n "
"#endif\r\n#else\r\n\tvec3 worldNormal = var_Normal;\r\n#endif\r\n\r\n\tvec4"
" diffuse = texture2D(u_DiffuseMap, tex);\r\n\r\n#if defined(USE_LIGHT) && d"
"efined(USE_FAST_LIGHT)\r\n\tdiffuse.rgb *= directedLight;\r\n#elif defined("
"USE_LIGHT)\r\n\tworldNormal = normalize(worldNormal);\r\n\tworldLight = nor"
"malize(worldLight);\r\n\r\n #if defined(USE_LIGHTMAP) || defined(USE_LIGHT"
"_VERTEX)\r\n\tdirectedLight /= max(dot(normalize(var_Normal), worldLight), "
"0.004);\r\n\r\n #if defined(r_normalAmbient)\r\n\tvec3 ambientLight = di"
"rectedLight * r_normalAmbient;\r\n\tdirectedLight -= ambientLight;\r\n #"
"else\r\n\tvec3 ambientLight = vec3(0);\r\n #endif\r\n #endif\r\n\r\n\tf"
"loat NL = clamp(dot(worldNormal, worldLight), 0.0, 1.0);\r\n\tfloat NE ="
" clamp(dot(worldNormal, SampleToView), 0.0, 1.0);\r\n\t\r\n\tfloat fzero ="
" u_MaterialInfo.x;\r\n\tfloat shininess = u_MaterialInfo.y;\r\n #if define"
"d(USE_SPECULARMAP)\r\n\tvec4 specular = texture2D(u_SpecularMap, tex);\r\n"
"\t//specular.rgb = clamp(specular.rgb - diffuse.rgb, 0.0, 1.0);\r\n\tshinin"
"ess *= specular.a;\r\n #endif\r\n\tfloat directedDiff = NL * CalcDiffuse(w"
"orldNormal, worldLight, SampleToView, NE, NL, fzero, shininess);\r\n\tdiffu"
"se.rgb *= directedLight * directedDiff + ambientDiff * ambientLight;\r\n "
"\r\n #if defined(USE_SPECULARMAP)\r\n\tvec3 halfAngle = normalize(worldLig"
"ht + SampleToView);\r\n\r\n\tfloat EH = clamp(dot(SampleToView, halfAngle),"
" 0.0, 1.0);\r\n\tfloat NH = clamp(dot(worldNormal, halfAngle), 0.0, 1.0);"
"\r\n\r\n\tfloat directedSpec = NL * CalcSpecular(NH, NL, NE, EH, fzero, shi"
"niness);\r\n \r\n #if defined(r_normalAmbient)\r\n\tvec3 ambientHalf = "
"normalize(var_Normal + SampleToView);\r\n\tfloat ambientSpec = max(dot(ambi"
"entHalf, worldNormal) + 0.5, 0.0);\r\n\tambientSpec *= ambientSpec * 0.44;"
"\r\n\tambientSpec = pow(ambientSpec, shininess) * fzero;\r\n\tspecular.rgb "
"*= directedSpec * directedLight + ambientSpec * ambientLight;\r\n #else"
"\r\n\tspecular.rgb *= directedSpec * directedLight;\r\n #endif\r\n #end"
"if\r\n#endif\r\n\r\n\tgl_FragColor = diffuse;\r\n\r\n#if defined(USE_SPECUL"
"ARMAP) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)\r\n\tgl_FragColor."
"rgb += specular.rgb;\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VERTEX)\r\n\tg"
"l_FragColor *= var_Color;\r\n#endif\r\n}\r\n";
static const char *fallbackShadowfillShader_vp =
"attribute vec4 attr_Position;\r\nattribute vec3 attr_Normal;\r\nattribute"
@ -637,27 +638,29 @@ static const char *fallbackToneMapShader_vp =
"x * attr_Position;\r\n\tvar_TexCoords = attr_TexCoord0.st;\r\n}\r\n";
static const char *fallbackToneMapShader_fp =
"uniform sampler2D u_TextureMap;\r\nuniform sampler2D u_LevelsMap;\r\n\r\nun"
"iform vec4 u_Color;\r\n\r\nuniform vec2 u_AutoExposureMinMax;\r\n"
"\r\nvarying vec2 var_TexCoords;\r\n\r\nconst vec3 LUMINANCE_VECTOR = "
" vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 0.587, 0.114);\r\n\r\nvec3 Fi"
"lmicTonemap(vec3 x)\r\n{\r\n\tconst float SS = 0.22; // Shoulder Strength"
"\r\n\tconst float LS = 0.30; // Linear Strength\r\n\tconst float LA = 0.1"
"0; // Linear Angle\r\n\tconst float TS = 0.20; // Toe Strength\r\n\tconst "
"float TAN = 0.01; // Toe Angle Numerator\r\n\tconst float TAD = 0.30; // To"
"e Angle Denominator\r\n\t\r\n\tvec3 SSxx = SS * x * x;\r\n\tvec3 LSx = LS *"
" x;\r\n\tvec3 LALSx = LSx * LA;\r\n\t\r\n\treturn ((SSxx + LALSx + TS * TAN"
") / (SSxx + LSx + TS * TAD)) - TAN / TAD;\r\n\r\n\t//return ((x*(SS*x+LA*LS"
")+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD;\r\n\r\n}\r\n\r\nvoid main()\r\n{"
"\r\n\tvec4 color = texture2D(u_TextureMap, var_TexCoords) * u_Color;\r\n\tv"
"ec3 minAvgMax = texture2D(u_LevelsMap, var_TexCoords).rgb;\r\n\tvec3 logMin"
"AvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, -u_AutoExposureMinMax.y, -u_Auto"
"ExposureMinMax.x);\r\n\t\t\r\n\tfloat avgLum = exp2(logMinAvgMaxLum.y);\r\n"
"\t//float maxLum = exp2(logMinAvgMaxLum.z);\r\n\t\r\n\tcolor.rgb /= avgLum;"
"\r\n\r\n\tvec3 fWhite = 1.0 / FilmicTonemap(vec3(2.0));\r\n\tcolor.rgb = Fi"
"lmicTonemap(color.rgb) * fWhite;\r\n\t\r\n#if defined(r_obbcorrect)\r\n\tco"
"lor.rgb /= r_obbcorrect;\r\n#endif\r\n\t\r\n\tgl_FragColor = color;\r\n}\r"
"\n";
"#define AVG_MAP 1.0\r\n#define WHITE_LEVEL 2.0\r\n#define BLACK_LEVEL 0.1\r"
"\n\r\nuniform sampler2D u_TextureMap;\r\nuniform sampler2D u_LevelsMap;\r\n"
"\r\nuniform vec4 u_Color;\r\n\r\nuniform vec2 u_AutoExposureMinMa"
"x;\r\n\r\nvarying vec2 var_TexCoords;\r\n\r\nconst vec3 LUMINANCE_VEC"
"TOR = vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 0.587, 0.114);\r\n\r\nv"
"ec3 FilmicTonemap(vec3 x)\r\n{\r\n\tconst float SS = 0.22; // Shoulder Str"
"ength\r\n\tconst float LS = 0.30; // Linear Strength\r\n\tconst float LA "
"= 0.10; // Linear Angle\r\n\tconst float TS = 0.20; // Toe Strength\r\n\tc"
"onst float TAN = 0.01; // Toe Angle Numerator\r\n\tconst float TAD = 0.30; "
"// Toe Angle Denominator\r\n\t\r\n\tvec3 SSxx = SS * x * x;\r\n\tvec3 LSx ="
" LS * x;\r\n\tvec3 LALSx = LSx * LA;\r\n\t\r\n\treturn ((SSxx + LALSx + TS "
"* TAN) / (SSxx + LSx + TS * TAD)) - TAN / TAD;\r\n\r\n\t//return ((x*(SS*x+"
"LA*LS)+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD;\r\n\r\n}\r\n\r\nvoid main()"
"\r\n{\r\n\tvec4 color = texture2D(u_TextureMap, var_TexCoords) * u_Color;\r"
"\n\tvec3 minAvgMax = texture2D(u_LevelsMap, var_TexCoords).rgb;\r\n\tvec3 l"
"ogMinAvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, -u_AutoExposureMinMax.y, -u"
"_AutoExposureMinMax.x);\r\n\t\t\r\n\tfloat avgLum = exp2(logMinAvgMaxLum.y)"
";\r\n\t//float maxLum = exp2(logMinAvgMaxLum.z);\r\n\t\r\n\tcolor.rgb *= AV"
"G_MAP / avgLum;\r\n\tcolor.rgb = max(vec3(0.0), color.rgb - vec3(BLACK_LEVE"
"L));\r\n\r\n\tvec3 fWhite = 1.0 / FilmicTonemap(vec3(WHITE_LEVEL - BLACK_LE"
"VEL));\r\n\tcolor.rgb = FilmicTonemap(color.rgb) * fWhite;\r\n\t\r\n#if def"
"ined(r_obbcorrect)\r\n\tcolor.rgb /= r_obbcorrect;\r\n#endif\r\n\t\r\n\tgl_"
"FragColor = color;\r\n}\r\n";
static const char *fallbackCalcLevels4xShader_vp =
"attribute vec4 attr_Position;\r\nattribute vec4 attr_TexCoord0;\r\n\r\nunif"