vk: add patchable smoothing threshold
Automatically smooth normals between surfaces with normals less than 45 degrees off. Can be adjusted from map.bsp.patch file like this (e.g. to 50 degrees): ``` { "_xvk_smoothing_threshold" "50" } ```
This commit is contained in:
parent
a9dcf94f1b
commit
0856e9e70d
|
@ -41,6 +41,7 @@ const int INDIRECT_SCALE = 2;
|
|||
//#define DEBUG_TEXTURE normals_gs
|
||||
//#define DEBUG_TEXTURE emissive
|
||||
//#define DEBUG_TEXTURE light_point_diffuse
|
||||
//#define DEBUG_NORMAL
|
||||
|
||||
// Blatantly copypasted from https://www.shadertoy.com/view/XsGfWV
|
||||
vec3 aces_tonemap(vec3 color){
|
||||
|
@ -197,7 +198,7 @@ void main() {
|
|||
//imageStore(out_dest, pix, vec4(fract(imageLoad(position_t, pix).rgb/10.), 0.)); return;
|
||||
//imageStore(out_dest, pix, vec4(fract(imageLoad(geometry_prev_position, pix).rgb/50.), 0.)); return;
|
||||
|
||||
#if 0
|
||||
#if defined(DEBUG_NORMAL)
|
||||
vec3 geometry_normal, shading_normal;
|
||||
readNormals(pix, geometry_normal, shading_normal);
|
||||
//imageStore(out_dest, pix, vec4(.5 + geometry_normal * .5, 0.)); return;
|
||||
|
|
|
@ -807,16 +807,10 @@ static qboolean shouldSmoothLinkSurfaces(const model_t* mod, int surf1, int surf
|
|||
getSurfaceNormal(mod->surfaces + surf2, n2);
|
||||
|
||||
// TODO patch filtering
|
||||
const float threshold = .7f;
|
||||
return DotProduct(n1, n2) > threshold;
|
||||
const float dot = DotProduct(n1, n2);
|
||||
DEBUG("Smoothing: dot(%d, %d) = %f (t=%f)", surf1, surf2, dot, g_map_entities.smoothing_threshold);
|
||||
|
||||
/*
|
||||
if (
|
||||
((cedge->surfs[0] == 743 || cedge->surfs[1] == 743) &&
|
||||
(cedge->surfs[0] == 741 || cedge->surfs[1] == 741)) ||
|
||||
((cedge->surfs[0] == 367 || cedge->surfs[1] == 367) &&
|
||||
(cedge->surfs[0] == 404 || cedge->surfs[1] == 404))) {
|
||||
*/
|
||||
return dot >= g_map_entities.smoothing_threshold;
|
||||
}
|
||||
|
||||
static int lvFindValue(const linked_value_t *li, int count, int needle) {
|
||||
|
|
|
@ -570,6 +570,8 @@ static void parseEntities( char *string, qboolean is_patch ) {
|
|||
addPatchSurface( &values, have_fields );
|
||||
} else if (have_fields & Field__xvk_ent_id) {
|
||||
patchEntity( &values, have_fields );
|
||||
} else if (have_fields & Field__xvk_smoothing_threshold) {
|
||||
g_map_entities.smoothing_threshold = cosf(DEG2RAD(values._xvk_smoothing_threshold));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -676,6 +678,7 @@ void XVK_ParseMapEntities( void ) {
|
|||
g_map_entities.single_environment_index = NoEnvironmentLights;
|
||||
g_map_entities.entity_count = 0;
|
||||
g_map_entities.func_walls_count = 0;
|
||||
g_map_entities.smoothing_threshold = cosf(DEG2RAD(45.f));
|
||||
|
||||
parseEntities( map->entities, false );
|
||||
orientSpotlights();
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
X(19, vec2_t, _xvk_tex_offset, Vec2) \
|
||||
X(20, vec2_t, _xvk_tex_scale, Vec2) \
|
||||
X(21, string, model, String) \
|
||||
X(22, float, _xvk_smoothing_threshold, Float) \
|
||||
|
||||
/* NOTE: not used
|
||||
X(22, int, rendermode, Int) \
|
||||
|
@ -128,6 +129,8 @@ typedef struct {
|
|||
// TODO find out how to read this from the engine, or make its size dynamic
|
||||
//#define MAX_MAP_ENTITIES 2048
|
||||
xvk_mapent_ref_t refs[MAX_MAP_ENTITIES];
|
||||
|
||||
float smoothing_threshold;
|
||||
} xvk_map_entities_t;
|
||||
|
||||
extern xvk_map_entities_t g_map_entities;
|
||||
|
|
Loading…
Reference in New Issue