bgfx/examples/12-lod/fs_tree.sc

43 lines
1.1 KiB
Python
Raw Normal View History

2013-05-18 14:41:32 +04:00
$input v_pos, v_view, v_normal, v_texcoord0
/*
* Copyright 2013 Milos Tosic. All rights reserved.
2022-01-15 22:59:06 +03:00
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
2013-05-18 14:41:32 +04:00
*/
#include "../common/common.sh"
2015-10-25 08:34:11 +03:00
SAMPLER2D(s_texColor, 0);
SAMPLER2D(s_texStipple, 1);
2015-05-29 01:27:00 +03:00
uniform vec4 u_stipple;
2013-05-18 14: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 20:43:57 +04:00
vec2 stippleUV = viewport*(v_pos.xy*0.5 + 0.5);
2015-10-25 08:34:11 +03:00
vec4 color = texture2D(s_texColor, v_texcoord0);
2015-10-25 08:47:24 +03:00
if ( (u_stipple.x - texture2D(s_texStipple, stippleUV).x)*u_stipple.y > u_stipple.z
2015-05-29 01:27:00 +03:00
|| color.w < 0.5)
2013-05-19 09:55:43 +04:00
{
2013-05-18 14:41:32 +04:00
discard;
2013-05-19 09:55:43 +04:00
}
2013-05-18 14: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);
2015-10-25 08:53:26 +03:00
float l = saturate(bln.y) + 0.12;
2013-05-18 20:43:57 +04:00
2013-05-19 09:55:43 +04:00
color.xyz = toLinear(color.xyz)*l;
2013-05-18 14:41:32 +04:00
gl_FragColor = toGamma(color);
}