opengl - 如何用具有纹理的对象绘制没有纹理的对象 OPENGL
问题描述
我有几个没有纹理坐标 UV 的对象传递到片段着色器,而我只有两个其他对象的纹理坐标 UV 传递到片段着色器。没有纹理的物体仍然可见,但颜色暗淡。但在插入光方程后,它会变成黑色且不可见。我如何在不改变其原始颜色并保持光照方程的情况下绘制非纹理化对象(我已经为它们创建了颜色数组并将它们传递给顶点着色器)。我已经尝试过了,但我的片段着色器无法编译。
#version 330
in vec3 fragmentColor;
in vec3 fragmentNormal;
in vec2 UV;
in vec4 Position;
uniform vec4 lighteye;
uniform float intensityh;
uniform float intensityd;
uniform float objectd;
uniform vec4 worldCoord;
// 纹理均匀采样器 2D texture_Colors 的数据;
if(UV.x >= 0.0)
color = intensityh * texture2D( texture_Colors, UV ).rgb * diffuse + (intensityd * texture2D( texture_Colors, UV ).rgb * something) ;
else
color = vec4(fragmentColor,1.0);
解决方案
据我了解,您可以执行以下操作:
color r = intensityh * texture2D( texture_Colours, worldCoord.xy).rgb * diffuse+( intensityd* texture2D (texture_Colours, worldCoord.xy).rgb * something
这应该根据对象在 3D 空间中的位置来纹理化您的对象。但是,不要忘记通过 CPU 代码为每个纹理启用纹理重复,如下所示:
glTexParameterf(GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_WRAP_T, GL_REPEAT);
推荐阅读
- python - TensorFlow:整合神经网络的输出
- .net - 尽早刷新视图组件
- jquery - asp.net mvc angular jquery 表不工作
- sql - 如何识别 SQL Server 表中的 SCD 类型 1 和类型 2 列
- excel - 如果找到复制到 vba 宏中的另一个文件夹,则使用文件名在文件夹和子文件夹中搜索文件
- python - 使用“while”时删除最后一个字符
- json - 从角度材料表生成json数组对象或json对象
- c# - 为什么 EF6 更新了错误的数据库?
- php - 如何使用 foreach 循环更新 MYSQL 中的数据
- ruby-on-rails - 为什么在安装 rmagick (3.0.0) 时出现错误