demotool/test/shaders/lib/shading-blinnphong.glsl

24 lines
548 B
Text
Raw Normal View History

2017-10-04 19:06:50 +02:00
//! type library
struct T_BPMaterial
{
vec3 cAlbedo, cSpecular;
float specPower , ambient;
};
vec3 BP_Shade(
in T_BPMaterial material ,
in vec3 rayDir ,
in vec3 normal ,
in vec3 lightDir )
{
const vec3 halfVec = normalize( rayDir + lightDir );
const float nDotL = dot( normal , lightDir ) ,
nDotH = dot( normal , halfVec ) ,
si = pow( clamp( nDotH , 0 , 1 ) , material.specPower ) ,
di = material.ambient + ( 1 - material.ambient )
* clamp( nDotL , 0 , 1 );
return mix( material.cAlbedo * di , material.cSpecular , si );
}