Skip to content

Instantly share code, notes, and snippets.

@kettle11
Created August 21, 2022 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kettle11/9fe169f7cbf2411b1c861b704931b9f3 to your computer and use it in GitHub Desktop.
Save kettle11/9fe169f7cbf2411b1c861b704931b9f3 to your computer and use it in GitHub Desktop.
#VERTEX
#version 300 es
precision mediump float;
in vec3 a_position;
void main()
{
gl_Position = vec4(a_position, 1.0);
}
#FRAGMENT
#version 300 es
precision mediump float;
struct LightInfo {
vec3 position;
vec3 inverse_direction;
vec3 color_and_intensity;
lowp int mode;
};
// NOTE: IF THIS UNIFORM IS REDUCED TO 'p_lights[10]' PERFORMANCE RETURNS TO 60 FPS
uniform LightInfo p_lights[100];
precision mediump float;
out vec4 color_out;
vec3 BRDF(LightInfo light) {
vec3 l;
float attenuation;
// NOTE: IF THIS IS BRANCH IS REMOVED PERFORMANCE RETURNS TO 60 FPS
if (light.mode == 0) {
l = light.inverse_direction;
attenuation = 1.0;
} else {
vec3 diff = light.position;
float distance = length(diff);
l = diff / distance;
attenuation = 1.0 / (distance * distance);
};
// apply lighting...
return l * light.color_and_intensity;
}
void main()
{
color_out = vec4(0, 0, 0, 1);
// NOTE: IF THIS IS BRANCH IS CHANGED TO 'i < 9' PERFORMANCE RETURNS TO 60 FPS
for (int i = 0; i < 10; i++) {
color_out.rgb += BRDF(p_lights[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment