X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=shaderlib%2Fcommon.glsl;h=35d5a87eafb8bf8c83e8fe877cdf5e90b0a3d724;hb=HEAD;hp=300726dc541c0f7d4cfcdfdcdba9094f4662f242;hpb=857c2db0fb3112b750b618625649d12e13d9ae1a;p=libs%2Fgl.git diff --git a/shaderlib/common.glsl b/shaderlib/common.glsl index 300726dc..249cae7c 100644 --- a/shaderlib/common.glsl +++ b/shaderlib/common.glsl @@ -1,10 +1,17 @@ import msp_interface; import shadow; +struct AlphaCutoffParams +{ + float cutoff; + float feather; +}; + layout(set=1) uniform sampler2D normal_map; layout(constant_id=auto) const bool use_instancing = false; layout(constant_id=auto) const bool use_normal_map = false; +layout(constant_id=auto) const bool use_alpha_cutoff = false; #pragma MSP stage(vertex) virtual vec4 get_vertex_position() @@ -68,12 +75,6 @@ void main() } #pragma MSP stage(fragment) -struct IncomingLight -{ - vec3 direction; - vec3 color; -}; - layout(location=0) out vec4 frag_color; virtual vec3 get_fragment_normal() @@ -86,13 +87,17 @@ virtual vec3 get_fragment_normal() return sgn*normalize(world_normal); } -virtual IncomingLight get_incoming_light(int index, vec3 world_pos) +float apply_alpha_cutoff(float alpha, AlphaCutoffParams params) { - vec4 light_pos = light_sources[index].position; - vec3 rel_pos = light_pos.xyz-world_pos*light_pos.w; - float d = length(rel_pos); - float attenuation = 1.0/dot(vec3(1.0, d, d*d), light_sources[index].attenuation); - return IncomingLight(rel_pos/d, light_sources[index].color*attenuation); + if(use_alpha_cutoff) + { + if(alpha