- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
该应用程序将地形高程数据加载到浮点纹理中。然后在 float 颜色缓冲区上渲染纹理(使用 *GL_ARB_color_buffer_float*)。
第一遍是获取整体纹理(由多个纹理四边形渲染产生)。为此,我禁用颜色钳位,渲染每个四边形,并将( float )帧缓冲区复制到( float )纹理中:此纹理是用于处理地形高程数据的多个 channel 的基础。
使用假颜色渲染 float 纹理数据没有问题:确实,地形高程信息在第一次传递期间被保留(无颜色限制)。
我在计算地形法线时遇到了麻烦。这是片段着色器的截图:
// Required shader language version (compatibility profile)
#version 150 compatibility
//---------------------------------------------------------------------------
// SYSTEM INPUTS/OUTPUT
//---------------------------------------------------------------------------
// Fragment texture coordinate (in)
in vec4 gl_TexCoord[];
// Fragment color (out)
vec4 gl_FragColor;
// DTED elevation data as texture.
// Value fetched by the texture if the altitude of the terrain, in meters.
uniform sampler2D rdr_ElevationData;
// Obtain fragment elevation
float GetFragmentElevation(const vec2 texcoord)
{
// This is OK! Tested with false colors
return (texture(rdr_ElevationData, gl_TexCoord[0].st).r);
}
vec3 GetFragmentNormal(const vec2 texcoord, const float sOffset, const float tOffset)
{
const vec2
texcoordN = texcoord + vec2( 0.0, +tOffset),
texcoordNE = texcoord + vec2(+sOffset, +tOffset),
texcoordE = texcoord + vec2(+sOffset, 0.0),
texcoordSE = texcoord + vec2(+sOffset, -tOffset),
texcoordS = texcoord + vec2( 0.0, -tOffset),
texcoordSW = texcoord + vec2(-sOffset, -tOffset),
texcoordW = texcoord + vec2(-sOffset, 0.0),
texcoordNW = texcoord + vec2(-sOffset, +tOffset);
float TerrainAroundHeights[9];
// Ensuring clamped texture coordinates
clamp(texcoordN , 0.0, 1.0);
clamp(texcoordNE, 0.0, 1.0);
clamp(texcoordE , 0.0, 1.0);
clamp(texcoordSE, 0.0, 1.0);
clamp(texcoordS , 0.0, 1.0);
clamp(texcoordSW, 0.0, 1.0);
clamp(texcoordW , 0.0, 1.0);
clamp(texcoordNW, 0.0, 1.0);
// Fetch terrain heights around the fragment
TerrainAroundHeights[0] = GetFragmentElevation(texcoord);
TerrainAroundHeights[1] = GetFragmentElevation(texcoordN);
TerrainAroundHeights[2] = GetFragmentElevation(texcoordNE);
TerrainAroundHeights[3] = GetFragmentElevation(texcoordE);
TerrainAroundHeights[4] = GetFragmentElevation(texcoordSE);
TerrainAroundHeights[5] = GetFragmentElevation(texcoordS);
TerrainAroundHeights[6] = GetFragmentElevation(texcoordSW);
TerrainAroundHeights[7] = GetFragmentElevation(texcoordW);
TerrainAroundHeights[8] = GetFragmentElevation(texcoordNW);
const float NormalLength = 0.001;
vec3 v0 = vec3(0.0, 0.0, 0.0), v1 = vec3(0.0, NormalLength, 0.0), v2 = vec3(NormalLength, 0.0, 0.0);
// Compute averaged heights for each fragment corner
/*v0.z = (TerrainAroundHeights[0] + TerrainAroundHeights[7] + TerrainAroundHeights[6] + TerrainAroundHeights[5]) / 4.0;
v1.z = (TerrainAroundHeights[0] + TerrainAroundHeights[1] + TerrainAroundHeights[8] + TerrainAroundHeights[7]) / 4.0;
v2.z = (TerrainAroundHeights[0] + TerrainAroundHeights[5] + TerrainAroundHeights[4] + TerrainAroundHeights[3]) / 4.0;*/
// MY TESTS... unable to understand what's going on
if (TerrainAroundHeights[0] < (TerrainAroundHeights[5]))
v0.z = 1.0;
return (v0);
// Compute terrain normal
return (normalize(cross(v2 - v0, v1 - v0)));
}
void main()
{
ivec2 rdr_ElevationData_Size = textureSize(rdr_ElevationData, 0); // Texture size, in textel
vec3 frag_Normal; // Fragment normal
float rdr_ElevationData_S_CoordStep = 1.0 / /*rdr_ElevationData_Size[0]*/ 672.0 /* Tried but not working... * 4.0 */;
float rdr_ElevationData_T_CoordStep = 1.0 / /*rdr_ElevationData_Size[1]*/ 672.0 /* Tried but not working... * 4.0 */;
// Determine fragment normal
frag_Normal = GetFragmentNormal(gl_TexCoord[0].st, rdr_ElevationData_S_CoordStep, rdr_ElevationData_T_CoordStep);
// Test purpose... (always 0.0!!!)
gl_FragColor = vec4(frag_Normal.z, 0.0, 0.0, 1.0);
}
您可以在GetFragmentNormal中看到,我尝试从邻居文本中获取高程数据,但是TerrainAroundHeights的值似乎总是相等!!!
我错过了什么大事吗?有没有更好的方法来获取邻居文本?
最佳答案
您在 GetFragmentNormal 中计算偏移 texcoord,然后将其传递给 GetFragmentElevation,但随后您不在纹理查找中使用它 - 您在添加偏移之前使用原始 texcoord。
float GetFragmentElevation(const vec2 texcoord)
{
// This is OK! Tested with false colors
return (texture(rdr_ElevationData, gl_TexCoord[0].st).r);
}
因此,毫不奇怪,无论偏移量如何,您都会获得相同的高度。将 gl_TexCoord[0]
更改为 texcoord
。
关于opengl - 在片段着色器中根据地形高程数据计算法线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6255562/
我必须在文本区域上绘制哪些选项? 我认识一些所见即所得的编辑器。我不确定他们使用的方法是什么,并且会看看他们以了解,但我知道像 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
我是一名优秀的程序员,十分优秀!