opengl - 更改片段着色器内的变量

标签 opengl shader

是否禁止更改片段着色器内不变量的值?当我尝试为“doseValue”设置新值时,以下代码崩溃了:

const GLchar *point_fragment_shader =
"#version 420\n"
""
"/* Per Fragment Input Attributes */"
"in float doseValue;"
"in float alphaValue;"
"in vec2  displayUncertaintyByChangedColor;"
""
"/* Uniform Attributes */"
"uniform float minDisplayDoseValue;"
"uniform int   pointVisualizationMode;"
""
"/* Per Fragment Output Values */"
"out vec4 out_color;"
""
"void main()"
"{"
"   "
"   /* Discard all Points whose dose value is below the minimum */"
"   if(doseValue < minDisplayDoseValue)"
"   {"
"       discard;"
"   }"
"   else"
"   {"
"       if(displayUncertaintyByChangedColor.x == 1.0)"
"       {"
"           doseValue = 500.0;"
"       }"
" ..."

在 vec2 内部,第一个分量是 0.0 或 1.0,第二个分量是某个 float 。如果我设置一个新变量并在第二个 if 语句中使用某个任意值对其进行初始化,则不会出现错误。

最佳答案

GLSL 4.20 spec, Page 38, Section 4.3.4: Input Variables :

Shader input variables are declared with the storage qualifier in. They form the input interface between previous stages of the OpenGL pipeline and the declaring shader. Input variables must be declared at global scope. Values from the previous pipeline stage are copied into input variables at the beginning of shader execution. Variables declared as inputs cannot be written to during shader execution.

关于opengl - 更改片段着色器内的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14629191/

相关文章:

c++ - 为什么我们必须在渲染过程中清除 OpenGL 中的深度缓冲区?

c - glOrtho(-1, 1, -1, 1, -1, 1) 完成了什么?

opengl - 在 OpenGL 中设置 mat4

math - 将深度纹理样本转换为距离

c++ - 如何使用粒子和更深的对象处理 OpenGL 加法混合和深度测试

floating-point - 您如何处理 GLSL 中增加浮点值的小数精度?

c++ - 在图形应用程序中,为什么着色器会在运行时加载到应用程序中?

c++ - OpenGL 什么都不会显示

glsl - 如何在 WebGL 中创建合适的圆角矩形?

opengl - 使用立方体贴图(OpenGL/GLSL)的点光是否可以实现软阴影?