mirror of https://github.com/bkaradzic/bgfx
Added examples 13-stencil and 14-shadowvolumes
This commit is contained in:
parent
2723b15ab6
commit
48aa0079ae
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
$input v_normal, v_view
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
uniform vec4 u_params;
|
||||
uniform vec3 u_ambient;
|
||||
uniform vec3 u_diffuse;
|
||||
uniform vec4 u_color;
|
||||
uniform vec4 u_specular_shininess;
|
||||
uniform vec4 u_lightPosRadius[5];
|
||||
uniform vec4 u_lightRgbInnerR[5];
|
||||
|
||||
#define u_ambientPass u_params.x
|
||||
#define u_lightningPass u_params.y
|
||||
#define u_alpha u_params.z
|
||||
#define u_lightCount u_params.w
|
||||
#define u_specular u_specular_shininess.xyz
|
||||
#define u_shininess u_specular_shininess.w
|
||||
|
||||
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
||||
{
|
||||
float ndotl = dot(_normal, _lightDir);
|
||||
vec3 reflected = 2.0*ndotl*_normal - _lightDir; // reflect(_lightDir, _normal);
|
||||
float rdotv = dot(reflected, _viewDir);
|
||||
return vec2(ndotl, rdotv);
|
||||
}
|
||||
|
||||
vec4 lit(float _ndotl, float _rdotv, float _m)
|
||||
{
|
||||
float diff = max(0.0, _ndotl);
|
||||
float spec = step(0.0, _ndotl) * pow(max(0.0, _rdotv), _m);
|
||||
return vec4(1.0, diff, spec, 1.0);
|
||||
}
|
||||
|
||||
vec3 calcLight(int _idx, vec3 _view, vec3 _normal, vec3 _viewDir)
|
||||
{
|
||||
if (float(_idx) >= u_lightCount)
|
||||
return vec3_splat(0.0);
|
||||
|
||||
vec3 lightPos = mul(u_view, vec4(u_lightPosRadius[_idx].xyz, 1.0)).xyz;
|
||||
vec3 toLight = lightPos - _view;
|
||||
vec3 lightDir = normalize(toLight);
|
||||
|
||||
vec2 bln = blinn(lightDir, _normal, _viewDir);
|
||||
vec4 lc = lit(bln.x, bln.y, u_shininess);
|
||||
|
||||
float dist = max(length(toLight), u_lightPosRadius[_idx].w);
|
||||
float attn = 100.0 * pow(dist, -2.0);
|
||||
vec3 rgb = (lc.y * u_diffuse + lc.z * u_specular) * u_lightRgbInnerR[_idx].rgb * attn;
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = normalize(v_normal);
|
||||
vec3 viewDir = -normalize(v_view);
|
||||
|
||||
vec3 ambientColor = u_ambient * u_ambientPass;
|
||||
|
||||
vec3 lightColor = vec3_splat(0.0);
|
||||
for(int ii = 0; ii < 5; ++ii)
|
||||
{
|
||||
lightColor += calcLight(ii, v_view, normal, viewDir);
|
||||
}
|
||||
lightColor *= u_lightningPass;
|
||||
|
||||
vec3 color = u_color.xyz;
|
||||
|
||||
vec3 ambient = toGamma(ambientColor * color);
|
||||
vec3 diffuse = toGamma(lightColor * color);
|
||||
gl_FragColor.xyz = clamp(ambient + diffuse, 0.0, 1.0);
|
||||
|
||||
gl_FragColor.w = u_alpha;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
$input v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
uniform vec4 u_color;
|
||||
SAMPLER2D(u_texColor, 0);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tcolor = toLinear(texture2D(u_texColor, v_texcoord0));
|
||||
|
||||
if (tcolor.x < 0.1) //OK for now.
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
gl_FragColor = toGamma(tcolor + u_color);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
$input v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
SAMPLER2D(u_texColor, 0);
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(u_texColor, v_texcoord0);
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
$input v_normal, v_view, v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
uniform vec4 u_params;
|
||||
uniform vec3 u_ambient;
|
||||
uniform vec3 u_diffuse;
|
||||
uniform vec4 u_color;
|
||||
uniform vec4 u_specular_shininess;
|
||||
uniform vec4 u_lightPosRadius[5];
|
||||
uniform vec4 u_lightRgbInnerR[5];
|
||||
SAMPLER2D(u_texColor, 0);
|
||||
|
||||
#define u_ambientPass u_params.x
|
||||
#define u_lightningPass u_params.y
|
||||
#define u_alpha u_params.z
|
||||
#define u_lightCount u_params.w
|
||||
#define u_specular u_specular_shininess.xyz
|
||||
#define u_shininess u_specular_shininess.w
|
||||
|
||||
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
||||
{
|
||||
float ndotl = dot(_normal, _lightDir);
|
||||
vec3 reflected = 2.0*ndotl*_normal - _lightDir; // reflect(_lightDir, _normal);
|
||||
float rdotv = dot(reflected, _viewDir);
|
||||
return vec2(ndotl, rdotv);
|
||||
}
|
||||
|
||||
vec4 lit(float _ndotl, float _rdotv, float _m)
|
||||
{
|
||||
float diff = max(0.0, _ndotl);
|
||||
float spec = step(0.0, _ndotl) * pow(max(0.0, _rdotv), _m);
|
||||
return vec4(1.0, diff, spec, 1.0);
|
||||
}
|
||||
|
||||
vec3 calcLight(int _idx, vec3 _view, vec3 _normal, vec3 _viewDir)
|
||||
{
|
||||
if (float(_idx) >= u_lightCount)
|
||||
return vec3_splat(0.0);
|
||||
|
||||
vec3 lightPos = mul(u_view, vec4(u_lightPosRadius[_idx].xyz, 1.0)).xyz;
|
||||
vec3 toLight = lightPos - _view;
|
||||
vec3 lightDir = normalize(toLight);
|
||||
|
||||
vec2 bln = blinn(lightDir, _normal, _viewDir);
|
||||
vec4 lc = lit(bln.x, bln.y, u_shininess);
|
||||
|
||||
float dist = max(length(toLight), u_lightPosRadius[_idx].w);
|
||||
float attn = 100.0 * pow(dist, -2.0);
|
||||
vec3 rgb = (lc.y * u_diffuse + lc.z * u_specular) * u_lightRgbInnerR[_idx].rgb * attn;
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = normalize(v_normal);
|
||||
vec3 viewDir = -normalize(v_view);
|
||||
|
||||
vec3 ambientColor = u_ambient * u_ambientPass;
|
||||
|
||||
vec3 lightColor = vec3_splat(0.0);
|
||||
for(int ii = 0; ii < 5; ++ii)
|
||||
{
|
||||
lightColor += calcLight(ii, v_view, normal, viewDir);
|
||||
}
|
||||
lightColor *= u_lightningPass;
|
||||
|
||||
vec3 color = toLinear(texture2D(u_texColor, v_texcoord0)).xyz;
|
||||
|
||||
vec3 ambient = toGamma(ambientColor * color);
|
||||
vec3 diffuse = toGamma(lightColor * color);
|
||||
gl_FragColor.xyz = clamp(ambient + diffuse, 0.0, 1.0);
|
||||
|
||||
gl_FragColor.w = u_alpha;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#
|
||||
# Copyright 2013 Dario Manesku. All rights reserved.
|
||||
# License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
#
|
||||
|
||||
BGFX_DIR=../..
|
||||
RUNTIME_DIR=$(BGFX_DIR)/examples/runtime
|
||||
BUILD_DIR=../../.build
|
||||
|
||||
include $(BGFX_DIR)/premake/shader.mk
|
||||
|
||||
geometry: ../runtime/meshes/column.bin
|
||||
|
||||
../runtime/meshes/column.bin: column.obj
|
||||
../../tools/bin/geometryc -f column.obj -o ../runtime/meshes/column.bin --packnormal 1
|
||||
|
||||
rebuild:
|
||||
@make -s --no-print-directory TARGET=0 clean all
|
||||
@make -s --no-print-directory TARGET=1 clean all
|
||||
@make -s --no-print-directory TARGET=2 clean all
|
||||
@make -s --no-print-directory TARGET=3 clean all
|
||||
@make -s --no-print-directory TARGET=4 clean all
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
|||
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||
vec3 v_view : TEXCOORD1 = vec3(0.0, 0.0, 0.0);
|
||||
vec3 v_normal : NORMAL = vec3(0.0, 0.0, 1.0);
|
||||
|
||||
vec3 a_position : POSITION;
|
||||
vec4 a_normal : NORMAL;
|
||||
vec2 a_texcoord0 : TEXCOORD0;
|
|
@ -0,0 +1,13 @@
|
|||
$input a_position
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
$input a_position, a_normal, a_texcoord0
|
||||
$output v_normal, v_view
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||
|
||||
vec4 normal = a_normal * 2.0f - 1.0f;
|
||||
v_normal = mul(u_modelView, vec4(normal.xyz, 0.0)).xyz;
|
||||
v_view = mul(u_modelView, vec4(a_position, 1.0)).xyz;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
$input a_position, a_texcoord0
|
||||
$output v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||
|
||||
v_texcoord0 = a_texcoord0;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
$input a_position, a_texcoord0
|
||||
$output v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||
|
||||
v_texcoord0 = a_texcoord0;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
$input a_position, a_normal, a_texcoord0
|
||||
$output v_normal, v_view, v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||
|
||||
vec4 normal = a_normal * 2.0f - 1.0f;
|
||||
v_normal = mul(u_modelView, vec4(normal.xyz, 0.0)).xyz;
|
||||
v_view = mul(u_modelView, vec4(a_position, 1.0)).xyz;
|
||||
|
||||
v_texcoord0 = a_texcoord0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,88 @@
|
|||
$input v_normal, v_view, v_pos
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
uniform vec4 u_params;
|
||||
uniform vec4 u_svparams;
|
||||
uniform vec3 u_ambient;
|
||||
uniform vec3 u_diffuse;
|
||||
uniform vec4 u_color;
|
||||
uniform vec4 u_specular_shininess;
|
||||
uniform vec4 u_fog;
|
||||
uniform vec4 u_lightPosRadius;
|
||||
uniform vec4 u_lightRgbInnerR;
|
||||
SAMPLER2D(u_texStencil, 7);
|
||||
|
||||
#define u_ambientPass u_params.x
|
||||
#define u_lightningPass u_params.y
|
||||
#define u_alpha u_params.z
|
||||
#define u_specular u_specular_shininess.xyz
|
||||
#define u_shininess u_specular_shininess.w
|
||||
|
||||
#define u_fogColor u_fog.xyz
|
||||
#define u_fogDensity u_fog.w
|
||||
|
||||
#define u_useStencilTex u_svparams.x
|
||||
|
||||
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
||||
{
|
||||
float ndotl = dot(_normal, _lightDir);
|
||||
vec3 reflected = 2.0*ndotl*_normal - _lightDir; // reflect(_lightDir, _normal);
|
||||
float rdotv = dot(reflected, _viewDir);
|
||||
return vec2(ndotl, rdotv);
|
||||
}
|
||||
|
||||
vec4 lit(float _ndotl, float _rdotv, float _m)
|
||||
{
|
||||
float diff = max(0.0, _ndotl);
|
||||
float spec = step(0.0, _ndotl) * pow(max(0.0, _rdotv), _m);
|
||||
return vec4(1.0, diff, spec, 1.0);
|
||||
}
|
||||
|
||||
vec3 calcLight(vec3 _view, vec3 _normal, vec3 _viewDir)
|
||||
{
|
||||
vec3 lightPos = mul(u_view, vec4(u_lightPosRadius.xyz, 1.0)).xyz;
|
||||
vec3 toLight = lightPos - _view;
|
||||
vec3 lightDir = normalize(toLight);
|
||||
|
||||
vec2 bln = blinn(lightDir, _normal, _viewDir);
|
||||
vec4 lc = lit(bln.x, bln.y, u_shininess);
|
||||
|
||||
float dist = max(length(toLight), u_lightPosRadius.w);
|
||||
float attn = 50.0 * pow(dist, -2.0);
|
||||
vec3 rgb = (lc.y * u_diffuse + lc.z * u_specular) * u_lightRgbInnerR.rgb * attn;
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ambientColor = u_ambient * u_ambientPass;
|
||||
|
||||
vec3 normal = normalize(v_normal);
|
||||
vec3 viewDir = -normalize(v_view);
|
||||
vec3 lightColor = calcLight(v_view, normal, viewDir) * u_lightningPass;
|
||||
|
||||
vec2 ndc = ((v_pos.xy / v_pos.w) + 1.0) / 2.0;
|
||||
vec4 texcolor = texture2D(u_texStencil, ndc);
|
||||
float s = (texcolor.x - texcolor.y) + 2.0 * (texcolor.z - texcolor.w);
|
||||
s *= u_useStencilTex;
|
||||
|
||||
const float LOG2 = 1.442695;
|
||||
float z = length(v_view);
|
||||
float fogFactor = 1.0/exp2(u_fogDensity*u_fogDensity*z*z*LOG2);
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
vec3 color = u_color.xyz;
|
||||
|
||||
vec3 ambient = toGamma(ambientColor * color);
|
||||
vec3 diffuse = toGamma(lightColor * color);
|
||||
vec3 final = mix(ambient, ambient + diffuse, float((abs(s) < 0.0001)));
|
||||
|
||||
gl_FragColor.xyz = mix(u_fogColor, final, fogFactor);
|
||||
gl_FragColor.w = u_alpha;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
$input v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
uniform vec4 u_color;
|
||||
SAMPLER2D(u_texColor, 0);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tcolor = toLinear(texture2D(u_texColor, v_texcoord0));
|
||||
|
||||
if (tcolor.x < 0.1) //OK for now.
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
gl_FragColor = toGamma(tcolor + u_color);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4_splat(1.0);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
uniform vec4 u_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor.xyz = u_color.xyz;
|
||||
gl_FragColor.w = 0.98;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2013 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
|
||||
);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float k = 1.0;
|
||||
if (!gl_FrontFacing)
|
||||
k = -k;
|
||||
|
||||
gl_FragColor = stencilColor(k);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2013 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
|
||||
);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float k = 2.0;
|
||||
if (!gl_FrontFacing)
|
||||
k = -k;
|
||||
|
||||
gl_FragColor = stencilColor(k);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor.xyz = vec3_splat(0.0);
|
||||
gl_FragColor.w = 1.0;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
uniform vec4 u_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor.xyz = u_color.xyz;
|
||||
gl_FragColor.w = 0.98;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2013 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
|
||||
);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float k = -1.0;
|
||||
if (gl_FrontFacing)
|
||||
k = -k;
|
||||
|
||||
gl_FragColor = stencilColor(k);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright 2013 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
|
||||
);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float k = -2.0;
|
||||
if (gl_FrontFacing)
|
||||
k = -k;
|
||||
|
||||
gl_FragColor = stencilColor(k);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
$input v_k
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
uniform vec3 u_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
float k = v_k;
|
||||
if (!gl_FrontFacing)
|
||||
k = -k;
|
||||
|
||||
gl_FragColor.xyzw =
|
||||
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
|
||||
);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
$input v_k
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
$input v_k
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
uniform vec4 u_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor.xyz = u_color.xyz;
|
||||
gl_FragColor.w = 0.98;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
$input v_k
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
uniform vec4 u_svparams;
|
||||
|
||||
#define u_dfail u_svparams.y
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float k = v_k;
|
||||
|
||||
if (!gl_FrontFacing)
|
||||
k = -k;
|
||||
|
||||
if (u_dfail == 0.0)
|
||||
k = -k;
|
||||
|
||||
gl_FragColor = stencilColor(k);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
$input v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
SAMPLER2D(u_texColor, 0);
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(u_texColor, v_texcoord0);
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
$input v_normal, v_view, v_texcoord0, v_pos
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
uniform vec4 u_params;
|
||||
uniform vec4 u_svparams;
|
||||
uniform vec3 u_ambient;
|
||||
uniform vec3 u_diffuse;
|
||||
uniform vec4 u_color;
|
||||
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);
|
||||
|
||||
#define u_ambientPass u_params.x
|
||||
#define u_lightningPass u_params.y
|
||||
#define u_alpha u_params.z
|
||||
#define u_specular u_specular_shininess.xyz
|
||||
#define u_shininess u_specular_shininess.w
|
||||
|
||||
#define u_fogColor u_fog.xyz
|
||||
#define u_fogDensity u_fog.w
|
||||
|
||||
#define u_useStencilTex u_svparams.x
|
||||
|
||||
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
|
||||
{
|
||||
float ndotl = dot(_normal, _lightDir);
|
||||
vec3 reflected = 2.0*ndotl*_normal - _lightDir; // reflect(_lightDir, _normal);
|
||||
float rdotv = dot(reflected, _viewDir);
|
||||
return vec2(ndotl, rdotv);
|
||||
}
|
||||
|
||||
vec4 lit(float _ndotl, float _rdotv, float _m)
|
||||
{
|
||||
float diff = max(0.0, _ndotl);
|
||||
float spec = step(0.0, _ndotl) * pow(max(0.0, _rdotv), _m);
|
||||
return vec4(1.0, diff, spec, 1.0);
|
||||
}
|
||||
|
||||
vec3 calcLight(vec3 _view, vec3 _normal, vec3 _viewDir)
|
||||
{
|
||||
vec3 lightPos = mul(u_view, vec4(u_lightPosRadius.xyz, 1.0)).xyz;
|
||||
vec3 toLight = lightPos - _view;
|
||||
vec3 lightDir = normalize(toLight);
|
||||
|
||||
vec2 bln = blinn(lightDir, _normal, _viewDir);
|
||||
vec4 lc = lit(bln.x, bln.y, u_shininess);
|
||||
|
||||
float dist = max(length(toLight), u_lightPosRadius.w);
|
||||
float attn = 50.0 * pow(dist, -2.0);
|
||||
vec3 rgb = (lc.y * u_diffuse + lc.z * u_specular) * u_lightRgbInnerR.rgb * attn;
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ambientColor = u_ambient * u_ambientPass;
|
||||
|
||||
vec3 normal = normalize(v_normal);
|
||||
vec3 viewDir = -normalize(v_view);
|
||||
vec3 lightColor = calcLight(v_view, normal, viewDir) * u_lightningPass;
|
||||
|
||||
vec2 ndc = ((v_pos.xy / v_pos.w) + 1.0) / 2.0;
|
||||
vec4 texcolor = texture2D(u_texStencil, ndc);
|
||||
float s = (texcolor.x - texcolor.y) + 2.0 * (texcolor.z - texcolor.w);
|
||||
s *= u_useStencilTex;
|
||||
|
||||
const float LOG2 = 1.442695;
|
||||
float z = length(v_view);
|
||||
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 ambient = toGamma(ambientColor * color);
|
||||
vec3 diffuse = toGamma(lightColor * color);
|
||||
vec3 final = mix(ambient, ambient + diffuse, float((abs(s) < 0.0001)));
|
||||
|
||||
gl_FragColor.xyz = mix(u_fogColor, final, fogFactor);
|
||||
gl_FragColor.w = u_alpha;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# Copyright 2013 Dario Manesku. All rights reserved.
|
||||
# License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
#
|
||||
|
||||
BGFX_DIR=../..
|
||||
RUNTIME_DIR=$(BGFX_DIR)/examples/runtime
|
||||
BUILD_DIR=../../.build
|
||||
|
||||
include $(BGFX_DIR)/premake/shader.mk
|
||||
|
||||
geometry: ../runtime/meshes/bunny_patched.bin ../runtime/meshes/bunny_decimated.bin
|
||||
|
||||
../runtime/meshes/bunny_patched.bin: bunny_patched.obj
|
||||
../../tools/bin/geometryc -f bunny_patched.obj -o ../runtime/meshes/bunny_patched.bin --packnormal 1
|
||||
|
||||
../runtime/meshes/bunny_decimated.bin: bunny_decimated.obj
|
||||
../../tools/bin/geometryc -f bunny_decimated.obj -o ../runtime/meshes/bunny_decimated.bin --packnormal 1
|
||||
|
||||
rebuild:
|
||||
@make -s --no-print-directory TARGET=0 clean all
|
||||
@make -s --no-print-directory TARGET=1 clean all
|
||||
@make -s --no-print-directory TARGET=2 clean all
|
||||
@make -s --no-print-directory TARGET=3 clean all
|
||||
@make -s --no-print-directory TARGET=4 clean all
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,16 @@
|
|||
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||
vec4 v_pos : TEXCOORD1 = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
vec3 v_normal : NORMAL = vec3(0.0, 0.0, 1.0);
|
||||
vec3 v_view : TEXCOORD2 = vec3(0.0, 0.0, 0.0);
|
||||
vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
float v_k : FOG = 1.0;
|
||||
|
||||
vec3 a_position : POSITION;
|
||||
vec4 a_normal : NORMAL;
|
||||
vec4 a_color0 : COLOR0;
|
||||
vec2 a_texcoord0 : TEXCOORD0;
|
||||
vec4 i_data0 : TEXCOORD3;
|
||||
vec4 i_data1 : TEXCOORD4;
|
||||
vec4 i_data2 : TEXCOORD5;
|
||||
vec4 i_data3 : TEXCOORD6;
|
||||
vec4 i_data4 : TEXCOORD7;
|
|
@ -0,0 +1,23 @@
|
|||
$input a_position, a_color0, a_normal, a_texcoord0
|
||||
$output v_normal, v_view, v_pos
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
uniform float u_flipV;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||
|
||||
vec4 normal = a_normal * 2.0f - 1.0f;
|
||||
v_normal = mul(u_modelView, vec4(normal.xyz, 0.0)).xyz;
|
||||
v_view = mul(u_modelView, vec4(a_position, 1.0)).xyz;
|
||||
|
||||
v_pos = gl_Position;
|
||||
v_pos.y *= -u_flipV;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
$input a_position, a_texcoord0
|
||||
$output v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||
|
||||
v_texcoord0 = a_texcoord0;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
$input a_position
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
uniform vec4 u_virtualLightPos_extrusionDist;
|
||||
|
||||
#define u_virtualLightPos u_virtualLightPos_extrusionDist.xyz
|
||||
#define u_extrusionDistance u_virtualLightPos_extrusionDist.w
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 pos = a_position;
|
||||
|
||||
vec3 toLight = pos - u_virtualLightPos;
|
||||
pos += normalize(toLight) * u_extrusionDistance;
|
||||
|
||||
gl_Position = mul(u_modelViewProj, vec4(pos, 1.0));
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
$input a_position
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
$input a_position, a_texcoord0
|
||||
$output v_k
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
uniform vec4 u_virtualLightPos_extrusionDist;
|
||||
|
||||
#define u_virtualLightPos u_virtualLightPos_extrusionDist.xyz
|
||||
#define u_extrusionDistance u_virtualLightPos_extrusionDist.w
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 pos = a_position;
|
||||
if (a_texcoord0.x == 1.0)
|
||||
{
|
||||
vec3 toLight = pos - u_virtualLightPos;
|
||||
pos += normalize(toLight) * u_extrusionDistance;
|
||||
}
|
||||
gl_Position = mul(u_modelViewProj, vec4(pos, 1.0));
|
||||
|
||||
v_k = a_texcoord0.y;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
$input a_position, a_texcoord0
|
||||
$output v_texcoord0
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||
|
||||
v_texcoord0 = a_texcoord0;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
$input a_position, a_normal, a_texcoord0
|
||||
$output v_normal, v_view, v_texcoord0, v_pos
|
||||
|
||||
/*
|
||||
* Copyright 2013 Dario Manesku. All rights reserved.
|
||||
* License: http://www.opensource.org/licenses/BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "../common/common.sh"
|
||||
|
||||
uniform float u_flipV;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
|
||||
|
||||
vec4 normal = a_normal * 2.0f - 1.0f;
|
||||
v_normal = mul(u_modelView, vec4(normal.xyz, 0.0)).xyz;
|
||||
v_view = mul(u_modelView, vec4(a_position, 1.0)).xyz;
|
||||
|
||||
v_texcoord0 = a_texcoord0;
|
||||
|
||||
v_pos = gl_Position;
|
||||
v_pos.y *= -u_flipV;
|
||||
}
|
Loading…
Reference in New Issue