23 lines
548 B
GLSL
23 lines
548 B
GLSL
//! 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 );
|
|
}
|