2
votes

Is it forbidden to change the value of an in-variable inside a fragment shader? The following code crashes exactly when I try to set a new value to "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;"
"       }"
" ..."

Inside the vec2, the first component is 0.0 or 1.0, the second is some floating point number. If I set up a new variable and initialize it with some arbitrary value inside the second if-statement, there's no error.

1
Try this for inline GLSL.genpfault

1 Answers

5
votes

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.