Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8891057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:38:31+00:00 2026-06-14T22:38:31+00:00

In what appears to be my fragment shader, I have these two errors: 0(47)

  • 0

In what appears to be my fragment shader, I have these two errors:

0(47) : error C7011: implicit cast from "int" to "vec3"
0(55) : error C7011: implicit cast from "int" to "vec3"

Yet, after spending a good 30 minutes or so looking over the functions being used in the shader programs, it looks like I’m doing this properly, and the majority of the vectors in my shaders are vec4 – basically, any rgba calculations. What I’m trying to figure out is why I’m receiving this error…

I’ve checked my vertex shader as well, just to be sure, and I can’t seem to find anything which matches up with that either.

What is the error?

Fragment Shader

#version 330 core

in vec2 UV;

in vec3 Position_worldSpace;
in vec3 Normal_cameraSpace;
in vec3 EyeDirection_cameraSpace;
in vec3 LightDirection_cameraSpace;

out vec4 Color;

uniform sampler2D TextureSampler;
uniform mat4 ViewMatrix;
uniform mat4 ModelMatrix;
uniform vec3 LightPosition_worldSpace;

void main() 
{
    // Light emission properties
    // Make them uniforms for flexibility/customization

    vec4 LightColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);
    float LightPower = 50.0f;

    // Material properties
    vec4 MaterialDiffuseColor  = texture(TextureSampler, UV).rgba;
    vec4 MaterialAmbientColor  = vec4(0.1f, 0.1f, 0.1f, 1.0f) * MaterialDiffuseColor;
    vec4 MaterialSpecularColor = vec4(0.3f, 0.3f, 0.3f, 1.0f);

    float DistanceToLight = length(LightPosition_worldSpace - Position_worldSpace);     

    // Normal of the computed fragment, in camera space

    vec3 normal = normalize(Normal_cameraSpace);

    // Light Direction, from the fragment to the light itself

    vec3 ld = normalize(LightDirection_cameraSpace);

    // Cosine of the angle between the normal and the light direction,
    // clamped above 0
    //  - light is at the vertical of the triangle -> 1
    //  - light is perpendicular to the triangle   -> 0
    //  - light is behind the triangle             -> 0

    float cosTheta = clamp(dot(normal, 1), 0, 1);

    // Eye vector (towards the camera)

    vec3 norm_EyeDir = normalize(EyeDirection_cameraSpace);

    // direction in which the triangle reflects the light

    vec3 reflection = reflect(-1, normal);

    // Cosine of the angle between the Eye vector and
    // the Reflect vector, clamped to 0
    //  - Looking into the reflection -> 1
    //  - Looking elsewhere           -> less than 1

    float cosAlpha = clamp(dot(norm_EyeDir, reflection), 0, 1);

    float DistSquared = DistanceToLight * DistanceToLight;

    Color = 
        // Ambient : simulates indirect lighting
        MaterialAmbientColor + 
        // Diffuse : "color" of the object
        MaterialDiffuseColor * LightColor * LightPower * cosTheta / DistSquared +
        // Specular : reflective highlight, like a mirror
        MaterialSpecularColor * LightColor * LightPower * pow(cosAlpha, 5) / DistSquared;

}

Vertex Shader

#version 330 core

// Input data, which is different for all executions of this shader

layout(location = 0) in vec3 VertexPosition_modelSpace;
layout(location = 1) in vec2 VertexUV;
layout(location = 2) in vec3 VertexNormal_modelSpace;

// Output data ; will be interpolated for each fragment

out vec2 UV;

out vec3 Position_worldSpace;
out vec3 Normal_cameraSpace;
out vec3 EyeDirection_cameraSpace;
out vec3 LightDirection_cameraSpace;

// Values which stay constant for the whole mesh

uniform mat4 MvpMatrix;
uniform mat4 ViewMatrix;
uniform mat4 ModelMatrix;

uniform vec3 LightPosition_worldSpace;

void main()
{
    vec4 vPos = vec4(VertexPosition_modelSpace, 1.0f);

    // Output position of the vertex, in clip space : MvpMatrix * position
    gl_Position = MvpMatrix * vPos;

    // Position of the vertex, in worldSpace : ModelMatrix * position
    Position_worldSpace = (ModelMatrix * vPos).xyz;


    // Vector that goes from the vertex to the camera, in camera space.
    // In camera space, the camera is at the origin (0, 0, 0).

    vec3 VertexPosition_cameraSpace = (ViewMatrix * ModelMatrix * vPos).xyz;

    EyeDirection_cameraSpace = vec3(0.0f, 0.0f, 0.0f) - VertexPosition_cameraSpace;

    // Vector that goes from the vertex to the light, in camera space.
    // M is identity, thus it's ommitted 
    vec3 LightPosition_cameraSpace = (ViewMatrix * vec4(LightPosition_worldSpace, 1.0f)).xyz;
    LightDirection_cameraSpace = LightPosition_cameraSpace + EyeDirection_cameraSpace;

    // Normal of the vertex, in camera space

    // This is only correct if ModelMatrix does not scale the model; use its transpose if doesn't work properly.
    Normal_cameraSpace = (ViewMatrix * ModelMatrix * vec4(VertexNormal_modelSpace, 0.0f)).xyz; 

    // UV of the vertex.

    UV = VertexUV;
}

Update

The two lines I tracked down are as follows:

vec3 reflection = reflect(-1.0f, normal);

float cosTheta = clamp( dot(normal, 1.0f), 0.0f, 1.0f);

What’s weird is before I was passing whole integers in without the .0f suffix, and since I’ve changed that, the messages are now implicit cast from "float" to "vec3", as opposed to "int". Yet, according to the GLSL specification/man pages, both of these functions return GLSL’s genType.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:38:32+00:00Added an answer on June 14, 2026 at 10:38 pm

    I think its

    float cosTheta = clamp(dot(normal, 1), 0, 1);
    

    You can’t dot a vector (normal) with a scalar (1).

    And it looks like there’s another one, also in the Fragment Shader:

    vec3 reflection = reflect(-1, normal);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have in fragment two of my own widgets. These widgets have edit text
So I have this fragment shader, which was working great until I refactored some
I have a problem with memory allocation using malloc. Here is a fragment from
I have a fragment interface with tabs along the bottom which open different fragments
NOTE: This appears to be a limit in the javac program. I have Java
I have this SQL: SELECT count (1) FROM users AS total_drafts WHERE version_replace =
I'm trying to create a wireframe vertex/fragment shader in Unity. It seems possible according
I have a vertex shader in which I do a texture lookup to determine
I'm writing a simplistic shader manager so I don't have to write repeditive code
I would like to partially hide a fragment when a new fragment appears. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.