shader snippets

shdr

precision highp float;
uniform float time;
uniform vec2 resolution;
varying vec3 fPosition;
varying vec3 fNormal;

Ward

float Ward(vec3 lightDir, vec3 viewDir, vec3 normal, float exponent)
{
    vec3 H = normalize(lightDir + viewDir);
    float delta = acos(dot(H,normal));
    float alpha2 = exponent * exponent;
    float temp = exp(-pow(tan(delta), 2.) / (alpha2)) / (4. * 3.1415 * alpha2);
    float temp2 = sqrt(dot(viewDir,normal) * dot(lightDir,normal));
    float K = temp2 * temp;
    return K;
}

Ashikhmin

float fresnel(float costheta, float fresnelCoef)
{
  return fresnelCoef + (1. - fresnelCoef) * pow(1. - costheta, 5.);
}

float Ashikhmin(vec3 lightDir, vec3 viewDir,  vec3 normal, float exponent, float fresnelCoef)
{
  vec3 H = normalize(lightDir+viewDir);
  float numerateur_s = ( exponent + 1.)/(8.*3.14159) * pow(dot(normal,H), exponent );
  float denominateur_s = dot(lightDir,H)*(dot(normal,lightDir) + dot(normal, viewDir) -
  dot(normal, lightDir) * dot(normal, viewDir));
  
  float K =  fresnel(dot(normal,lightDir), fresnelCoef) * ( numerateur_s / denominateur_s  ) ;
  return K;
}

OrenNayarDir

float OrenNayarDir(vec3 lightDir, vec3 viewDir, vec3 normal, float exponent)
{
  float LdotN = dot(lightDir,normal);
  float VdotN = dot(viewDir,normal);
  float result = clamp( LdotN, 0. , 1.);
  float soft_rim = clamp( 1. - VdotN/2., 0. , 1.);
  float fakey = pow(1. - result * soft_rim , 2.);
  float fakey_magic = 0.62;
  fakey = fakey_magic - fakey*fakey_magic;
  float K =  mix(result, fakey, exponent) ;
  return K;
}
void main()
{
  
  vec3 pos = fPosition;
  vec3 c = vec3(1,1,0);
  //vec3 c = vec3(0.299, 0.587, 0.114);
  vec3 lightDir = normalize(vec3(10,100,50) - pos);
  vec3 viewDir = normalize(-pos);
  //float f = 5. * OrenNayarDir(lightDir,  viewDir, fNormal, 2.);
  float f = 10. * Ashikhmin(lightDir,  viewDir, fNormal, 2., .9);
  //float f = blinnPhongDir(lightDir, 1.,  .03, .5,  .4, 10.);
  gl_FragColor = vec4(f * c, 1.0);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值