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 7527415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:05:58+00:00 2026-05-30T04:05:58+00:00

Here is the shader from an example program I’m working with: static const char*

  • 0

Here is the shader from an example program I’m working with:

static const char* pFS = "                                                          \n\
#version 330                                                                        \n\
                                                                                    \n\
const int MAX_POINT_LIGHTS = 2;                                                     \n\
const int MAX_SPOT_LIGHTS = 2;                                                      \n\
                                                                                    \n\
in vec4 LightSpacePos;                                                              \n\
in vec2 TexCoord0;                                                                  \n\
in vec3 Normal0;                                                                    \n\
in vec3 WorldPos0;                                                                  \n\
in vec3 Tangent0;                                                                   \n\
                                                                                    \n\
out vec4 FragColor;                                                                 \n\
                                                                                    \n\
struct BaseLight                                                                    \n\
{                                                                                   \n\
    vec3 Color;                                                                     \n\
    float AmbientIntensity;                                                         \n\
    float DiffuseIntensity;                                                         \n\
};                                                                                  \n\
                                                                                    \n\
struct DirectionalLight                                                             \n\
{                                                                                   \n\
    struct BaseLight Base;                                                          \n\
    vec3 Direction;                                                                 \n\
};                                                                                  \n\
                                                                                    \n\
struct Attenuation                                                                  \n\
{                                                                                   \n\
    float Constant;                                                                 \n\
    float Linear;                                                                   \n\
    float Exp;                                                                      \n\
};                                                                                  \n\
                                                                                    \n\
struct PointLight                                                                           \n\
{                                                                                           \n\
    struct BaseLight Base;                                                                  \n\
    vec3 Position;                                                                          \n\
    Attenuation Atten;                                                                      \n\
};                                                                                          \n\
                                                                                            \n\
struct SpotLight                                                                            \n\
{                                                                                           \n\
    struct PointLight Base;                                                                 \n\
    vec3 Direction;                                                                         \n\
    float Cutoff;                                                                           \n\
};                                                                                          \n\
                                                                                            \n\
uniform int gNumPointLights;                                                                \n\
uniform int gNumSpotLights;                                                                 \n\
uniform DirectionalLight gDirectionalLight;                                                 \n\
uniform PointLight gPointLights[MAX_POINT_LIGHTS];                                          \n\
uniform SpotLight gSpotLights[MAX_SPOT_LIGHTS];                                             \n\
uniform sampler2D gColorMap;                                                                \n\
uniform sampler2D gShadowMap;                                                               \n\
uniform sampler2D gNormalMap;                                                               \n\
uniform vec3 gEyeWorldPos;                                                                  \n\
uniform float gMatSpecularIntensity;                                                        \n\
uniform float gSpecularPower;                                                               \n\
                                                                                            \n\
float CalcShadowFactor(vec4 LightSpacePos)                                                  \n\
{                                                                                           \n\
    vec3 ProjCoords = LightSpacePos.xyz / LightSpacePos.w;                                  \n\
    vec2 UVCoords;                                                                          \n\
    UVCoords.x = 0.5 * ProjCoords.x + 0.5;                                                  \n\
    UVCoords.y = 0.5 * ProjCoords.y + 0.5;                                                  \n\
    float Depth = texture(gShadowMap, UVCoords).x;                                          \n\
    if (Depth <= (ProjCoords.z + 0.005))                                                    \n\
        return 0.5;                                                                         \n\
    else                                                                                    \n\
        return 1.0;                                                                         \n\
}                                                                                           \n\
                                                                                            \n\
vec4 CalcLightInternal(struct BaseLight Light, vec3 LightDirection, vec3 Normal,            \n\
                       float ShadowFactor)                                                  \n\
{                                                                                           \n\
    vec4 AmbientColor = vec4(Light.Color, 1.0f) * Light.AmbientIntensity;                   \n\
    float DiffuseFactor = dot(Normal, -LightDirection);                                     \n\
                                                                                            \n\
    vec4 DiffuseColor  = vec4(0, 0, 0, 0);                                                  \n\
    vec4 SpecularColor = vec4(0, 0, 0, 0);                                                  \n\
                                                                                            \n\
    if (DiffuseFactor > 0) {                                                                \n\
        DiffuseColor = vec4(Light.Color, 1.0f) * Light.DiffuseIntensity * DiffuseFactor;    \n\
                                                                                            \n\
        vec3 VertexToEye = normalize(gEyeWorldPos - WorldPos0);                             \n\
        vec3 LightReflect = normalize(reflect(LightDirection, Normal));                     \n\
        float SpecularFactor = dot(VertexToEye, LightReflect);                              \n\
        SpecularFactor = pow(SpecularFactor, gSpecularPower);                               \n\
        if (SpecularFactor > 0) {                                                           \n\
            SpecularColor = vec4(Light.Color, 1.0f) *                                       \n\
                            gMatSpecularIntensity * SpecularFactor;                         \n\
        }                                                                                   \n\
    }                                                                                       \n\
                                                                                            \n\
    return (AmbientColor + ShadowFactor * (DiffuseColor + SpecularColor));                  \n\
}                                                                                           \n\
                                                                                            \n\
vec4 CalcDirectionalLight(vec3 Normal)                                                      \n\
{                                                                                                \n\
    return CalcLightInternal(gDirectionalLight.Base, gDirectionalLight.Direction, Normal, 1.0);  \n\
}                                                                                                \n\
                                                                                            \n\
vec4 CalcPointLight(struct PointLight l, vec3 Normal, vec4 LightSpacePos)                   \n\
{                                                                                           \n\
    vec3 LightDirection = WorldPos0 - l.Position;                                           \n\
    float Distance = length(LightDirection);                                                \n\
    LightDirection = normalize(LightDirection);                                             \n\
    float ShadowFactor = CalcShadowFactor(LightSpacePos);                                   \n\
                                                                                            \n\
    vec4 Color = CalcLightInternal(l.Base, LightDirection, Normal, ShadowFactor);           \n\
    float Attenuation =  l.Atten.Constant +                                                 \n\
                         l.Atten.Linear * Distance +                                        \n\
                         l.Atten.Exp * Distance * Distance;                                 \n\
                                                                                            \n\
    return Color / Attenuation;                                                             \n\
}                                                                                           \n\
                                                                                            \n\
vec4 CalcSpotLight(struct SpotLight l, vec3 Normal, vec4 LightSpacePos)                     \n\
{                                                                                           \n\
    vec3 LightToPixel = normalize(WorldPos0 - l.Base.Position);                             \n\
    float SpotFactor = dot(LightToPixel, l.Direction);                                      \n\
                                                                                            \n\
    if (SpotFactor > l.Cutoff) {                                                            \n\
        vec4 Color = CalcPointLight(l.Base, Normal, LightSpacePos);                         \n\
        return Color * (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - l.Cutoff));                   \n\
    }                                                                                       \n\
    else {                                                                                  \n\
        return vec4(0,0,0,0);                                                               \n\
    }                                                                                       \n\
}                                                                                           \n\
                                                                                            \n\
vec3 CalcBumpedNormal()                                                                     \n\
{                                                                                           \n\
    vec3 Normal = normalize(Normal0);                                                       \n\
    vec3 Tangent = normalize(Tangent0);                                                     \n\
    Tangent = normalize(Tangent - dot(Tangent, Normal) * Normal);                           \n\
    vec3 Bitangent = cross(Tangent, Normal);                                                \n\
    vec3 BumpMapNormal = texture(gNormalMap, TexCoord0).xyz;                                \n\
    BumpMapNormal = 2.0 * BumpMapNormal - vec3(1.0, 1.0, 1.0);                              \n\
    vec3 NewNormal;                                                                         \n\
    mat3 TBN = mat3(Tangent, Bitangent, Normal);                                            \n\
    NewNormal = TBN * BumpMapNormal;                                                        \n\
    NewNormal = normalize(NewNormal);                                                       \n\
    return NewNormal;                                                                       \n\
}                                                                                           \n\
                                                                                            \n\
void main()                                                                                 \n\
{                                                                                           \n\
    vec3 Normal = CalcBumpedNormal();                                                       \n\
    vec4 TotalLight = CalcDirectionalLight(Normal);                                         \n\
                                                                                            \n\
    for (int i = 0 ; i < gNumPointLights ; i++) {                                           \n\
        TotalLight += CalcPointLight(gPointLights[i], Normal, LightSpacePos);               \n\
    }                                                                                       \n\
                                                                                            \n\
    for (int i = 0 ; i < gNumSpotLights ; i++) {                                            \n\
        TotalLight += CalcSpotLight(gSpotLights[i], Normal, LightSpacePos);                 \n\
    }                                                                                       \n\
                                                                                            \n\
    vec4 SampledColor = texture2D(gColorMap, TexCoord0.xy);                                 \n\
    FragColor = SampledColor * TotalLight;                                                  \n\
}";

GLSL complains that:
Error compiling FS: ‘Fragment shader failed to compile with the following errors:
ERROR: 0:24: error(#132) Syntax error: ‘Base’ parse error
ERROR: error(#273) 1 compilation errors. No code generated’

However, the GLSL standard clearly states:

…it also
creates a variable of that type called variableName. As in C/C++, the
variable name can be omitted. Structs cannot contain variables of
sampler types. They can contain variables of other struct types.
Structs define a named type. But there are limits on the type
qualifiers that can be used with struct types. Uniforms can use struct
types, as well as regular globals, locals, and constant variables.
Structs cannot be used with any other storage qualifiers.

Why doesn’t this compile?

  • 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-05-30T04:05:59+00:00Added an answer on May 30, 2026 at 4:05 am
    struct BaseLight Base;
    

    GLSL is not C. You don’t use the struct keyword like that. BaseLight is a typename, so you just say BaseLight Base. You do it correctly when you create PointLight, so I don’t know why you got it wrong so consistently with your uses of BaseLight.

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

Sidebar

Related Questions

Here is my code, which takes two version identifiers in the form 1, 5,
I'm trying to get MRT working in OpenGL to try out deferred rendering. Here's
I have some problems adding my shader-glsl files from one xcode project to another.
I've created a basic orthographic shader that displays sprites from textures. It works great.
Here's a snippet of a pixel bender shader that I'm using in Flash: parameter
I have converted a Depth Of Field shader from XNA 3.1 to 4.0. The
Running openGL 3.1, the question is simple. From GLSL site, here is how one
ES 2.0 newbie here. I'm currently trying to make some 3D interlaced images from
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form

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.