- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个考虑两个表面的折射着色器。因此,我使用 FBO 来渲染纹理的深度和法线,并使用立方体贴图来表示环境。我需要使用存储在纹理中的法线值从立方体贴图中获取值,以获得背面的折射法线。
只要我不尝试从已从纹理检索值的向量访问立方体贴图,它就可以完美地工作。
这是一个失败的最小片段着色器。颜色仍然是极度的黑色。我确信对纹理 2D 的调用会返回非零值:如果我尝试显示方向中包含的纹理颜色(表示法线),我会得到一个完美的彩色模型。无论我对“方向”向量进行何种操作,它都会失败。
uniform samplerCube cubemap;
uniform sampler2D normalTexture;
uniform vec2 viewportSize;
void main()
{
vec3 direction = texture2D(normalTexture, gl_FragCoord.xy/viewportSize).xyz;
// direction = vec3(1., 0., 0) + direction; // fails as well!!
vec4 color = textureCube(cubemap, direction);
gl_FragColor = color;
}
这里是以颜色显示的向量“方向”的值,只是证明它们不为空! 这是上述着色器的结果(只是茶壶)。
虽然这段代码可以完美运行:
uniform samplerCube cubemap;
uniform vec2 viewportSize;
varying vec3 T1;
void main()
{
vec4 color = textureCube(cubemap, T1);
gl_FragColor = color;
}
我想不出任何原因为什么每当我访问采样器立方体值时我的颜色都会保持黑色!
为了完整起见,尽管我的立方体贴图可以工作,但以下是用于设置它的参数: glGenTextures(1, &mTextureId);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, mTextureId);
// Set parameters
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
除非我在某个地方错过了一些重要的东西,否则我认为这可能是一个驱动程序错误。我没有任何显卡,我使用的是 Intel Core i5 处理器芯片组。
00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09)
知道为什么会发生这种情况,或者您有解决方法吗?
编辑:这是我的着色器类绑定(bind)纹理的方式
4 textures to bind
Bind texture 3 on texture unit unit 0
Bind to shader uniform: 327680
Bind texture 4 on texture unit unit 1
Bind to shader uniform: 262144
Bind texture 5 on texture unit unit 2
Bind to shader uniform: 393216
Bind texture 9 on texture unit unit 3
Bind to shader uniform: 196608
纹理 3 和 4 是深度,5 是法线贴图,9 是立方体贴图。
以及执行绑定(bind)的代码:
void Shader::bindTextures() {
dinf << m_textures.size() << " textures to bind" << endl;
int texture_slot_index = 0;
for (auto it = m_textures.begin(); it != m_textures.end(); it++) {
dinf << "Bind texture " << it->first<< " on texture unit unit "
<< texture_slot_index << std::endl;
glActiveTexture(GL_TEXTURE0 + texture_slot_index);
glBindTexture(GL_TEXTURE_2D, it->first);
// Binds to the shader
dinf << "Bind to shader uniform: " << it->second << endl;
glUniform1i(it->second, texture_slot_index);
texture_slot_index++;
}
// Make sure that the texture unit which is left active is the number 0
glActiveTexture(GL_TEXTURE0);
}
m_textures 是纹理 id 到统一 id 的映射。
最佳答案
您似乎没有为法线贴图和立方体贴图使用单独的纹理单元。一切都默认为纹理单元 0。您需要类似:
uniform sampler2D norm_tex;
uniform samplerCube cube_tex;
在着色器中。使用 (3.2+) 核心配置文件时,纹理查找应仅使用“重载”texture
函数。使用(3.3+)您还可以使用 sampler objects .
生成纹理并将其绑定(bind)到单独的纹理单元:
... generate 'norm_tex' and 'cube_tex' ...
glActiveTexture(GL_TEXTURE0);
... bind 'norm_tex' and set parameters ...
glActiveTexture(GL_TEXTURE1);
... bind 'cube_tex' and set parameters ...
... glUseProgram(prog); ...
glUniform1i(glGetUniformLocation(prog, "norm_map"), 0);
glUniform1i(glGetUniformLocation(prog, "cube_map"), 1);
关于opengl - 在片段着色器中使用textureCube访问环境贴图失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15775948/
我必须在文本区域上绘制哪些选项? 我认识一些所见即所得的编辑器。我不确定他们使用的方法是什么,并且会看看他们以了解,但我知道像 tinymce 这样的事情已经存在了一段时间,所以我猜现在可能有更现代的
我在我的 woo commerce 商店页面中创建了一个子类别排序菜单。我想将链接到我现在所在页面的链接设置为红色。我对 css 没有问题,只是用 js 脚本。我怎样才能让它突出当前?这是我创建的排序
所以我使用 TextWrangler4.5.3 并主要使用 Python 编写脚本。当我编写 Python 时,我经常喜欢发表类似这样的评论:# BEGINS foo 然后是 # ENDS foo 我
我需要你的帮助! 我有一个表格,里面有行(姓名等)现在,当位于该行上的对象具有特定值时,我想为特定的 tableCells 背景着色。但我只得到它来读取这个单元格的值。但我需要阅读对象(在我的代码中称
有人知道在 uikit 中给 uiactionsheet 着色吗? 最佳答案 是的,因为它是一个 UIView(如 kmit 所述),您可以使用以下命令:addSubview,因此您可以添加自己的背景
在 vba 中,我想从工作表中的单元格中读取颜色来为条形图中的特定条形着色。我的问题是我的颜色格式为 4F9F92,但要在 makro 中读取它,我需要使用单元格中的 excel 颜色代码 40762
我正在尝试绘制一个 geom_histogram,其中条形图由渐变着色。 这就是我想要做的: library(ggplot2) set.seed(1) df <- data.frame(id=past
我正在构建一个带有 shiny 的应用程序,并使用与 Shiny gallery ( http://shiny.rstudio.com/gallery/slider-bar-and-slider-ra
在 iOS 6 和 xcode 4 中,我有这个: https://dl.dropboxusercontent.com/u/60718318/photo.PNG使用代码可以轻松创建 [editButt
我正在向我的 iPhone UI 添加自定义按钮,并希望使它们具有 Apple 应用程序中的玻璃外观。我有一个很好的默认玻璃图像,但我不想为我想要的每种色调(红色、绿色、蓝色等)都有一个单独的图像。
我到处寻找但没有找到解决方案。我有图像 1。如何以编程方式使用渐变对它们进行着色以获得图像 2 和 3?以下是这些图像: 我通过 Photoshop 应用到它们的色调是简单的 2 色线性渐变。 我的问
有没有办法告诉 OS X 自动设置 NSToolbarItem 的样式/色调? 我通过 IB/Xcode 添加了一个“图像工具栏项”,并将图标设置为黑色 PDF as described in the
我试图区分列范围图表上的多种类型的数据。问题是我希望能够按多个标准对它们进行分组。 我可以轻松地为不同的列着色,从而解决一个问题,但我希望能够根据我传递到图表的数据,为 xAxis 上的类别(图表是倒
有人在编译模式 Emacs 中添加了对 ansi-color 的支持吗?如果是这样,颜色写入程序必须检查什么属性/属性才能确保其事件终端支持 ANSI 转义着色。 最佳答案 已经有一个函数可以将颜色应
我正在尝试实现 Phong 着色模型,但我不确定如何选择光源。更具体地说,我不明白光源应该是什么样子。它应该是vec3吗?或者也许是我在 Java 代码中定义的矩阵?另外,如果我们假设我希望相机作为光
我有 2 个 dhtmlxSidebars,就像示例中一样 here如何为嵌套背景设置不同的背景颜色?如果我添加CSS .dhxsidebar_side { background-color:
我有一个 JTable,每行都根据最后一列中的值着色。 但是,当我单击标题对行进行排序时,颜色不会跟随行。 我尝试在 JTable 鼠标退出事件上调用我的“colourTable”方法(我知道 Hac
geom_hline 似乎忽略了美观,我错过了什么还是这是一个错误? df session 信息: R version 3.4.4 (2018-03-15) Platform: x86_64-pc-
这个问题已经有答案了: How to draw a BufferedImage with a color tint (1 个回答) 已关闭 8 年前。 如何将通过此处的图标着色为不同的颜色?假设我想拍
我想为除我点击的那个之外的所有 div 着色。在我的代码中它有效,但只有一次。如果我点击另一个 div,它不起作用。 http://jsfiddle.net/6VhK8/353/ id="1
我是一名优秀的程序员,十分优秀!