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

  • Home
  • SEARCH
  • 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 9125653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:51:13+00:00 2026-06-17T06:51:13+00:00

Heres my vertex shader code: #version 330 layout(location = 0) in vec3 vertex_position; layout(location

  • 0

Heres my vertex shader code:

#version 330

layout(location = 0) in vec3 vertex_position;
layout(location = 0) in vec3 vertex_normal;

//model space
uniform vec3 toLight;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

smooth out vec3 color;

void main()
{
  gl_Position = projection * view * model * vec4(vertex_position, 1.0f);
  
  vec3 normal = normalize(vertex_normal);
  
  float intensity = dot(normal, toLight);
  intensity = clamp(intensity, 0, 1);
  
  color = vec3(intensity);
}

In this code I am trying to calculate lighting using the tutorial at Learning Modern 3D Graphics Programming site. Which is a great book by the way, however the code here is basically identical to the listed code with a couple of names changed, however through the some experimentation, I have discovered something very peculiar. The segmentation fault occurs on the

color = vec3(intensity);

line, I know that because removing that line causes the program to run normally, (except without lighting of course)

However when I replace the line

float intensity = dot(normal, toLight);

with:

float intensity = 3.14159;

It clamps to 1.0f and everything works fine, the cube is white, same happens if I put a negative number: the number is clamped to zero and the cube is black…

So this is strange, here’s the facts:

  • The segmentation fault disappears when removing the line that sets the output vector to the color requested.
  • The segmentation fault also disappears when removing the calculation of the dot product
  • When the intensity is a constant float, everything works fine.
  • setting the color to anything not involving the intensity works fine.
  • EDIT: found some interesting info, when setting a variable other than the color variable using the intensity variable works fine, for example vec3 temp = vec3(intensity); doesn’t cause a segfault, however setting color to something that is not related to the intensity variable works fine also color = vec3(1.0f); although, if I were to set color to temp it would crash too, this is very strange.

Any suggestions are greatly appreciated. Thanks

Also, I would include my opengl, c++ code, but I don’t think it’s necessary, correct me if I’m wrong.

  • 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-17T06:51:14+00:00Added an answer on June 17, 2026 at 6:51 am

    Oh, god! I made a big mistake, right here:

    layout(location = 0) in vec3 vertex_position;
    layout(location = 0) in vec3 vertex_normal;
    

    notice how vertex_position and vertex_normal have the same location, I didn’t either. Setting the vertex_normal location to 1 fixed everything, sorry I wasted most of your time, but thanks to all of you for suggestions and to Tim who got me to realize that a segfault was occurring with the normal, leading me to the top of the source, thanks all of you just the same… =D

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this shader code (GLSL): #version 420 in vec4 vertex; uniform mat4 modelViewMatrix;
I have two simple shaders (vertex and fragment) Vertex Shader #version 330 core //=============================================
My vertex shader is , uniform Block1{ vec4 offset_x1; vec4 offset_x2;}block1; out float value;
In the vertex shader I define a structure: #version 110 struct LightSourceParameters { vec4
I am implementing a diffuse per-vertex shader from the OpenGL 4.0 Shading Language Cookbook,
I'm writing a simplistic shader manager so I don't have to write repeditive code
In the OpenGL ES 2.0 introduction, found here: http://www.webreference.com/programming/opengl_es/2.html a vertex shader is defined:
I'm making a simple WebGL demo. I have a simple vertex shader that takes
heres what I'm currently using: Rails -v 3.2.3 I'm trying to make a path
Heres my issue. I have a login screen which is shown using PresentModalViewAnimated. Once

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.