fixes for premultiplied alpha

This commit is contained in:
Sean Barrett 2015-03-17 02:21:17 -07:00
parent ba49d37e6a
commit 0669a6659a
2 changed files with 4 additions and 13 deletions

View File

@ -861,6 +861,7 @@ static char *stbvox_fragment_program =
" uint tex2_id = facedata.y;\n"
" uint texprojid = facedata.w & 31u;\n"
" uint color_id = facedata.z;\n"
// @TODO: could use a separate lookup table keyed on tex2 to determine this; maybe another field of texscale?
" bool texblend_mode = ((facedata.w & 128u) != 0u);\n"
#ifndef STBVOX_CONFIG_PREFER_TEXBUFFER
@ -899,17 +900,15 @@ static char *stbvox_fragment_program =
" tex2.a *= texlerp;\n"
#endif
// @TODO: could use a separate lookup table keyed on tex2 to determine this
" if (texblend_mode)\n"
" albedo = tex2.xyz * rlerp(tex2.a, 2.0*tex1.xyz, vec3(1.0,1.0,1.0));\n"
" else {\n"
#ifdef STBVOX_CONFIG_PREMULTIPLIED_ALPHA
" albedo = (1.0-tex2.a)*tex1.xyz + tex2.xyz;\n"
" fragment_alpha = tex1.a;\n"
#else
" albedo = rlerp(tex2.a, tex1.xyz, tex2.xyz);\n"
" fragment_alpha = tex1.a*(1-tex2.a)+tex2.a;\n"
#endif
" fragment_alpha = tex1.a*(1-tex2.a)+tex2.a;\n"
" }\n"
" fragment_alpha = tex1.a;\n"
@ -1050,16 +1049,8 @@ static char *stbvox_fragment_program_alpha_only =
" tex2.a *= texlerp;\n"
// @TODO: could use a separate lookup table keyed on tex2 to determine this
" if (texblend_mode)\n"
" ;\n"
" else {\n"
#ifdef STBVOX_CONFIG_PREMULTIPLIED_ALPHA
" fragment_alpha = tex1.a;\n"
#else
" if (!texblend_mode)\n"
" fragment_alpha = tex1.a*(1-tex2.a)+tex2.a;\n"
#endif
" }\n"
#else // UNTEXTURED
" vec4 color;"

View File

@ -21,7 +21,7 @@
#define STBVOX_CONFIG_PREFER_TEXBUFFER
//#define STBVOX_CONFIG_LIGHTING_SIMPLE
#define STBVOX_CONFIG_FOG_SMOOTHSTEP
#define STBVOX_CONFIG_PREMULTIPLIED_ALPHA // use this even though it doesn't really work for alpha test without next #define
//#define STBVOX_CONFIG_PREMULTIPLIED_ALPHA // use this even though it doesn't really work for alpha test without next #define
//#define STBVOX_CONFIG_UNPREMULTIPLY // slower, makes windows & fancy leaves look better
#define STBVOX_ROTATION_IN_LIGHTING