Error C7565: assignment to varying in

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;

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;

It works.

Thank you very much.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.