PDA

View Full Version : error C7565: assignment to varying in ...



shapeare
09-19-2011, 01:42 AM
my fragment shader is as simple as:



#version 130

out vec4 oColor;

uniform sampler2D depthTexture;

smooth in vec4 oPosition;
smooth in vec4 texPosition;

void main(void)
{
texPosition.x /= texPosition.w;
texPosition.y /= texPosition.w;
texPosition.z /= texPosition.w;
float depth = texture(depthTexture, texPosition.xy).r;
float dis = texPosition.z - depth;

if(dis < 0.0001)
oColor = vec4(0.01, 0.01, 0.01, 0.0);
else if (dis <0.00015)
oColor = vec4( 0, 0.01 , 0.01, 0);
else
oColor = vec4(0, 0, 0.01, 0);
}

when I compile, the compiler said:
error C7565: assignment to varying in texPosition
three times.

I cannot find out the problem with the three lines above:


texPosition.x /= texPosition.w;
texPosition.y /= texPosition.w;
texPosition.z /= texPosition.w;

ZbuffeR
09-19-2011, 01:50 AM
Well this message seem quite clear to me, "in" varyings are read-only, and you try to write to it.

Something like that should work :


smooth in vec4 texPosition;

void main(void)
{
vec4 newTexPosition = texPosition / texPosition.w;
float depth = texture(depthTexture, newTexPosition.xy).r;
float dis = newTexPosition.z - depth;

shapeare
09-19-2011, 04:49 AM
It works.

Thank you very much.