OpenGL 4.0 GLSL 用多个光照模型
来源:互联网 发布:淘宝客返利api 编辑:程序博客网 时间:2024/04/29 21:03
在多个光照模型中,我们需要计算每个光照模型的颜色值,然后把这些颜色值相加得到最终物体表面的颜色值。
通常,我们会创建一个统一的数组来存储光源的位置和光照强度(密度)(见下文shader)
如图:一个5个光源的场景
顶点shader
#version 430layout (location = 0) in vec3 VertexPosition;layout (location = 1) in vec3 VertexNormal;out vec3 Color;struct LightInfo { vec4 Position; // Light position in eye coords. vec3 Intensity; // Light intesity (amb., diff., and spec.)};uniform LightInfo lights[5];// Material parametersuniform vec3 Kd; // Diffuse reflectivityuniform vec3 Ka; // Ambient reflectivityuniform vec3 Ks; // Specular reflectivityuniform float Shininess; // Specular shininess factoruniform mat4 ModelViewMatrix;uniform mat3 NormalMatrix;uniform mat4 ProjectionMatrix;uniform mat4 MVP;vec3 ads( int lightIndex, vec4 position, vec3 norm ){ vec3 s = normalize( vec3(lights[lightIndex].Position - position) ); vec3 v = normalize(vec3(-position)); vec3 r = reflect( -s, norm ); vec3 I = lights[lightIndex].Intensity; return I * ( Ka + Kd * max( dot(s, norm), 0.0 ) +Ks * pow( max( dot(r,v), 0.0 ), Shininess ) );}void main(){ vec3 eyeNorm = normalize( NormalMatrix * VertexNormal); vec4 eyePosition = ModelViewMatrix * vec4(VertexPosition,1.0); // Evaluate the lighting equation, for each light Color = vec3(0.0); for( int i = 0; i < 5; i++ ) Color += ads( i, eyePosition, eyeNorm ); gl_Position = MVP * vec4(VertexPosition,1.0);}
片元shader
#version 430in vec3 Color;layout( location = 0 ) out vec4 FragColor;void main() { FragColor = vec4(Color, 1.0);}
0 0
- OpenGL 4.0 GLSL 用多个光照模型
- OpenGL 4.0 GLSL 采用平行光照模型
- OpenGL 4.0 GLSL 用单光源 实现逐顶点 漫反射光照模型
- OpenGL进阶(十三) - GLSL光照(Lighting)
- OpenGL进阶(十三) - GLSL光照(Lighting)
- OpenGL光照模型
- OpenGL-光照模型
- OpenGL-光照模型
- opengl光照模型
- OpenGL.光照模型
- opengl光照模型
- 基础光照模型公式与源码【GLSL】
- OpenGL光照模型--四种光照效果
- OpenGL光照模型--四种光照效果
- OpenGL光照的计算模型
- OpenGL光照的计算模型
- Android OpenGL ES 光照模型
- Opengl 4种光照模型
- 2013年中国手机打车应用市场研究报告
- android驱动之旅-下载编译Linux Kernel 源代码 for Android 以及android源码(2)
- 浏览器中关于事件的那点事儿
- c++中构造函数
- JAVA String.format 方法使用介绍
- OpenGL 4.0 GLSL 用多个光照模型
- 在启动activity时添加动画效果
- MFC MDI和SDI美化----之客户区美化
- c++继承中的函数覆盖规则
- lucene4.6索引创建和搜索例子
- The controlfile header block returned by the OS has a sequence number that is too old
- angualrJS支持的event
- 做注册的验证,在服务器端处理,客服端ajax异步提交数据
- Debug Assertion Failed! f:\sp\vctools\vc7libs\ship\atlmfc\src\mfc\dlgdata.cpp Line: 42