mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 14:53:01 +02:00
Adding better octree visualization
This commit is contained in:
parent
a2a9227d28
commit
972d4cda77
5 changed files with 89 additions and 32 deletions
|
@ -10,35 +10,6 @@
|
|||
!>
|
||||
<@if not GPU_COLOR_SLH@>
|
||||
<@def GPU_COLOR_SLH@>
|
||||
<!
|
||||
float colorComponentToLinear(float cs) {
|
||||
// sRGB to linear conversion
|
||||
// { cs / 12.92, cs <= 0.04045
|
||||
// cl = {
|
||||
// { ((cs + 0.055)/1.055)^2.4, cs > 0.04045
|
||||
// constants:
|
||||
// T = 0.04045
|
||||
// A = 1 / 1.055 = 0.94786729857
|
||||
// B = 0.055 * A = 0.05213270142
|
||||
// C = 1 / 12.92 = 0.0773993808
|
||||
// G = 2.4
|
||||
const float T = 0.04045;
|
||||
const float A = 0.947867;
|
||||
const float B = 0.052132;
|
||||
const float C = 0.077399;
|
||||
const float G = 2.4;
|
||||
|
||||
if (cs > T) {
|
||||
return pow((cs * A + B), G);
|
||||
} else {
|
||||
return cs * C;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 colorToLinear(vec3 srgb) {
|
||||
return vec3(colorComponentToLinear(srgb.x), colorComponentToLinear(srgb.y), colorComponentToLinear(srgb.z));
|
||||
}
|
||||
!>
|
||||
|
||||
vec3 colorToLinearRGB(vec3 srgb) {
|
||||
const float GAMMA_22 = 2.2;
|
||||
|
@ -49,4 +20,27 @@ vec4 colorToLinearRGBA(vec4 srgba) {
|
|||
return vec4(colorToLinearRGB(srgba.xyz), srgba.w);
|
||||
}
|
||||
|
||||
<@func declareColorWheel()@>
|
||||
vec3 colorWheel(float normalizedHue) {
|
||||
float v = normalizedHue * 6.f;
|
||||
if (v < 0.f) {
|
||||
return vec3(1.f, 0.f, 0.f);
|
||||
} else if (v < 1.f) {
|
||||
return vec3(1.f, v, 0.f);
|
||||
} else if (v < 2.f) {
|
||||
return vec3(1.f - (v-1.f), 1.f, 0.f);
|
||||
} else if (v < 3.f) {
|
||||
return vec3(0.f, 1.f, (v-2.f));
|
||||
} else if (v < 4.f) {
|
||||
return vec3(0.f, 1.f - (v-3.f), 1.f );
|
||||
} else if (v < 5.f) {
|
||||
return vec3((v-4.f), 0.f, 1.f );
|
||||
} else if (v < 6.f) {
|
||||
return vec3(1.f, 0.f, 1.f - (v-5.f));
|
||||
} else {
|
||||
return vec3(1.f, 0.f, 0.f);
|
||||
}
|
||||
}
|
||||
<@endfunc@>
|
||||
|
||||
<@endif@>
|
|
@ -37,6 +37,7 @@ const gpu::PipelinePointer DrawSceneOctree::getDrawCellBoundsPipeline() {
|
|||
|
||||
_drawBoundPosLoc = program->getUniforms().findLocation("inBoundPos");
|
||||
_drawBoundDimLoc = program->getUniforms().findLocation("inBoundDim");
|
||||
_drawCellLocationLoc = program->getUniforms().findLocation("inCellLocation");
|
||||
|
||||
auto state = std::make_shared<gpu::State>();
|
||||
|
||||
|
@ -104,10 +105,16 @@ void DrawSceneOctree::run(const SceneContextPointer& sceneContext,
|
|||
AABox* cellAABox = reinterpret_cast<AABox*> (_cells->editData());
|
||||
|
||||
const unsigned int VEC3_ADRESS_OFFSET = 3;
|
||||
const auto& inCells = scene->getSpatialTree()._cells;
|
||||
|
||||
for (int i = 0; i < nbCells; i++) {
|
||||
batch._glUniform3fv(_drawBoundPosLoc, 1, (const float*) (cellAABox + i));
|
||||
batch._glUniform3fv(_drawBoundDimLoc, 1, ((const float*) (cellAABox + i)) + VEC3_ADRESS_OFFSET);
|
||||
batch._glUniform3fv(_drawBoundDimLoc, 1, ((const float*)(cellAABox + i)) + VEC3_ADRESS_OFFSET);
|
||||
|
||||
auto& cellLoc = inCells[i].getlocation();
|
||||
glm::ivec4 cellLocation(cellLoc.pos.x, cellLoc.pos.y, cellLoc.pos.z, cellLoc.depth);
|
||||
|
||||
batch._glUniform4iv(_drawCellLocationLoc, 1, ((const int*)(&cellLocation)));
|
||||
|
||||
batch.draw(gpu::LINES, 24, 0);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace render {
|
|||
|
||||
int _drawBoundPosLoc;
|
||||
int _drawBoundDimLoc;
|
||||
int _drawCellLocationLoc;
|
||||
gpu::PipelinePointer _drawCellBoundsPipeline;
|
||||
gpu::BufferPointer _cells;
|
||||
|
||||
|
|
|
@ -16,5 +16,5 @@ out vec4 outFragColor;
|
|||
|
||||
|
||||
void main(void) {
|
||||
outFragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
outFragColor = varColor;
|
||||
}
|
||||
|
|
|
@ -16,8 +16,63 @@
|
|||
|
||||
<$declareStandardTransform()$>
|
||||
|
||||
<@include gpu/Color.slh@>
|
||||
<$declareColorWheel()$>
|
||||
|
||||
<!
|
||||
uniform ivec4 inCellLocation;
|
||||
|
||||
const float _size = 32768.0;
|
||||
const float _invSize = 1.0 / _size;
|
||||
const vec3 _origin = vec3(-16384.0);
|
||||
|
||||
float getSize() { return _size; }
|
||||
vec3 getOrigin() { return _origin; }
|
||||
|
||||
const int MAX_DEPTH = 15;
|
||||
const float INV_DEPTH_DIM[16] = float[16](
|
||||
1.0,
|
||||
1.0 / 2.0,
|
||||
1.0 / 4.0,
|
||||
1.0 / 8.0,
|
||||
1.0 / 16.0,
|
||||
1.0 / 32.0,
|
||||
1.0 / 64.0,
|
||||
1.0 / 128.0,
|
||||
1.0 / 256.0,
|
||||
1.0 / 512.0,
|
||||
1.0 / 1024.0,
|
||||
1.0 / 2048.0,
|
||||
1.0 / 4096.0,
|
||||
1.0 / 8192.0,
|
||||
1.0 / 16384.0,
|
||||
1.0 / 32768.0 );
|
||||
|
||||
int getDepthDimension(int depth) { return 1 << depth; }
|
||||
float getInvDepthDimension(int depth) { return INV_DEPTH_DIM[depth]; }
|
||||
|
||||
float getCellWidth(int depth) { return _size * getInvDepthDimension(depth); }
|
||||
float getInvCellWidth(int depth) { return float(getDepthDimension(depth)) * _invSize; }
|
||||
|
||||
vec3 evalPos(ivec3 coord, int depth = MAX_DEPTH) {
|
||||
return getOrigin() + vec3(coord) * getCellWidth(depth);
|
||||
}
|
||||
vec3 evalPos(ivec3 coord, float cellWidth) {
|
||||
return getOrigin() + vec3(coord) * cellWidth;
|
||||
}
|
||||
|
||||
vec4 evalBound(ivec4 loc) {
|
||||
float cellWidth = getCellWidth(loc.w);
|
||||
return vec4(evalPos(loc.xyz, cellWidth), cellWidth);
|
||||
}
|
||||
!>
|
||||
|
||||
uniform vec3 inBoundPos;
|
||||
uniform vec3 inBoundDim;
|
||||
uniform ivec4 inCellLocation;
|
||||
|
||||
out vec4 varColor;
|
||||
|
||||
|
||||
void main(void) {
|
||||
const vec4 UNIT_BOX[8] = vec4[8](
|
||||
|
@ -53,5 +108,5 @@ void main(void) {
|
|||
TransformObject obj = getTransformObject();
|
||||
<$transformModelToClipPos(cam, obj, pos, gl_Position)$>
|
||||
|
||||
// varTexcoord = (pos.xy + 1) * 0.5;
|
||||
varColor = vec4(colorWheel(fract(float(inCellLocation.w) / 5.0)), 1.0);
|
||||
}
|
Loading…
Reference in a new issue