// [COMBO] {"material":"ui_editor_properties_fog","combo":"FOG","default":1} // [COMBO] {"material":"ui_editor_properties_refract","combo":"REFRACT","type":"options","default":0} #include "common_fragment.h" #include "common_fog.h" uniform sampler2D g_Texture0; // {"label":"ui_editor_properties_albedo","default":"util/white"} uniform float g_Overbright; // {"material":"ui_editor_properties_overbright","default":1.0,"range":[0,5]} #if REFRACT uniform sampler2D g_Texture1; // {"label":"ui_editor_properties_normal","format":"normalmap","formatcombo":true,"default":"util/flatnormal"} uniform sampler2D g_Texture2; // {"default":"_rt_FullFrameBuffer","hidden":true} #endif #if SPRITESHEET varying vec4 v_TexCoord; varying float v_TexCoordBlend; #else varying vec2 v_TexCoord; #endif varying vec4 v_Color; #if REFRACT varying vec3 v_ScreenCoord; varying vec4 v_ScreenTangents; #endif #if FOG_DIST || FOG_HEIGHT varying vec4 v_ViewDir; #endif void main() { #if SPRITESHEET #if SPRITESHEETBLEND // This is wrong because it can sample colors that are invisible on one frame but changing this can negatively impact additive particles vec4 color = v_Color * mix(ConvertTexture0Format(texSample2D(g_Texture0, v_TexCoord.xy)), ConvertTexture0Format(texSample2D(g_Texture0, v_TexCoord.zw)), v_TexCoordBlend); #else vec4 color = v_Color * ConvertTexture0Format(texSample2D(g_Texture0, v_TexCoord.xy)); #endif #else vec4 color = v_Color * ConvertTexture0Format(texSample2D(g_Texture0, v_TexCoord.xy)); #endif #if REFRACT vec4 normal = DecompressNormalWithMask(texSample2D(g_Texture1, v_TexCoord.xy)); //normal = vec4((v_TexCoord.xy - 0.5) * 2, 0, 1); vec2 screenRefractionOffset = v_ScreenTangents.xy * normal.x + v_ScreenTangents.zw * normal.y; #ifndef HLSL screenRefractionOffset.y = -screenRefractionOffset.y; #endif vec2 refractTexCoord = v_ScreenCoord.xy / v_ScreenCoord.z * vec2(0.5, 0.5) + 0.5 + screenRefractionOffset * normal.a * v_Color.a; color.rgb *= texSample2D(g_Texture2, refractTexCoord).rgb; #endif color.rgb *= g_Overbright; #if FOG_HEIGHT || FOG_DIST vec2 fogPixelState = CalculateFogPixelState(length(v_ViewDir.xyz), v_ViewDir.w); color.rgb = ApplyFog(color.rgb, fogPixelState); color.a = ApplyFogAlpha(color.a, fogPixelState); #endif gl_FragColor = color; #if ALPHATOCOVERAGE gl_FragColor.a = (gl_FragColor.a - 0.5) / max(fwidth(gl_FragColor.a), 0.0001) + 0.5; #if GLSL if (gl_FragColor.a < 0.5) discard; #endif #endif }