fix emissive surfaces being too dark, #145

This commit is contained in:
Ivan Avdeev 2021-11-17 10:27:58 -08:00
parent f938427771
commit a736b223c9
3 changed files with 22 additions and 13 deletions

View File

@ -594,7 +594,7 @@ static qboolean canSurfaceLightAffectAABB(const model_t *mod, const msurface_t *
return retval;
}
const vk_emissive_surface_t *VK_LightsAddEmissiveSurface( const struct vk_render_geometry_s *geom, const matrix3x4 *transform_row, qboolean static_map ) {
void VK_LightsAddEmissiveSurface( const struct vk_render_geometry_s *geom, const matrix3x4 *transform_row, qboolean static_map ) {
APROF_SCOPE_BEGIN_EARLY(emissive_surface);
const int texture_num = geom->texture; // Animated texture
vk_emissive_surface_t *retval = NULL;
@ -699,7 +699,6 @@ const vk_emissive_surface_t *VK_LightsAddEmissiveSurface( const struct vk_render
fin:
APROF_SCOPE_END(emissive_surface);
return retval;
}
static void addLightIndexToleaf( const mleaf_t *leaf, int index ) {
@ -929,11 +928,10 @@ void VK_LightsLoadMapStaticLights( void ) {
for (int i = 0; i < bmodel->render_model.num_geometries; ++i) {
const vk_render_geometry_t *geom = bmodel->render_model.geometries + i;
if (!VK_LightsAddEmissiveSurface( geom, &xform, true )) {
VK_LightsAddEmissiveSurface( geom, &xform, true );
// TODO how to differentiate between this and non-emissive gEngine.Con_Printf(S_ERROR "Ran out of surface light slots, geom %d of %d\n", i, bmodel->render_model.num_geometries);
}
}
}
// Fix static counts
{
@ -948,6 +946,20 @@ void VK_LightsLoadMapStaticLights( void ) {
}
}
void XVK_GetEmissiveForTexture( vec3_t out, int texture_id ) {
ASSERT(texture_id >= 0);
ASSERT(texture_id < MAX_TEXTURES);
{
vk_emissive_texture_t *const etex = g_lights.map.emissive_textures + texture_id;
if (etex->set) {
VectorCopy(etex->emissive, out);
} else {
VectorSet(out, 0, 0, 0);
}
}
}
void VK_LightsFrameFinalize( void ) {
APROF_SCOPE_BEGIN_EARLY(finalize);
const model_t* const world = gEngine.pfnGetModelByIndex( 1 );

View File

@ -86,6 +86,7 @@ void VK_LightsFrameInit( void );
// b. kusochki now have emissive color, so it probably makes more sense to not store emissive
// separately in emissive surfaces.
struct vk_render_geometry_s;
const vk_emissive_surface_t *VK_LightsAddEmissiveSurface( const struct vk_render_geometry_s *geom, const matrix3x4 *transform_row, qboolean static_map );
void VK_LightsAddEmissiveSurface( const struct vk_render_geometry_s *geom, const matrix3x4 *transform_row, qboolean static_map );
void XVK_GetEmissiveForTexture( vec3_t out, int texture_id );
void VK_LightsFrameFinalize( void );

View File

@ -310,7 +310,6 @@ static void computeConveyorSpeed(const color24 rendercolor, int tex_index, vec2_
void VK_RayFrameAddModel( vk_ray_model_t *model, const vk_render_model_t *render_model, const matrix3x4 *transform_row, const vec4_t color, color24 entcolor) {
qboolean HACK_reflective = false;
qboolean force_emissive = false;
vk_ray_draw_model_t* draw_model = g_ray_model_state.frame.models + g_ray_model_state.frame.num_models;
ASSERT(vk_core.rtx);
@ -346,7 +345,6 @@ void VK_RayFrameAddModel( vk_ray_model_t *model, const vk_render_model_t *render
// Additive blending: C = SRC * alpha + DST
case kRenderGlow:
case kRenderTransAdd:
force_emissive = true;
draw_model->material_mode = MaterialMode_Additive;
break;
@ -361,11 +359,13 @@ void VK_RayFrameAddModel( vk_ray_model_t *model, const vk_render_model_t *render
for (int i = 0; i < render_model->num_geometries; ++i) {
const vk_render_geometry_t *geom = render_model->geometries + i;
const vk_emissive_surface_t *esurf = render_model->static_map ? NULL : VK_LightsAddEmissiveSurface( geom, transform_row, false );
vk_kusok_data_t *kusok = (vk_kusok_data_t*)(g_ray_model_state.kusochki_buffer.mapped) + geom->kusok_index;
const xvk_material_t *const mat = XVK_GetMaterialForTextureIndex( geom->texture );
ASSERT(mat);
if (!render_model->static_map)
VK_LightsAddEmissiveSurface( geom, transform_row, false );
kusok->tex_base_color = mat->base_color;
kusok->tex_roughness = mat->roughness;
kusok->tex_metalness = mat->metalness;
@ -383,11 +383,7 @@ void VK_RayFrameAddModel( vk_ray_model_t *model, const vk_render_model_t *render
Vector4Copy(color, kusok->color);
if (esurf) {
VectorCopy(esurf->emissive, kusok->emissive);
} else if (force_emissive) {
VectorSet(kusok->emissive, 1.f, 1.f, 1.f);
}
XVK_GetEmissiveForTexture( kusok->emissive, geom->texture );
if (geom->material == kXVkMaterialConveyor) {
computeConveyorSpeed( entcolor, geom->texture, kusok->uv_speed );