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,17 +65,13 @@ 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));
|
||||||
|
|
||||||
|
if (l.type == LIGHT_SPOT) {
|
||||||
float angle = dot(l.dir, -lightDir);
|
float angle = dot(l.dir, -lightDir);
|
||||||
if (angle > l.outerCone) {
|
if (angle > l.outerCone) {
|
||||||
float intensity = (angle-l.outerCone)/(l.innerCone-l.outerCone);
|
float intensity = (angle-l.outerCone)/(l.innerCone-l.outerCone);
|
||||||
|
@ -84,6 +80,7 @@ vec3 shading_phong(light_t l) {
|
||||||
attenuation = 0.0;
|
attenuation = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fast-rejection for faraway vertices
|
// fast-rejection for faraway vertices
|
||||||
if (attenuation <= 0.01) {
|
if (attenuation <= 0.01) {
|
||||||
|
|
Loading…
Reference in New Issue