Created
August 21, 2022 20:22
-
-
Save kettle11/9fe169f7cbf2411b1c861b704931b9f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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