GLSL error: illegal non-ASCII character - opengl

I am writing a vertex shader for openGl. This is my code:
#version 150
in vec4 vPosition;
in vec3 vNormal;
out vec3 fN;
out vec3 fE;
out vec3 fL;
uniform mat4 model_matrix;
uniform mat4 view_matrix;
uniform mat4 proj_matrix;
uniform vec4 lightPos;
void main()
{
vec3 pos = (view_matrix * model_matrix * vPosition).xyz;
vec3 lightPosInCam = (view_matrix * lightPos).xyz;
fN = normalize(view_matrix * model_matrix * vec4(vNormal,1.0)).xyz;
fE = normalize(vec3(0,0,0) - pos);
fL = normalize(lightPosInCam.xyz - pos);
gl_Position = proj_matrix*view_matrix*model_matrix*vPosition;
}
However, when I run my program, it seems like the error says there is some nonASCII character after my }, because in console prints:
#version 150
in vec4 vPosition;
in vec3 vNormal;
out vec3 fN;
out vec3 fE;
out vec3 fL;
uniform mat4 model_matrix;
uniform mat4 view_matrix;
uniform mat4 proj_matrix;
uniform vec4 lightPos;
void main()
{
vec3 pos = (view_matrix * model_matrix * vPosition).xyz;
vec3 lightPosInCam = (view_matrix * lightPos).xyz;
fN = normalize(view_matrix * model_matrix * vec4(vNormal,1.0)).xyz;
fE = normalize(vec3(0,0,0) - pos);
fL = normalize(lightPosInCam.xyz - pos);
gl_Position = proj_matrix*view_matrix*model_matrix*vPosition;
}═════════════════════════
Printed Shader Read Status
vshader_hw5.glsl failed to compile:
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)
ERROR: 0:26: '' : illegal non-ASCII character (0xcd)

However, when I run my program, it seems like the error says there is some nonASCII character after my }, because in console prints:
This is a typical error encountered when the shader source strings to OpenGL are not properly terminated with a zero byte (NUL) and/or if the the buffer length(s) passed do not match the length of the source string.
Solution: If you're not passing the lengths explicitly (i.e. pass NULL for the lengths parameter) make sure the source strings are properly zero terminated. Otherwise make sure, that the lengths properly match the lengths of the source string buffers.

Related

wrong operand types - no operation '*' exists that takes a left-hand operand of type 'uniform lowp samplerCube'

I wanna add dir and amb light to the cubeMap sampler.
Any sugestion?
FS
// shader for opengles native 'uniform samplerCube' CubeMap canvas2d textures.
precision mediump float;
precision highp float;
varying vec3 vLightWeighting;
uniform float textureSamplerAmount[1];
int MixOperandString = ${mixOperand};
// The CubeMap texture.
uniform samplerCube u_texture;
varying vec3 v_normal;
varying vec3 v_normal_cubemap;
void main(void) {
gl_FragColor = textureCube(u_texture * vLightWeighting, v_normal_cubemap);
}
VS
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
varying vec3 v_normal;
varying vec3 v_normal_cubemap;
// lights
uniform vec3 uAmbientColor;
uniform vec3 uLightingDirection;
uniform vec3 uDirectionalColor;
uniform bool uUseLighting;
varying vec2 vTextureCoord;
varying vec3 vLightWeighting;
void main(void) {
v_normal = mat3(uNMatrix) * aVertexNormal;
v_normal_cubemap = normalize(aVertexPosition.xyz);
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
// lights
// vTextureCoord = aTextureCoord;
if (!uUseLighting) {
vLightWeighting = vec3(1.0, 1.0, 1.0);
}
else {
vec3 transformedNormal = uNMatrix * aVertexNormal;
float directionalLightWeighting = max(dot(transformedNormal, uLightingDirection), 0.0);
vLightWeighting = uAmbientColor + uDirectionalColor * directionalLightWeighting;
}
Error log:
app.js:833 Shader Program compile failed:ERROR: 0:16: '' : Invalid
operation for variables with an opaque type ERROR: 0:16: '' : wrong
operand types - no operation '*' exists that takes a left-hand operand
of type 'uniform lowp samplerCube' and a right operand of type
'varying highp 3-component vector of float' (or there is no acceptable
conversion)
u_texture is a sampler. You can't multiply a sampler by anything. However, you can multiply the color returned by the texture lookup with vLightWeighting:
void main(void) {
vec4 lightMapColor = textureCube(u_texture, v_normal_cubemap);
gl_FragColor = vec4(lightMapColor.rgb * vLightWeighting, lightMapColor.a);
}

GLSL vertex shader for texture display not compiling

I've got a vertex shader that doesn't want to compile, but I see absolutely no reason for the error it is giving. It's failing with the following error:
ERROR: D:\local\Temp\f46179fe-8934-4135-820a-bed1e54b98bf.tmp:22: 'texture2D' : no matching overloaded function found
ERROR: D:\local\Temp\f46179fe-8934-4135-820a-bed1e54b98bf.tmp:22: 'assign' : cannot convert from ' const float' to ' smooth out 4-component vector of float'
ERROR: D:\local\Temp\f46179fe-8934-4135-820a-bed1e54b98bf.tmp:22: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
SPIR-V is not generated for failed compile or link
Here is the code:
#version 460
//Passes variables from uniforms to frag_hud shader
layout(location = 0) in vec3 pos;
layout(location = 1) in vec2 vert_tex_coord;
uniform float vert_col_dist;
uniform sampler2D vert_hud01;
uniform sampler2D vert_hud02;
uniform sampler2D vert_hud03;
out vec2 tex_coord;
out float col_dist;
out vec4 hud01;
out vec4 hud02;
out vec4 hud03;
void main() {
gl_Position = vec4(pos, 1.0);
tex_coord = vec2(vert_tex_coord.x, vert_tex_coord.y);
col_dist = vert_col_dist;
hud01 = texture2D(vert_hud01, vert_tex_coord);
hud02 = texture2D(vert_hud02, vert_tex_coord);
hud03 = texture2D(vert_hud03, vert_tex_coord);
}
Figured it out. Needed to use texture() instead of texture2D().

GLSL Error when trying to pass data to geometry shader

I have a vertex shader that takes in position, texture coordinates, normals and some uniforms:
#version 330 core
layout(location = 0) in vec4 position;
layout(location = 1) in vec2 texCoord;
layout(location = 2) in vec3 normal;
//MVP
uniform mat4 u_Model;
uniform mat4 u_View;
uniform mat4 u_Proj;
//Lighting
uniform mat4 u_InvTranspModel;
uniform mat4 u_LightMVP;
out DATA
{
vec2 v_TexCoord;
vec3 v_Normal;
vec3 v_FragPos;
vec4 v_LightSpacePos;
mat4 v_Proj;
} data_out[];
void main()
{
gl_Position = u_Model * position;
data_out.v_TexCoord = texCoord;
data_out.v_Normal = mat3(u_InvTranspModel) * normal;
data_out.v_Proj = u_Proj * u_View * u_Model;
//Light
data_out.v_FragPos = vec3(u_Model*position);
data_out.v_LightSpacePos = u_LightMVP * position;
}
I'm passing into my geometry shader:
#version 330 core
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
in DATA
{
vec2 v_TexCoord;
vec3 v_Normal;
vec3 v_FragPos;
vec4 v_LightSpacePos;
mat4 v_Proj;
} data_in[];
out vec2 g_TexCoord;
out vec3 g_Normal;
out vec3 g_FragPos;
out vec4 g_LightSpacePos;
void main()
{
gl_Position = data_in[0].v_Proj * gl_in[0].gl_Position;
g_Normal = data_in[0].v_Normal;
g_FragPos = data_in[0].v_FragPos;
g_TexCoord = data_in[0].v_TexCoord;
g_LightSpacePos = data_in[0].v_LightSpacePos;
EmitVertex();
gl_Position = data_in[1].v_Proj * gl_in[1].gl_Position;
g_Normal = data_in[1].v_Normal;
g_FragPos = data_in[1].v_FragPos;
g_TexCoord = data_in[1].v_TexCoord;
g_LightSpacePos = data_in[1].v_LightSpacePos;
EmitVertex();
gl_Position = data_in[2].v_Proj * gl_in[2].gl_Position;
g_Normal = data_in[2].v_Normal;
g_FragPos = data_in[2].v_FragPos;
g_TexCoord = data_in[2].v_TexCoord;
g_LightSpacePos = data_in[2].v_LightSpacePos;
EmitVertex();
EndPrimitive();
}
However I get the errors:
ERROR: 0:28: '.' : dot operator to an array only takes length()
ERROR: 0:28: 'assign' : cannot convert from 'attribute 2-component vector of highp float' to 'varying unknown-sized array of highp block'
ERROR: 0:29: '.' : dot operator to an array only takes length()
ERROR: 0:29: 'assign' : cannot convert from '3-component vector of highp float' to 'varying unknown-sized array of highp block'
................ Etc
I get these errors for every variable in the vertex shader that is passed to the geometry shader.
This shader works when its in a form without geometry shader, and should be setup currently to do nothing, so what have I done wrong?
The output of the vertex shader is not an array, even if the next stage is a Geometry shader. The Vertex shader processes a single vertex, and therefore the outputs are always single values related to that vertex. The geometry shader's input interface is an array because the geometry shader takes a primitive (multiple vertices) as input rather than a single vertex. Remove [] in the vertex shader:
out DATA
{
vec2 v_TexCoord;
vec3 v_Normal;
vec3 v_FragPos;
vec4 v_LightSpacePos;
mat4 v_Proj;
} data_out; // <--- remove []

GLSL Vertex Shader Compilation Error

This is my following Error which is ERROR #160 in GLSL.
#version 330 core
layout (location = 0) in vec3 position;
out vec4 pos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(position, 1.0f);
pos = position;
}
and this is the error which was created when trying to compile this GLSL program.
ERROR: Vertex Shader Program Compilation Failed! Vertex shader failed to compile with the following errors:
ERROR: 0:13: error(#160) Cannot convert from: "in highp 3-component vector of vec3" to: "default out highp 4-component vector of vec4"
ERROR: error(#273) 1 compilation errors. No code generated
I have no knowledge on debugging GLSL so if there is anyone who can help it would e much appreciated.
Well, your error is pretty clear. Since you assign position to pos, and pos is a vec4 while position is a vec3, and there is no implicit conversion for this, the compiler complains. To fix this, simply create a vec4 from you position, e.g.
pos = vec4(position, 1.0f);
However, you should think about why you would need a vec4 for your position down the pipeline, or whether having pos be a vec3 would be sufficient or not.

Loading a Shader file string into glShaderSource and failing somehow

Hi im getting this very weird error with loading the shader.txt file's string into glShaderSource and the compiling it with glCompileShader.
ERROR: 0:14: error(#89) Syntax error ERROR___EOF_IN_COMMENT and
ERROR: 0:14: error(#131) Syntax error: pre-mature EOF parse error
this is the shader file string im checking with glGetShaderiv:
"#version 330 core\n\nlayout (location = 0) in vec4 position;\n\nuniform mat4 pr_matrix;\nuniform mat4 vw_matrix = mat4(1.0);\nuniform mat4 ml_matrix = mat4(1.0);\n\nvoid main()\n{\n\ngl_Position = /*pr_matrix *
notice that it couldn't copy the whole thing, But i assure you its all correctly writed. What to do?
You have an unterminated comment. Your string should look like this:
"#version 330 core\n\nlayout (location = 0) in vec4 position;\n\nuniform mat4 pr_matrix;\nuniform mat4 vw_matrix = mat4(1.0);\nuniform mat4 ml_matrix = mat4(1.0);\n\nvoid main()\n{\n\ngl_Position = pr_matrix; }"