Skip to content

Commit

Permalink
Detail radius and density by K.D.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Mar 31, 2019
1 parent 0f93ccf commit 9f40a9a
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 23 deletions.
58 changes: 58 additions & 0 deletions cs/engine/layers/xrRender/DetailManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,69 @@ CDetailManager::CDetailManager ()
m_time_rot_2 = 0;
m_time_pos = 0;
m_global_time_old = 0;

// KD: variable detail radius
dm_size = dm_current_size;
dm_cache_line = dm_current_cache_line;
dm_cache1_line = dm_current_cache1_line;
dm_cache_size = dm_current_cache_size;
dm_fade = dm_current_fade;
ps_r__Detail_density = ps_current_detail_density;
cache_level1 = (CacheSlot1**)Memory.mem_alloc(dm_cache1_line * sizeof(CacheSlot1*)
#ifdef USE_MEMORY_MONITOR
, "CDetailManager::cache_level1"
#endif
);
for (u32 i = 0; i < dm_cache1_line; ++i)
{
cache_level1[i] = (CacheSlot1*)Memory.mem_alloc(dm_cache1_line * sizeof(CacheSlot1)
#ifdef USE_MEMORY_MONITOR
, "CDetailManager::cache_level1 " + i
#endif
);
for (u32 j = 0; j < dm_cache1_line; ++j)
new (&(cache_level1[i][j])) CacheSlot1();
}

cache = (Slot***)Memory.mem_alloc(dm_cache_line * sizeof(Slot**)
#ifdef USE_MEMORY_MONITOR
, "CDetailManager::cache"
#endif
);
for (u32 i = 0; i < dm_cache_line; ++i)
cache[i] = (Slot**)Memory.mem_alloc(dm_cache_line * sizeof(Slot*)
#ifdef USE_MEMORY_MONITOR
, "CDetailManager::cache " + i
#endif
);

cache_pool = (Slot *)Memory.mem_alloc(dm_cache_size * sizeof(Slot)
#ifdef USE_MEMORY_MONITOR
, "CDetailManager::cache_pool"
#endif
);
for (u32 i = 0; i < dm_cache_size; ++i)
new (&(cache_pool[i])) Slot();
}

CDetailManager::~CDetailManager ()
{
for (u32 i = 0; i < dm_cache_size; ++i)
cache_pool[i].~Slot();
Memory.mem_free(cache_pool);

for (u32 i = 0; i < dm_cache_line; ++i)
Memory.mem_free(cache[i]);
Memory.mem_free(cache);


for (u32 i = 0; i < dm_cache1_line; ++i)
{
for (u32 j = 0; j < dm_cache1_line; ++j)
cache_level1[i][j].~CacheSlot1();
Memory.mem_free(cache_level1[i]);
}
Memory.mem_free(cache_level1);
}
/*
*/
Expand Down
47 changes: 29 additions & 18 deletions cs/engine/layers/xrRender/DetailManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,34 @@
#else
const int dm_max_decompress = 7;
#endif
const int dm_size = 24; //!

// common detail constants
const int dm_cache1_count = 4; //
const int dm_cache1_line = dm_size*2/dm_cache1_count; //! dm_size*2 must be div dm_cache1_count
const int dm_max_objects = 64;
const int dm_obj_in_slot = 4;
const int dm_cache_line = dm_size+1+dm_size;
const int dm_cache_size = dm_cache_line*dm_cache_line;
const float dm_fade = float(2*dm_size)-.5f;
const float dm_slot_size = DETAIL_SLOT_SIZE;

const u32 dm_max_cache_size = 62001; // assuming max dm_size = 124
extern u32 dm_size;
extern u32 dm_cache1_line;
extern u32 dm_cache_line;
extern u32 dm_cache_size;
extern float dm_fade;
extern u32 dm_current_size;// = iFloor((float)ps_r__detail_radius/4)*2; //!
extern u32 dm_current_cache1_line;// = dm_current_size*2/dm_cache1_count; //! dm_current_size*2 must be div dm_cache1_count
extern u32 dm_current_cache_line;// = dm_current_size+1+dm_current_size;
extern u32 dm_current_cache_size;// = dm_current_cache_line*dm_current_cache_line;
extern float dm_current_fade;// = float(2*dm_current_size)-.5f;
extern float ps_current_detail_density;

class ECORE_API CDetailManager
{
public:
struct SlotItem { // îäèí êóñòèê
struct SlotItem { // один кустик
float scale;
float scale_calculated;
Fmatrix mRotY;
u32 vis_ID; // èíäåêñ â visibility ñïèñêå îí æå òèï [íå êà÷àåòñÿ, êà÷àåòñÿ1, êà÷àåòñÿ2]
u32 vis_ID; // индекс в visibility списке он же тип [не качается, качается1, качается2]
float c_hemi;
float c_sun;
#if RENDER==R_R1
Expand All @@ -51,23 +61,23 @@ class ECORE_API CDetailManager
using SlotItemVec = xr_vector<SlotItem*>;
using SlotItemVecIt = SlotItemVec::iterator;
struct SlotPart { //
u32 id; // ID ìîäåëüêè
SlotItemVec items; // ñïèñîê êóñòèêîâ
SlotItemVec r_items[3]; // ñïèñîê êóñòèêîâ for render
u32 id; // ID модельки
SlotItemVec items; // список кустиков
SlotItemVec r_items[3]; // список кустиков for render
};
enum SlotType {
stReady = 0, // Ready to use
stPending, // Pending for decompression

stFORCEDWORD = 0xffffffff
};
struct Slot { // ðàñïàêîâàíûé ñëîò ðàçìåðîì DETAIL_SLOT_SIZE
struct Slot { // распакованый слот размером DETAIL_SLOT_SIZE
struct{
u32 empty :1;
u32 type :1;
u32 frame :30;
};
int sx,sz; // êîîðäèíàòû ñëîòà X x Y
int sx,sz; // координаты слота X x Y
vis_data vis; //
SlotPart G[dm_obj_in_slot]; //

Expand Down Expand Up @@ -114,15 +124,16 @@ class ECORE_API CDetailManager

#ifndef _EDITOR
xrXRC xrc;
#endif
CacheSlot1 cache_level1[dm_cache1_line][dm_cache1_line];
Slot* cache [dm_cache_line][dm_cache_line]; // grid-cache itself
svector<Slot*,dm_cache_size> cache_task; // non-unpacked slots
Slot cache_pool [dm_cache_size]; // just memory for slots
#endif

CacheSlot1** cache_level1;
Slot*** cache; // grid-cache itself
svector<Slot*,dm_max_cache_size>cache_task; // non-unpacked slots
Slot* cache_pool; // just memory for slots
int cache_cx;
int cache_cz;

PSS poolSI; // pool èç êîòîðîãî âûäåëÿþòñÿ SlotItem
PSS poolSI; // pool из которого выделяются SlotItem

void UpdateVisibleM ();
void UpdateVisibleS ();
Expand Down
50 changes: 46 additions & 4 deletions cs/engine/layers/xrRender/xrRender_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ xr_token qminmax_sm_token [ ]={
{ 0, 0 }
};

// “Off”
// “DX10.0 style [Standard]”
// “DX10.1 style [Higher quality]”
// “Off”
// “DX10.0 style [Standard]”
// “DX10.1 style [Higher quality]”

// Common
extern int psSkeletonUpdate;
Expand Down Expand Up @@ -192,6 +192,21 @@ int ps_r2_wait_sleep = 0;
float ps_r2_lt_smooth = 1.f; // 1.f
float ps_r2_slight_fade = 1.f; // 1.f

// KD
int ps_r__detail_radius = 49;
u32 dm_size = 24;
u32 dm_cache1_line = 12; //dm_size*2/dm_cache1_count
u32 dm_cache_line = 49; //dm_size+1+dm_size
u32 dm_cache_size = 2401; //dm_cache_line*dm_cache_line
float dm_fade = 47.5; //float(2*dm_size)-.5f;
u32 dm_current_size = 24;
u32 dm_current_cache1_line = 12; //dm_current_size*2/dm_cache1_count
u32 dm_current_cache_line = 49; //dm_current_size+1+dm_current_size
u32 dm_current_cache_size = 2401; //dm_current_cache_line*dm_current_cache_line
float dm_current_fade = 47.5; //float(2*dm_current_size)-.5f;
float ps_current_detail_density = 0.6;
// KD

// x - min (0), y - focus (1.4), z - max (100)
Fvector3 ps_r2_dof = Fvector3().set(-1.4f, 0.0f, 250.f);
float ps_r2_dof_sky = 30; // distance to sky
Expand All @@ -213,6 +228,32 @@ float ps_r2_gloss_factor = 3.0f;
#include "../xrRenderDX10/StateManager/dx10SamplerStateCache.h"
#endif // USE_DX10

// KD
class CCC_DetailRadius : public CCC_Integer
{
public:
void apply()
{
dm_current_size = iFloor((float)ps_r__detail_radius / 4) * 2;
dm_current_cache1_line = dm_current_size * 2 / 4; // assuming cache1_count = 4
dm_current_cache_line = dm_current_size + 1 + dm_current_size;
dm_current_cache_size = dm_current_cache_line * dm_current_cache_line;
dm_current_fade = float(2 * dm_current_size) - .5f;
}
CCC_DetailRadius(LPCSTR N, int* V, int _min = 0, int _max = 999) : CCC_Integer(N, V, _min, _max)
{};
virtual void Execute(LPCSTR args)
{
CCC_Integer::Execute(args);
apply();
}
virtual void Status(TStatus& S)
{
CCC_Integer::Status(S);
}
};
// KD

//-----------------------------------------------------------------------
class CCC_tf_Aniso : public CCC_Integer
{
Expand Down Expand Up @@ -585,7 +626,8 @@ void xrRender_initconsole ()
//. CMD4(CCC_Float, "r__geometry_lod_pow", &ps_r__LOD_Power, 0, 2 );

//. CMD4(CCC_Float, "r__detail_density", &ps_r__Detail_density, .05f, 0.99f );
CMD4(CCC_Float, "r__detail_density", &ps_r__Detail_density, .2f, 0.6f );
CMD4(CCC_Float, "r__detail_density", &ps_current_detail_density, 0.04f, 0.6f ); // KD: extended from 0.2 to 0.04 and replaced variable
CMD4(CCC_DetailRadius, "r__detail_radius", &ps_r__detail_radius, 49, 250 ); // KD

#ifdef DEBUG
CMD4(CCC_Float, "r__detail_l_ambient", &ps_r__Detail_l_ambient, .5f, .95f );
Expand Down
1 change: 1 addition & 0 deletions cs/engine/layers/xrRender/xrRender_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern ECORE_API int ps_r__LightSleepFrames;
extern ECORE_API float ps_r__Detail_l_ambient;
extern ECORE_API float ps_r__Detail_l_aniso;
extern ECORE_API float ps_r__Detail_density;
extern ECORE_API int ps_r__detail_radius;

extern ECORE_API float ps_r__Tree_w_rot;
extern ECORE_API float ps_r__Tree_w_speed;
Expand Down
18 changes: 17 additions & 1 deletion cs/engine/layers/xrRenderPC_R1/FStaticRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ void CRender::destroy ()
void CRender::reset_begin ()
{
xr_delete (Target);

// KD: let's reload details while changed details options on vid_restart
if (b_loaded && ((dm_current_size != dm_size) || (ps_r__Detail_density != ps_current_detail_density)))
{
Details->Unload();
xr_delete(Details);
}

//. HWOCC.occq_destroy ();
}

Expand All @@ -119,7 +127,15 @@ void CRender::reset_end ()
xrRender_apply_tf ();
//. HWOCC.occq_create (occq_size);
Target = new CRenderTarget();
if (L_Projector) L_Projector->invalidate ();

// KD: let's reload details while changed details options on vid_restart
if (b_loaded && ((dm_current_size != dm_size) || (ps_r__Detail_density != ps_current_detail_density)))
{
Details = xr_new<CDetailManager>();
Details->Load();
}

if (L_Projector) L_Projector->invalidate ();
}

void CRender::OnFrame ()
Expand Down
14 changes: 14 additions & 0 deletions cs/engine/layers/xrRenderPC_R2/r2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ void CRender::reset_begin()
Lights_LastFrame.clear ();
}

// KD: let's reload details while changed details options on vid_restart
if (b_loaded && ((dm_current_size != dm_size) || (ps_r__Detail_density != ps_current_detail_density)))
{
Details->Unload();
xr_delete(Details);
}

xr_delete (Target);
HWOCC.occq_destroy ();
//_RELEASE (q_sync_point[1]);
Expand All @@ -338,6 +345,13 @@ void CRender::reset_end()

Target = new CRenderTarget();

// KD: let's reload details while changed details options on vid_restart
if (b_loaded && ((dm_current_size != dm_size) || (ps_r__Detail_density != ps_current_detail_density)))
{
Details = xr_new<CDetailManager>();;
Details->Load();
}

xrRender_apply_tf ();
}
/*
Expand Down
15 changes: 15 additions & 0 deletions cs/engine/layers/xrRenderPC_R3/r3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,14 @@ void CRender::reset_begin()
}

xr_delete (Target);

// KD: let's reload details while changed details options on vid_restart
if (b_loaded && ((dm_current_size != dm_size) || (ps_r__Detail_density != ps_current_detail_density)))
{
Details->Unload();
xr_delete(Details);
}

HWOCC.occq_destroy ();
//_RELEASE (q_sync_point[1]);
//_RELEASE (q_sync_point[0]);
Expand All @@ -459,6 +467,13 @@ void CRender::reset_end()

Target = new CRenderTarget();

// KD: let's reload details while changed details options on vid_restart
if (b_loaded && ((dm_current_size != dm_size) || (ps_r__Detail_density != ps_current_detail_density)))
{
Details = xr_new<CDetailManager>();;
Details->Load();
}

xrRender_apply_tf ();
FluidManager.SetScreenSize(Device.dwWidth, Device.dwHeight);
}
Expand Down

0 comments on commit 9f40a9a

Please sign in to comment.