首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >组成ADS (Phong/Gourang)组件

组成ADS (Phong/Gourang)组件
EN

Stack Overflow用户
提问于 2013-04-21 04:24:02
回答 1查看 91关注 0票数 0

我有下面的基本着色器代码,用于Phong照明模型。我已经测试了漫反射、环境光和镜面光,它们产生了正确的结果。当涉及到在最后一行上组成它们时,我总是得到一个看起来像环境光本身的效果。有人知道它出了什么问题吗?

代码语言:javascript
复制
//translate the normals to be in sync with any tranlations applied to the model
vec3 tnormal = normalize(vec3(viewMatrix * modelMatrix * vec4(normal,0.0)));    
vec3 tVertex = vec3(viewMatrix * modelMatrix * vec4(position, 1.0));

// Ambient = La * Ka
vec3 ambience = La * theMaterial.ka;

//Diffuse = Ld * Kd * dot(s, n)
vec3 s = normalize(vec3(myLight.position - tVertex));
vec3 diffuse = myLight.Ld * theMaterial.kd * max(dot(s, tnormal), 0.0);

//Specular = Ls * ks * dot(r,n)^f
//r is the reflection of -lightposition,  r = -s + 2 * dot(s,n) * n 
vec3 r = normalize(reflect(-myLight.position, tnormal));
vec3 v = normalize(-tVertex.xyz);
vec3 specularity = myLight.Ls * theMaterial.ks * pow(dot(v, r), theMaterial.f);


//(ABS) Intensity = Ia * Id * Is
LightIntensity = ambience * diffuse * specularity;
EN

回答 1

Stack Overflow用户

发布于 2013-04-21 04:30:07

我是个笨蛋。我的笔记错误地指出,强度应该是分量的乘积,而实际上它是总和。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16124824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档