render: optimise lighting
parent
9731ca611c
commit
4cd8f820de
|
@ -193,8 +193,8 @@ void ModelRender( Model *G, const mat44 _worldRootMatrix ) {
|
||||||
for( int i = 0, end = array_count(G->meshes); i < end; i++ ) {
|
for( int i = 0, end = array_count(G->meshes); i < end; i++ ) {
|
||||||
const Mesh *mesh = &G->meshes[ i ];
|
const Mesh *mesh = &G->meshes[ i ];
|
||||||
// Postpone rendering transparent meshes
|
// Postpone rendering transparent meshes
|
||||||
if(mesh->transparent != bTransparentPass)
|
// if(mesh->transparent != bTransparentPass)
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
const pbr_material_t *material = &G->materials[ mesh->material_idx ];
|
const pbr_material_t *material = &G->materials[ mesh->material_idx ];
|
||||||
shader_colormap( "map_diffuse", material->diffuse );
|
shader_colormap( "map_diffuse", material->diffuse );
|
||||||
|
|
|
@ -65,23 +65,20 @@ vec3 shading_phong(light_t l) {
|
||||||
|
|
||||||
if (l.type == LIGHT_DIRECTIONAL) {
|
if (l.type == LIGHT_DIRECTIONAL) {
|
||||||
lightDir = normalize(-l.dir);
|
lightDir = normalize(-l.dir);
|
||||||
} else if (l.type == LIGHT_POINT) {
|
} else if (l.type == LIGHT_POINT || l.type == LIGHT_SPOT) {
|
||||||
vec3 toLight = l.pos - v_position_ws;
|
|
||||||
lightDir = normalize(toLight);
|
|
||||||
float distance = length(toLight);
|
|
||||||
attenuation = 1.0 / (l.constant + l.linear * distance + l.quadratic * (distance * distance));
|
|
||||||
} else if (l.type == LIGHT_SPOT) {
|
|
||||||
vec3 toLight = l.pos - v_position_ws;
|
vec3 toLight = l.pos - v_position_ws;
|
||||||
lightDir = normalize(toLight);
|
lightDir = normalize(toLight);
|
||||||
float distance = length(toLight);
|
float distance = length(toLight);
|
||||||
attenuation = 1.0 / (l.constant + l.linear * distance + l.quadratic * (distance * distance));
|
attenuation = 1.0 / (l.constant + l.linear * distance + l.quadratic * (distance * distance));
|
||||||
|
|
||||||
float angle = dot(l.dir, -lightDir);
|
if (l.type == LIGHT_SPOT) {
|
||||||
if (angle > l.outerCone) {
|
float angle = dot(l.dir, -lightDir);
|
||||||
float intensity = (angle-l.outerCone)/(l.innerCone-l.outerCone);
|
if (angle > l.outerCone) {
|
||||||
attenuation *= clamp(intensity, 0.0, 1.0);
|
float intensity = (angle-l.outerCone)/(l.innerCone-l.outerCone);
|
||||||
} else {
|
attenuation *= clamp(intensity, 0.0, 1.0);
|
||||||
attenuation = 0.0;
|
} else {
|
||||||
|
attenuation = 0.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue