This commit is contained in:
Branimir Karadžić 2015-06-07 21:28:36 -07:00
parent ddf0959d35
commit 9ebcfab447
23 changed files with 40 additions and 32 deletions

View File

@ -15,7 +15,7 @@ uniform vec4 u_specular_shininess;
uniform vec4 u_fog;
uniform vec4 u_lightPosRadius;
uniform vec4 u_lightRgbInnerR;
SAMPLER2D(u_texStencil, 7);
SAMPLER2D(s_texStencil, 1);
#define u_ambientPass u_params.x
#define u_lightningPass u_params.y
@ -68,7 +68,7 @@ void main()
vec3 lightColor = calcLight(v_view, normal, viewDir) * u_lightningPass;
vec2 ndc = gl_FragCoord.xy * u_viewTexel.xy + u_viewTexel.xy * u_texelHalf;
vec4 texcolor = texture2D(u_texStencil, ndc);
vec4 texcolor = texture2D(s_texStencil, ndc);
float s = (texcolor.x - texcolor.y) + 2.0 * (texcolor.z - texcolor.w);
s *= u_useStencilTex;

View File

@ -7,11 +7,11 @@ $input v_texcoord0
#include "../common/common.sh"
uniform vec4 u_color;
SAMPLER2D(u_texColor, 0);
SAMPLER2D(s_texColor, 0);
void main()
{
vec4 tcolor = toLinear(texture2D(u_texColor, v_texcoord0));
vec4 tcolor = toLinear(texture2D(s_texColor, v_texcoord0));
if (tcolor.x < 0.1) //OK for now.
{

View File

@ -11,14 +11,16 @@ vec4 stencilColor(float _k)
, float(abs(_k + 1.0) < 0.0001)/255.0
, float(abs(_k - 2.0) < 0.0001)/255.0
, float(abs(_k + 2.0) < 0.0001)/255.0
);
);
}
void main()
{
float k = 1.0;
if (!gl_FrontFacing)
{
k = -k;
}
gl_FragColor = stencilColor(k);
}

View File

@ -11,14 +11,16 @@ vec4 stencilColor(float _k)
, float(abs(_k + 1.0) < 0.0001)/255.0
, float(abs(_k - 2.0) < 0.0001)/255.0
, float(abs(_k + 2.0) < 0.0001)/255.0
);
);
}
void main()
{
float k = 2.0;
if (!gl_FrontFacing)
{
k = -k;
}
gl_FragColor = stencilColor(k);
}

View File

@ -1,24 +1,26 @@
/*
* Copyright 2013-2014 Dario Manesku. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
* Copyright 2013-2014 Dario Manesku. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "../common/common.sh"
vec4 stencilColor(float _k)
{
return vec4(float(abs(_k - 1.0) < 0.0001)/255.0
, float(abs(_k + 1.0) < 0.0001)/255.0
, float(abs(_k - 2.0) < 0.0001)/255.0
, float(abs(_k + 2.0) < 0.0001)/255.0
);
return vec4(float(abs(_k - 1.0) < 0.0001)/255.0
, float(abs(_k + 1.0) < 0.0001)/255.0
, float(abs(_k - 2.0) < 0.0001)/255.0
, float(abs(_k + 2.0) < 0.0001)/255.0
);
}
void main()
{
float k = -1.0;
if (gl_FrontFacing)
k = -k;
float k = -1.0;
if (gl_FrontFacing)
{
k = -k;
}
gl_FragColor = stencilColor(k);
gl_FragColor = stencilColor(k);
}

View File

@ -11,7 +11,9 @@ void main()
{
float k = v_k;
if (!gl_FrontFacing)
{
k = -k;
}
gl_FragColor.xyzw =
vec4( float(abs(k - 1.0) < 0.0001)/255.0

View File

@ -6,9 +6,9 @@ $input v_texcoord0
*/
#include "../common/common.sh"
SAMPLER2D(u_texColor, 0);
SAMPLER2D(s_texColor, 0);
void main()
{
gl_FragColor = texture2D(u_texColor, v_texcoord0);
gl_FragColor = texture2D(s_texColor, v_texcoord0);
}

View File

@ -14,8 +14,8 @@ uniform vec4 u_specular_shininess;
uniform vec4 u_fog;
uniform vec4 u_lightPosRadius;
uniform vec4 u_lightRgbInnerR;
SAMPLER2D(u_texColor, 0);
SAMPLER2D(u_texStencil, 7);
SAMPLER2D(s_texColor, 0);
SAMPLER2D(s_texStencil, 1);
#define u_ambientPass u_params.x
#define u_lightningPass u_params.y
@ -68,7 +68,7 @@ void main()
vec3 lightColor = calcLight(v_view, normal, viewDir) * u_lightningPass;
vec2 ndc = gl_FragCoord.xy * u_viewTexel.xy + u_viewTexel.xy * u_texelHalf;
vec4 texcolor = texture2D(u_texStencil, ndc);
vec4 texcolor = texture2D(s_texStencil, ndc);
float s = (texcolor.x - texcolor.y) + 2.0 * (texcolor.z - texcolor.w);
s *= u_useStencilTex;
@ -77,7 +77,7 @@ void main()
float fogFactor = 1.0/exp2(u_fogDensity*u_fogDensity*z*z*LOG2);
fogFactor = clamp(fogFactor, 0.0, 1.0);
vec3 color = toLinear(texture2D(u_texColor, v_texcoord0)).xyz;
vec3 color = toLinear(texture2D(s_texColor, v_texcoord0)).xyz;
vec3 ambient = toGamma(ambientColor * color);
vec3 diffuse = toGamma(lightColor * color);

View File

@ -116,8 +116,8 @@ static float s_texelHalf = 0.0f;
static uint32_t s_viewMask = 0;
static bgfx::UniformHandle u_texColor;
static bgfx::UniformHandle u_texStencil;
static bgfx::UniformHandle s_texColor;
static bgfx::UniformHandle s_texStencil;
static bgfx::FrameBufferHandle s_stencilFb;
void setViewClearMask(uint32_t _viewMask, uint8_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil)
@ -1175,9 +1175,9 @@ struct Model
// Set textures
if (bgfx::invalidHandle != m_texture.idx)
{
bgfx::setTexture(0, u_texColor, m_texture);
bgfx::setTexture(0, s_texColor, m_texture);
}
bgfx::setTexture(7, u_texStencil, s_stencilFb);
bgfx::setTexture(1, s_texStencil, s_stencilFb);
// Apply render state
::setRenderState(_renderState);
@ -1897,8 +1897,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
};
s_stencilFb = bgfx::createFrameBuffer(BX_COUNTOF(fbtextures), fbtextures, true);
u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Int1);
u_texStencil = bgfx::createUniform("u_texStencil", bgfx::UniformType::Int1);
s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1);
s_texStencil = bgfx::createUniform("s_texStencil", bgfx::UniformType::Int1);
bgfx::ProgramHandle programTextureLightning = loadProgram("vs_shadowvolume_texture_lightning", "fs_shadowvolume_texture_lightning");
bgfx::ProgramHandle programColorLightning = loadProgram("vs_shadowvolume_color_lightning", "fs_shadowvolume_color_lightning" );
@ -2843,8 +2843,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
s_uniforms.destroy();
bgfx::destroyUniform(u_texColor);
bgfx::destroyUniform(u_texStencil);
bgfx::destroyUniform(s_texColor);
bgfx::destroyUniform(s_texStencil);
bgfx::destroyFrameBuffer(s_stencilFb);
bgfx::destroyTexture(figureTex);