GLSL编程之GLSL(七)——逐像素光照
2014-08-15 10:24
239 查看
下边第二部分:逐像素点光,我试验出了修改方法,但是至于为什么要这样修改,我并不清楚,希望有大神可以帮忙解答,小女感激不尽!!!
本文参考/article/1945460.html
但经过实验,修正其中部分问题
第一部分:逐像素方向光
由原本代码运行得到的结果为:
主要原因是其片段着色器并未将所有颜色加在一起,最后加上这条语句即可:
以下修改代码也有修改其他成分——
修改其中的顶点着色器为:
片段着色器为:
修改之后的结果为:
第二部分:逐像素点光
原图:
添加语句即可修改
修改之后的图:
第三部分:逐像素聚光
本文参考/article/1945460.html
但经过实验,修正其中部分问题
第一部分:逐像素方向光
由原本代码运行得到的结果为:
主要原因是其片段着色器并未将所有颜色加在一起,最后加上这条语句即可:
color = globalAmbient + NdotL * diffuse + ambient;
以下修改代码也有修改其他成分——
修改其中的顶点着色器为:
varying vec4 diffuse,ambient,globalAmbient ; varying vec3 normal,lightDir,halfVector; void main() { normal = normalize(gl_NormalMatrix * gl_Normal); lightDir = normalize(vec3(gl_LightSource[0].position)); halfVector = normalize(gl_LightSource[0].halfVector.xyz); diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient; globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient; gl_Position = ftransform(); }
片段着色器为:
varying vec4 diffuse,ambient,globalAmbient; varying vec3 normal,lightDir,halfVector; void main() { vec3 n,halfV,viewV,ldir; float NdotL,NdotHV; vec4 color ; /* a fragment shader can't write a verying variable, hence we need a new variable to store the normalized interpolated normal */ n = normalize(normal); /* compute the dot product between normal and ldir */ NdotL = max(dot(n,lightDir),0.0); color = globalAmbient + NdotL * diffuse + ambient; gl_FragColor = color; }
修改之后的结果为:
第二部分:逐像素点光
原图:
添加语句即可修改
color = globalAmbient + NdotL * diffuse + ambient;
修改之后的图:
第三部分:逐像素聚光
相关文章推荐
- 【GLSL教程】(七)逐像素的光照
- GPU编程之GLSL(六)——着色与逐顶点光照
- 【GLSL教程】(七)逐像素的光照
- 【GLSL教程】(七)逐像素的光照
- 【GLSL教程】(七)逐像素的光照 【转】
- 【GLSL教程】(七)逐像素的光照
- 【GLSL教程】(七)逐像素的光照
- glsl实现像素光照的方法
- GLSL 逐像素的光照
- 【GLSL教程】(七)逐像素的光照
- GLSL逐像素光照 【转】
- GLSL逐个像素光照的问题(解决了,更新显卡驱动和GLEW就行了)
- 【GLSL教程】(七)逐像素的光照
- 我的opengl编程学习(一)(简介、绘制图像、三维观察、光照)
- GLSL着色语言的学习(二)光照模型
- HTML5高级编程之像素处理及粒子效果
- 基于Qt的OpenGL编程(3.x以上GLSL可编程管线版)---(二)你好,三角形_QOpenGLShader版
- 基于Qt的OpenGL编程(3.x以上GLSL可编程管线版)---(四)纹理
- Shader基于片段编程的Lambert光照,Phong光照和Blinn-Phong光照