Search code examples
openglglsl

Defining diffuse color as an array


#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 vertNormal;
layout(location = 1) in vec3 eyeDir;
layout(location = 2) in vec3 lightDir[2];

layout(location = 0) out vec4 fragColor;

void main() {
    vec4 ks = vec4(0.3 , 0.3 , 0.3 , 0.0);
    vec4 kd = vec4(0.4 , 0.0 , 0.0 , 0.0);
    vec4 kd2 = vec4(0.0 , 0.0 , 0.4 , 0.0);
    vec4 ka= 0.1 * kd;
    float diff = max(dot(lightDir[0] , vertNormal) , 0.0);
    float diff2 = max(dot(lightDir[1] , vertNormal) , 0.0);
    vec3 reflection = reflect(-lightDir[0] , vertNormal);
    vec3 reflection2 = reflect(-lightDir[1] , vertNormal);
    float spec = max(dot(eyeDir , reflection), 0.0);
    float spec2 = max(dot(eyeDir , reflection2), 0.0);
    spec = pow(spec , 14.0);
    spec2 = pow(spec , 14.0);
    fragColor = ka + (kd * diff) + (kd2 * diff2) + (ks * spec) + (ks * spec2);
}

Hello guys, so I was wondering, how can I make a diffuse color(float diff, diff2) as an array, so I can loop through it in future. I am a beginner, so I think the answer is very simple, I'd appreciate any help. Thanks a lot.


Solution

  • You can create a array like this.

    float a[2] = float[2](diff, diff2);