lightFuncSpecularV.glsl
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:1k
源码类别:
游戏引擎
开发平台:
C++ Builder
- /**
- * @file lightFuncSpecularV.glsl
- *
- * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
- * $License$
- */
- float calcDirectionalLight(vec3 n, vec3 l)
- {
- float a = max(dot(n,l),0.0);
- return a;
- }
- float calcDirectionalSpecular(vec3 view, vec3 n, vec3 l)
- {
- return pow(max(dot(reflect(view, n),l), 0.0),8.0);
- }
- float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da)
- {
- specular.rgb += calcDirectionalSpecular(view,n,l)*lightCol*da;
- return max(dot(n,l),0.0);
- }
- vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol)
- {
- //get light vector
- vec3 lv = l-v;
- //get distance
- float d = length(lv);
- //normalize light vector
- lv *= 1.0/d;
- //distance attenuation
- float da = clamp(1.0/(r * d), 0.0, 1.0);
- //angular attenuation
- da *= calcDirectionalLightSpecular(specular, view, n, lv, lightCol, da);
- return da*lightCol;
- }