Fixed halfTexel problem on dx9.

This commit is contained in:
Dario Manesku 2014-02-14 08:14:49 +01:00
parent 15a9282cc9
commit 1f58f4b874
17 changed files with 20 additions and 19 deletions

View file

@ -19,7 +19,7 @@ SAMPLER2D(u_texStencil, 7);
#define u_ambientPass u_params.x
#define u_lightningPass u_params.y
#define u_alpha u_params.z
#define u_texelHalf u_params.z
#define u_specular u_specular_shininess.xyz
#define u_shininess u_specular_shininess.w
@ -68,6 +68,7 @@ void main()
vec3 lightColor = calcLight(v_view, normal, viewDir) * u_lightningPass;
vec2 ndc = ((v_pos.xy / v_pos.w) + 1.0) / 2.0;
ndc += u_viewTexel.xy * u_texelHalf;
vec4 texcolor = texture2D(u_texStencil, ndc);
float s = (texcolor.x - texcolor.y) + 2.0 * (texcolor.z - texcolor.w);
s *= u_useStencilTex;
@ -84,5 +85,5 @@ void main()
vec3 final = mix(ambient, ambient + diffuse, float((abs(s) < 0.0001)));
gl_FragColor.xyz = mix(u_fogColor, final, fogFactor);
gl_FragColor.w = u_alpha;
gl_FragColor.w = 1.0;
}

View file

@ -20,7 +20,7 @@ SAMPLER2D(u_texStencil, 7);
#define u_ambientPass u_params.x
#define u_lightningPass u_params.y
#define u_alpha u_params.z
#define u_texelHalf u_params.z
#define u_specular u_specular_shininess.xyz
#define u_shininess u_specular_shininess.w
@ -69,6 +69,7 @@ void main()
vec3 lightColor = calcLight(v_view, normal, viewDir) * u_lightningPass;
vec2 ndc = ((v_pos.xy / v_pos.w) + 1.0) / 2.0;
ndc += u_viewTexel.xy * u_texelHalf;
vec4 texcolor = texture2D(u_texStencil, ndc);
float s = (texcolor.x - texcolor.y) + 2.0 * (texcolor.z - texcolor.w);
s *= u_useStencilTex;
@ -85,6 +86,6 @@ void main()
vec3 final = mix(ambient, ambient + diffuse, float((abs(s) < 0.0001)));
gl_FragColor.xyz = mix(u_fogColor, final, fogFactor);
gl_FragColor.w = u_alpha;
gl_FragColor.w = 1.0;
}

View file

@ -99,6 +99,7 @@ static const uint16_t s_planeIndices[s_numPlaneIndices] =
static const char* s_shaderPath = NULL;
static bool s_flipV = false;
static float s_texelHalf = 0.0f;
static uint32_t s_viewMask = 0;
@ -266,8 +267,7 @@ struct Uniforms
{
m_params.m_ambientPass = 1.0f;
m_params.m_lightningPass = 1.0f;
m_params.m_lightCount = 4.0f;
m_params.m_alpha = 1.0f;
m_params.m_texelHalf = 0.0f;
m_ambient[0] = 0.05f;
m_ambient[1] = 0.05f;
@ -374,16 +374,16 @@ struct Uniforms
{
float m_ambientPass;
float m_lightningPass;
float m_alpha;
float m_lightCount;
float m_texelHalf;
float m_unused00;
};
struct SvParams
{
float m_useStencilTex;
float m_dfail;
float m_unused0;
float m_unused1;
float m_unused10;
float m_unused11;
};
Params m_params;
@ -402,8 +402,8 @@ struct Uniforms
/**
* u_params.x - u_ambientPass
* u_params.y - u_lightningPass
* u_params.z - u_alpha
* u_params.w - u_lightCount
* u_params.z - u_texelHalf
* u_params.w - unused
* u_svparams.x - u_useStencilTex
* u_svparams.y - u_dfail
@ -1944,23 +1944,22 @@ int _main_(int /*_argc*/, char** /*_argv*/)
default:
case bgfx::RendererType::Direct3D9:
s_shaderPath = "shaders/dx9/";
s_flipV = true;
s_texelHalf = 0.5f;
break;
case bgfx::RendererType::Direct3D11:
s_shaderPath = "shaders/dx11/";
s_flipV = true;
break;
case bgfx::RendererType::OpenGL:
s_shaderPath = "shaders/glsl/";
s_flipV = false;
s_flipV = true;
break;
case bgfx::RendererType::OpenGLES2:
case bgfx::RendererType::OpenGLES3:
s_shaderPath = "shaders/gles/";
s_flipV = false;
s_flipV = true;
break;
}
@ -2331,7 +2330,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
//update settings
s_uniforms.m_params.m_ambientPass = 1.0f;
s_uniforms.m_params.m_lightningPass = 1.0f;
s_uniforms.m_params.m_lightCount = settings_numLights;
s_uniforms.m_params.m_texelHalf = s_texelHalf;
s_uniforms.m_svparams.m_useStencilTex = float(settings_useStencilTexture);
s_uniforms.submitPerFrameUniforms();

View file

@ -19,5 +19,5 @@ void main()
v_view = mul(u_modelView, vec4(a_position, 1.0)).xyz;
v_pos = gl_Position;
v_pos.y *= -u_flipV;
v_pos.y *= u_flipV;
}

View file

@ -21,5 +21,5 @@ void main()
v_texcoord0 = a_texcoord0;
v_pos = gl_Position;
v_pos.y *= -u_flipV;
v_pos.y *= u_flipV;
}