Basics Coding
Basics Coding

Reputation: 41

GLSL Shader is not compiling

I am working on a game and I am currently writing a shader to reflect light from an object and I keep getting the error message:

ERROR: 0:25: '-' does not operate on 'vec3' and 'vec4'

fragmentShader file:

vec3 unitVectorToCamera = normalize(toCameraVector); 

vec3 lightDirection = -unitLightVector; 

vertexShader file:

toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition;

Version:

#version 400 core

Any help would be greatly appreciated.

Upvotes: 1

Views: 431

Answers (2)

BDL
BDL

Reputation: 22157

toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition;

worldPosition is a vec4, vec4(0.0, 0.0, 0.0, 1.0)).xyz is a vec3. It is not allowed to subtract a vec4 from a vec3.

Upvotes: 0

Reigertje
Reigertje

Reputation: 725

(inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz

Returns a vec3 (x, y, z) - and you try to substract worldPosition, which is of type vec4.

You could change it to:

toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz;

Upvotes: 3

Related Questions