bgfx/examples/12-lod/fs_tree.sc

43 lines
1.1 KiB
Python
Raw Normal View History

2013-05-18 06:41:32 -04:00
$input v_pos, v_view, v_normal, v_texcoord0
/*
* Copyright 2013 Milos Tosic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "../common/common.sh"
SAMPLER2D(u_texColor, 0);
SAMPLER2D(u_texStipple, 1);
2015-05-28 18:27:00 -04:00
uniform vec4 u_stipple;
2013-05-18 06:41:32 -04:00
vec2 blinn(vec3 _lightDir, vec3 _normal, vec3 _viewDir)
{
float ndotl = dot(_normal, _lightDir);
vec3 reflected = _lightDir - 2.0*ndotl*_normal; // reflect(_lightDir, _normal);
float rdotv = dot(reflected, _viewDir);
return vec2(ndotl, rdotv);
}
void main()
{
vec2 viewport = (u_viewRect.zw - u_viewRect.xy) * vec2(1.0/8.0, 1.0/4.0);
2013-05-18 12:43:57 -04:00
vec2 stippleUV = viewport*(v_pos.xy*0.5 + 0.5);
2013-05-19 01:55:43 -04:00
vec4 color = texture2D(u_texColor, v_texcoord0);
2015-05-28 18:27:00 -04:00
if ( (u_stipple.x - texture2D(u_texStipple,stippleUV).x)*u_stipple.y > u_stipple.z
|| color.w < 0.5)
2013-05-19 01:55:43 -04:00
{
2013-05-18 06:41:32 -04:00
discard;
2013-05-19 01:55:43 -04:00
}
2013-05-18 06:41:32 -04:00
vec3 lightDir = vec3(0.0, 0.0, -1.0);
vec3 normal = normalize(v_normal);
vec3 view = normalize(v_view);
vec2 bln = blinn(lightDir, normal, view);
2013-05-19 01:55:43 -04:00
float l = saturate(bln.y);
2013-05-18 12:43:57 -04:00
2013-05-19 01:55:43 -04:00
color.xyz = toLinear(color.xyz)*l;
2013-05-18 06:41:32 -04:00
gl_FragColor = toGamma(color);
}