mesh per triangle custom color
This commit is contained in:
parent
ae05b8f85a
commit
0463ed5057
7 changed files with 279 additions and 41 deletions
|
|
@ -50,11 +50,27 @@ typedef struct
|
|||
float radius;
|
||||
} DebugCapsule;
|
||||
|
||||
// Hull/mesh/heightfield. Scale only for mesh.
|
||||
// A slice of a mesh holding the triangles that share one material color.
|
||||
// A zero color draws with the shape color.
|
||||
typedef struct
|
||||
{
|
||||
MeshHandle handle;
|
||||
uint32_t color;
|
||||
} DebugMeshPart;
|
||||
|
||||
// Hull/mesh/heightfield. Scale only for mesh. A top-level mesh whose material
|
||||
// slots carry different custom colors is drawn as parts, one per color. The
|
||||
// slot colors are snapshot so a runtime material change rebuilds the parts.
|
||||
// The whole mesh handle is kept for highlight and material overrides.
|
||||
typedef struct
|
||||
{
|
||||
MeshHandle handle;
|
||||
b3Vec3 scale;
|
||||
const b3MeshData* data;
|
||||
uint32_t* slotColors;
|
||||
int slotCount;
|
||||
DebugMeshPart* parts;
|
||||
int partCount;
|
||||
} DebugMesh;
|
||||
|
||||
typedef struct
|
||||
|
|
@ -148,6 +164,138 @@ static const float kBodyTypeRoughness[3] = { 0.70f, 0.55f, 0.40f };
|
|||
static const float kDebugMaterialMetallic[6] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.85f };
|
||||
static const float kDebugMaterialRoughness[6] = { 0.50f, 0.85f, 0.65f, 0.95f, 0.30f, 0.35f };
|
||||
|
||||
static void ReleaseMeshParts( DebugMesh* geom )
|
||||
{
|
||||
for ( int i = 0; i < geom->partCount; ++i )
|
||||
{
|
||||
ReleaseMeshReference( geom->parts[i].handle );
|
||||
}
|
||||
free( geom->parts );
|
||||
free( geom->slotColors );
|
||||
geom->parts = NULL;
|
||||
geom->partCount = 0;
|
||||
geom->slotColors = NULL;
|
||||
geom->slotCount = 0;
|
||||
}
|
||||
|
||||
// Group the mesh triangles by the custom color of their material slot. Slots
|
||||
// sharing a color share a part, so a conveyor with many belt slots of one
|
||||
// color costs one draw. Nothing is split when every used slot has one color.
|
||||
static void BuildMeshParts( DebugShape* us )
|
||||
{
|
||||
DebugMesh* geom = &us->geom;
|
||||
ReleaseMeshParts( geom );
|
||||
|
||||
const b3MeshData* data = geom->data;
|
||||
const uint8_t* indices = data != NULL ? b3GetMeshMaterialIndices( data ) : NULL;
|
||||
const int slotCount = b3Shape_GetMeshMaterialCount( us->shapeId );
|
||||
if ( indices == NULL || slotCount <= 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
geom->slotColors = (uint32_t*)malloc( (size_t)slotCount * sizeof( uint32_t ) );
|
||||
uint8_t* used = (uint8_t*)calloc( (size_t)slotCount, 1 );
|
||||
uint8_t* mask = (uint8_t*)malloc( (size_t)slotCount );
|
||||
uint32_t* colors = (uint32_t*)malloc( (size_t)slotCount * sizeof( uint32_t ) );
|
||||
if ( geom->slotColors == NULL || used == NULL || mask == NULL || colors == NULL )
|
||||
{
|
||||
free( used );
|
||||
free( mask );
|
||||
free( colors );
|
||||
free( geom->slotColors );
|
||||
geom->slotColors = NULL;
|
||||
return;
|
||||
}
|
||||
geom->slotCount = slotCount;
|
||||
|
||||
for ( int i = 0; i < slotCount; ++i )
|
||||
{
|
||||
geom->slotColors[i] = b3Shape_GetMeshSurfaceMaterial( us->shapeId, i ).customColor;
|
||||
}
|
||||
|
||||
for ( int t = 0; t < data->triangleCount; ++t )
|
||||
{
|
||||
const int slot = indices[t] < slotCount ? indices[t] : slotCount - 1;
|
||||
used[slot] = 1;
|
||||
}
|
||||
|
||||
int colorCount = 0;
|
||||
for ( int i = 0; i < slotCount; ++i )
|
||||
{
|
||||
if ( used[i] == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bool found = false;
|
||||
for ( int j = 0; j < colorCount; ++j )
|
||||
{
|
||||
if ( colors[j] == geom->slotColors[i] )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( found == false )
|
||||
{
|
||||
colors[colorCount++] = geom->slotColors[i];
|
||||
}
|
||||
}
|
||||
|
||||
if ( colorCount > 1 )
|
||||
{
|
||||
geom->parts = (DebugMeshPart*)malloc( (size_t)colorCount * sizeof( DebugMeshPart ) );
|
||||
for ( int j = 0; geom->parts != NULL && j < colorCount; ++j )
|
||||
{
|
||||
for ( int i = 0; i < slotCount; ++i )
|
||||
{
|
||||
mask[i] = ( used[i] != 0 && geom->slotColors[i] == colors[j] ) ? 1 : 0;
|
||||
}
|
||||
|
||||
MeshHandle handle = FindOrAddMeshSubset( data, mask, slotCount );
|
||||
if ( IsMeshHandleValid( handle ) == false )
|
||||
{
|
||||
// Fall back to drawing the whole mesh in the shape color
|
||||
for ( int k = 0; k < geom->partCount; ++k )
|
||||
{
|
||||
ReleaseMeshReference( geom->parts[k].handle );
|
||||
}
|
||||
free( geom->parts );
|
||||
geom->parts = NULL;
|
||||
geom->partCount = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
geom->parts[geom->partCount].handle = handle;
|
||||
geom->parts[geom->partCount].color = colors[j];
|
||||
geom->partCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
free( used );
|
||||
free( mask );
|
||||
free( colors );
|
||||
}
|
||||
|
||||
// Rebuild the parts when a slot color changed since they were built
|
||||
static void RefreshMeshParts( DebugShape* us )
|
||||
{
|
||||
DebugMesh* geom = &us->geom;
|
||||
if ( geom->slotCount <= 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < geom->slotCount; ++i )
|
||||
{
|
||||
if ( b3Shape_GetMeshSurfaceMaterial( us->shapeId, i ).customColor != geom->slotColors[i] )
|
||||
{
|
||||
BuildMeshParts( us );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitAdapter( void )
|
||||
{
|
||||
for ( int i = 0; i < BOX3D_USER_SHAPE_CAPACITY; ++i )
|
||||
|
|
@ -183,6 +331,7 @@ void ResetAdapterPool( void )
|
|||
DebugShape* us = &s_adapter.pool[i];
|
||||
if ( us->kind == Box3DUS_Hull || us->kind == Box3DUS_Mesh || us->kind == Box3DUS_HeightField )
|
||||
{
|
||||
ReleaseMeshParts( &us->geom );
|
||||
ReleaseMeshReference( us->geom.handle );
|
||||
}
|
||||
else if ( us->kind == Box3DUS_Compound )
|
||||
|
|
@ -532,11 +681,13 @@ static int CreateCompoundChild( const b3ChildShape* child, const DebugShape* par
|
|||
break;
|
||||
case b3_hullShape:
|
||||
us->kind = Box3DUS_Hull;
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = b3Vec3_one;
|
||||
break;
|
||||
case b3_meshShape:
|
||||
us->kind = Box3DUS_Mesh;
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = (b3Vec3){ child->mesh.scale.x, child->mesh.scale.y, child->mesh.scale.z };
|
||||
break;
|
||||
|
|
@ -603,6 +754,7 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont
|
|||
DebugShape* us = &s_adapter.pool[index];
|
||||
us->kind = Box3DUS_Hull;
|
||||
PopulateCommonFields( us, debugShape );
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = b3Vec3_one;
|
||||
return us;
|
||||
|
|
@ -625,8 +777,11 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont
|
|||
DebugShape* us = &s_adapter.pool[index];
|
||||
us->kind = Box3DUS_Mesh;
|
||||
PopulateCommonFields( us, debugShape );
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = (b3Vec3){ mesh->scale.x, mesh->scale.y, mesh->scale.z };
|
||||
us->geom.data = mesh->data;
|
||||
BuildMeshParts( us );
|
||||
return us;
|
||||
}
|
||||
|
||||
|
|
@ -647,6 +802,7 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont
|
|||
DebugShape* us = &s_adapter.pool[index];
|
||||
us->kind = Box3DUS_HeightField;
|
||||
PopulateCommonFields( us, debugShape );
|
||||
us->geom = (DebugMesh){ 0 };
|
||||
us->geom.handle = handle;
|
||||
us->geom.scale = b3Vec3_one;
|
||||
return us;
|
||||
|
|
@ -740,6 +896,7 @@ static void DestroyDebugShape( void* userShape, void* context )
|
|||
}
|
||||
else if ( us->kind == Box3DUS_Hull || us->kind == Box3DUS_Mesh || us->kind == Box3DUS_HeightField )
|
||||
{
|
||||
ReleaseMeshParts( &us->geom );
|
||||
ReleaseMeshReference( us->geom.handle );
|
||||
}
|
||||
|
||||
|
|
@ -757,8 +914,8 @@ static void DestroyDebugShape( void* userShape, void* context )
|
|||
// center, capsule frame) layers on top of baseTransform, so the same path
|
||||
// serves a top-level shape (base = body transform) and a compound child
|
||||
// (base = body transform composed with the child transform).
|
||||
static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform, Vec4 c, float metallic, float roughness,
|
||||
TransparentShadowCast shadowCast, HighlightKind hk )
|
||||
static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform, Vec4 c, float metallic,
|
||||
float roughness, TransparentShadowCast shadowCast, HighlightKind hk )
|
||||
{
|
||||
if ( us->kind == Box3DUS_Sphere )
|
||||
{
|
||||
|
|
@ -782,7 +939,24 @@ static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform
|
|||
{
|
||||
MeshMaterialMode mode = us->isGround ? MESH_MATERIAL_MODE_GROUND_GRID : MESH_MATERIAL_MODE_SOLID;
|
||||
float cell = us->isGround ? BOX3D_GROUND_GRID_CELL_SIZE : 0.0f;
|
||||
AppendMesh( us->geom.handle, baseTransform, us->geom.scale, c, metallic, roughness, mode, cell, shadowCast );
|
||||
if ( us->geom.partCount > 0 && us->hasMaterial == false )
|
||||
{
|
||||
for ( int i = 0; i < us->geom.partCount; ++i )
|
||||
{
|
||||
const DebugMeshPart* part = &us->geom.parts[i];
|
||||
Vec4 pc = c;
|
||||
if ( part->color != 0 )
|
||||
{
|
||||
pc = HexColorToLinear( (b3HexColor)part->color );
|
||||
pc.w = c.w;
|
||||
}
|
||||
AppendMesh( part->handle, baseTransform, us->geom.scale, pc, metallic, roughness, mode, cell, shadowCast );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendMesh( us->geom.handle, baseTransform, us->geom.scale, c, metallic, roughness, mode, cell, shadowCast );
|
||||
}
|
||||
if ( hk != HIGHLIGHT_KIND_NONE )
|
||||
{
|
||||
AppendHighlightGeometry( us->geom.handle, baseTransform, us->geom.scale, hk );
|
||||
|
|
@ -790,9 +964,8 @@ static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform
|
|||
}
|
||||
}
|
||||
|
||||
// Context for the compound cull query. Carries the resolved material and the
|
||||
// body relative transform so each visited child appends exactly as the full
|
||||
// walk would.
|
||||
// Context for the compound cull query. Carries the resolved material and the body relative transform so each visited
|
||||
// child appends exactly as the full walk would.
|
||||
typedef struct
|
||||
{
|
||||
const DebugShape* parent;
|
||||
|
|
@ -842,6 +1015,11 @@ static void DrawShape( void* userShape, b3WorldTransform shapeTransform, b3HexCo
|
|||
|
||||
RefreshMaterialFromOverride( us );
|
||||
|
||||
if ( us->kind == Box3DUS_Mesh )
|
||||
{
|
||||
RefreshMeshParts( us );
|
||||
}
|
||||
|
||||
Vec4 c;
|
||||
float metallic;
|
||||
float roughness;
|
||||
|
|
@ -964,8 +1142,8 @@ static void DrawTransformFcn( b3WorldTransform transform, void* context )
|
|||
Vec4 blue = MakeVec4( 0.0f, 0.0f, 1.0f, 1.0f );
|
||||
OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cx ), red, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS,
|
||||
OVERLAY_OCCLUSION_HIDE );
|
||||
OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cy ), green, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS,
|
||||
OVERLAY_OCCLUSION_HIDE );
|
||||
OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cy ), green, BOX3D_LINE_THICKNESS_PX,
|
||||
OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE );
|
||||
OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cz ), blue, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS,
|
||||
OVERLAY_OCCLUSION_HIDE );
|
||||
}
|
||||
|
|
@ -988,22 +1166,22 @@ static void DrawCapsuleFcn( b3Pos p1, b3Pos p2, float radius, b3HexColor color,
|
|||
{
|
||||
(void)context;
|
||||
|
||||
b3Vec3 e = b3SubPos(p2, p1);
|
||||
b3Vec3 e = b3SubPos( p2, p1 );
|
||||
float length = b3Length( e );
|
||||
if (length < FLT_EPSILON)
|
||||
if ( length < FLT_EPSILON )
|
||||
{
|
||||
DrawSphereEx( (b3WorldTransform){ p1, b3Quat_identity }, radius, HexColorAToVec4( color, alpha ), DEFAULT_METALLIC,
|
||||
DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE );
|
||||
DrawSphereEx( (b3WorldTransform){ p1, b3Quat_identity }, radius, HexColorAToVec4( color, alpha ),
|
||||
DEFAULT_METALLIC, DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE );
|
||||
return;
|
||||
}
|
||||
|
||||
b3Vec3 en = b3MulSV( 1.0f / length, e );
|
||||
b3WorldTransform transform;
|
||||
transform.p = b3OffsetPos( p1, b3MulSV( 0.5f, e ));
|
||||
transform.p = b3OffsetPos( p1, b3MulSV( 0.5f, e ) );
|
||||
transform.q = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisX, en );
|
||||
|
||||
DrawCapsuleEx( transform, 0.5f * length, radius, HexColorAToVec4( color, alpha ), DEFAULT_METALLIC,
|
||||
DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE );
|
||||
DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE );
|
||||
}
|
||||
|
||||
static void DrawBoundsFcn( b3AABB aabb, b3HexColor color, void* context )
|
||||
|
|
|
|||
|
|
@ -420,11 +420,14 @@ static inline int MeshEdgeLess( const EdgeRecord* a, const EdgeRecord* b )
|
|||
return a->v1 < b->v1;
|
||||
}
|
||||
|
||||
static MeshHandle BuildMeshData( const b3MeshData* meshData )
|
||||
// A NULL slotMask builds every triangle. Otherwise only triangles whose material
|
||||
// slot has a nonzero mask entry are emitted, and their edges with them.
|
||||
static MeshHandle BuildMeshData( const b3MeshData* meshData, uint64_t hash, const uint8_t* slotMask, int slotCount )
|
||||
{
|
||||
const b3Vec3* verts = b3GetMeshVertices( meshData );
|
||||
const b3MeshTriangle* tris = b3GetMeshTriangles( meshData );
|
||||
const uint8_t* flags = b3GetMeshFlags( meshData );
|
||||
const uint8_t* materialIndices = slotMask != NULL ? b3GetMeshMaterialIndices( meshData ) : NULL;
|
||||
if ( !verts || !tris || meshData->triangleCount <= 0 )
|
||||
{
|
||||
fprintf( stderr, "error: mesh missing arrays or empty (hash=0x%016" PRIx64 ")\n", meshData->hash );
|
||||
|
|
@ -436,6 +439,15 @@ static MeshHandle BuildMeshData( const b3MeshData* meshData )
|
|||
|
||||
for ( int t = 0; t < meshData->triangleCount; ++t )
|
||||
{
|
||||
if ( materialIndices != NULL )
|
||||
{
|
||||
const int slot = materialIndices[t] < slotCount ? materialIndices[t] : slotCount - 1;
|
||||
if ( slotMask[slot] == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
const b3MeshTriangle tri = tris[t];
|
||||
const b3Vec3 a = verts[tri.index1];
|
||||
const b3Vec3 b = verts[tri.index2];
|
||||
|
|
@ -523,7 +535,7 @@ static MeshHandle BuildMeshData( const b3MeshData* meshData )
|
|||
eb.count = write + 1;
|
||||
}
|
||||
|
||||
const MeshHandle h = RegisterMesh( meshData->hash, buf.vertices, buf.vertexCount, buf.indices, buf.indexCount, "geom_mesh" );
|
||||
const MeshHandle h = RegisterMesh( hash, buf.vertices, buf.vertexCount, buf.indices, buf.indexCount, "geom_mesh" );
|
||||
|
||||
if ( IsMeshHandleValid( h ) )
|
||||
{
|
||||
|
|
@ -821,7 +833,37 @@ MeshHandle FindOrAddMesh( const b3MeshData* meshData )
|
|||
return existing;
|
||||
}
|
||||
|
||||
return BuildMeshData( meshData );
|
||||
return BuildMeshData( meshData, meshData->hash, NULL, 0 );
|
||||
}
|
||||
|
||||
MeshHandle FindOrAddMeshSubset( const b3MeshData* meshData, const uint8_t* slotMask, int slotCount )
|
||||
{
|
||||
if ( !meshData || meshData->hash == 0 || slotMask == NULL || slotCount <= 0 ||
|
||||
b3GetMeshMaterialIndices( meshData ) == NULL )
|
||||
{
|
||||
return FindOrAddMesh( meshData );
|
||||
}
|
||||
|
||||
// FNV-1a over the mask, seeded with the mesh hash
|
||||
uint64_t hash = meshData->hash ^ 0xcbf29ce484222325ull;
|
||||
for ( int i = 0; i < slotCount; ++i )
|
||||
{
|
||||
hash ^= slotMask[i] != 0 ? 1u : 0u;
|
||||
hash *= 0x100000001b3ull;
|
||||
}
|
||||
if ( hash == 0 || hash == meshData->hash )
|
||||
{
|
||||
hash += 1;
|
||||
}
|
||||
|
||||
MeshHandle existing = FindMesh( hash );
|
||||
if ( IsMeshHandleValid( existing ) )
|
||||
{
|
||||
AddMeshReference( existing );
|
||||
return existing;
|
||||
}
|
||||
|
||||
return BuildMeshData( meshData, hash, slotMask, slotCount );
|
||||
}
|
||||
|
||||
MeshHandle FindOrAddHeightField( const b3HeightFieldData* heightField )
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@ MeshHandle FindOrAddHull( const b3HullData* hull );
|
|||
// draw time. Two b3Mesh sharing the same b3MeshData share one entry.
|
||||
MeshHandle FindOrAddMesh( const b3MeshData* meshData );
|
||||
|
||||
// Acquire the subset of a mesh whose triangles sit in a material slot with a
|
||||
// nonzero slotMask entry. Keyed by the mesh hash mixed with the mask, so shapes
|
||||
// sharing a mesh and a slot grouping share one entry. Falls back to the whole
|
||||
// mesh when the mesh carries no material indices.
|
||||
MeshHandle FindOrAddMeshSubset( const b3MeshData* meshData, const uint8_t* slotMask, int slotCount );
|
||||
|
||||
// Acquire for b3HeightFieldData. The `scale` vector is part of the height
|
||||
// field's hash (folded into construction), so two heightfields with
|
||||
// different scales hash to different entries, per-instance scale stays
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ EdgeOverlayParams GetDefaultEdgeParams( void )
|
|||
p.zBias = 1.0e-6f;
|
||||
p.convexColor = MakeVec4( 0.1f, 0.8f, 0.1f, 0.75f );
|
||||
p.concaveColor = MakeVec4( 0.8f, 0.10f, 0.10f, 0.75f );
|
||||
p.flatColor = MakeVec4( 0.6f, 0.6f, 0.6f, 0.5f );
|
||||
p.flatColor = MakeVec4( 0.6f, 0.6f, 0.6f, 0.2f );
|
||||
p.alphaScale = 1.0f;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
@ -106,9 +107,11 @@ void ShutdownEdges( void )
|
|||
s_edges.ready = false;
|
||||
}
|
||||
|
||||
static inline Vec4 Premultiply( Vec4 c )
|
||||
static inline Vec4 Premultiply( Vec4 c, float alphaScale )
|
||||
{
|
||||
return MakeVec4( c.x * c.w, c.y * c.w, c.z * c.w, c.w );
|
||||
float a = c.w * alphaScale;
|
||||
a = a < 1.0f ? a : 1.0f;
|
||||
return MakeVec4( c.x * a, c.y * a, c.z * a, a );
|
||||
}
|
||||
|
||||
// Per-batch policy: does the toggle want this batch drawn at all?
|
||||
|
|
@ -160,13 +163,13 @@ static void SubmitBatches( int width, int height, const Mat4* view, const Mat4*
|
|||
edge_ub_pass_t passMesh = { 0 };
|
||||
if ( params->showEdgeConvexity )
|
||||
{
|
||||
passMesh.convex_color = Premultiply( params->convexColor );
|
||||
passMesh.concave_color = Premultiply( params->concaveColor );
|
||||
passMesh.flat_color = Premultiply( params->flatColor );
|
||||
passMesh.convex_color = Premultiply( params->convexColor, params->alphaScale );
|
||||
passMesh.concave_color = Premultiply( params->concaveColor, params->alphaScale );
|
||||
passMesh.flat_color = Premultiply( params->flatColor, params->alphaScale );
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec4 flat = Premultiply( params->flatColor );
|
||||
Vec4 flat = Premultiply( params->flatColor, params->alphaScale );
|
||||
passMesh.convex_color = flat;
|
||||
passMesh.concave_color = flat;
|
||||
passMesh.flat_color = flat;
|
||||
|
|
@ -175,7 +178,7 @@ static void SubmitBatches( int width, int height, const Mat4* view, const Mat4*
|
|||
edge_ub_pass_t passHull = { 0 };
|
||||
|
||||
Vec4 hullEdgeColor = { 0.5f, 0.5f, 0.5f, 0.5f };
|
||||
Vec4 hull = Premultiply( hullEdgeColor );
|
||||
Vec4 hull = Premultiply( hullEdgeColor, params->alphaScale );
|
||||
passHull.convex_color = hull;
|
||||
passHull.concave_color = hull;
|
||||
passHull.flat_color = hull;
|
||||
|
|
|
|||
|
|
@ -6,18 +6,14 @@
|
|||
// into two submission paths to match the silhouette quality of the
|
||||
// rest of the scene:
|
||||
//
|
||||
// Opaque path (RenderEdgesInMSAA): opaque-arena batches (meshes,
|
||||
// heightfields, opaque hulls if policy 1b is ever relaxed). Draws
|
||||
// inside the caller's currently-open MSAA scene pass, picking up the
|
||||
// same 4x MSAA as the opaque shapes. Pipeline tracks scene_target's
|
||||
// color/depth formats and sample_count.
|
||||
// Opaque path (RenderEdgesInMSAA): opaque-arena batches (meshes, heightfields, opaque hulls). Draws inside the caller's
|
||||
// currently-open MSAA scene pass, picking up the same 4x MSAA as the opaque shapes. Pipeline tracks scene_target's
|
||||
// color/depth formats and sample_count.
|
||||
//
|
||||
// Transparent path (RenderEdgesPostTransparent): transparent-arena batches
|
||||
// (hulls per policy 1b). Opens its own single-sample pass against the
|
||||
// resolved scene color + GTAO prepass depth, so edges sit on top of the
|
||||
// transparent draws that have already blended into the resolve. MSAA
|
||||
// isn't available here (the resolve already happened), the FS's
|
||||
// fwidth-based AA does what it can.
|
||||
// Transparent path (RenderEdgesPostTransparent): transparent-arena batches (just hulls). Opens its own single-sample
|
||||
// pass against the resolved scene color + GTAO prepass depth, so edges sit on top of the transparent draws that have
|
||||
// already blended into the resolve. MSAA isn't available here (the resolve already happened), the FS's fwidth-based AA
|
||||
// does what it can.
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -43,6 +39,7 @@ typedef struct EdgeOverlayParams
|
|||
Vec4 convexColor; // straight (non-premultiplied) linear RGBA, premultiplied inside
|
||||
Vec4 concaveColor;
|
||||
Vec4 flatColor;
|
||||
float alphaScale; // multiplies the alpha of every edge color, clamped to 1
|
||||
} EdgeOverlayParams;
|
||||
|
||||
EdgeOverlayParams GetDefaultEdgeParams( void );
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ void SampleContext::Save()
|
|||
fprintf( file, " \"drawDistance\": %g,\n", drawDistance );
|
||||
fprintf( file, " \"showHullEdges\": %s,\n", GetEdgeOverlayParams().showHulls ? "true" : "false" );
|
||||
fprintf( file, " \"showEdgeConvexity\": %s,\n", GetEdgeOverlayParams().showEdgeConvexity ? "true" : "false" );
|
||||
fprintf( file, " \"edgeAlpha\": %g,\n", GetEdgeOverlayParams().alphaScale );
|
||||
fprintf( file, " \"showMetrics\": %s,\n", showMetrics ? "true" : "false" );
|
||||
fprintf( file, " \"showProfile\": %s,\n", showProfile ? "true" : "false" );
|
||||
fprintf( file, " \"replayKeyframeBudgetMB\": %d,\n", replayKeyframeBudgetMB );
|
||||
|
|
@ -274,6 +275,12 @@ void SampleContext::Load()
|
|||
p.showEdgeConvexity = strncmp( s, "true", 4 ) == 0;
|
||||
SetEdgeOverlayParams( &p );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "edgeAlpha" ) == 0 )
|
||||
{
|
||||
EdgeOverlayParams p = GetEdgeOverlayParams();
|
||||
p.alphaScale = b3ClampFloat( ParseFloat( data, tokens[i + 1] ), 0.0f, 4.0f );
|
||||
SetEdgeOverlayParams( &p );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "showMetrics" ) == 0 )
|
||||
{
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
|
|
@ -1756,6 +1763,11 @@ static void DrawRenderMenu( SampleContext& ctx )
|
|||
ImGui::Separator();
|
||||
|
||||
ImGui::PushItemWidth( 8.0f * ImGui::GetFontSize() );
|
||||
if ( ImGui::SliderFloat( "Edge Alpha", &edgeParams.alphaScale, 0.0f, 4.0f, "%.2f" ) )
|
||||
{
|
||||
SetEdgeOverlayParams( &edgeParams );
|
||||
}
|
||||
|
||||
float ev = GetExposure();
|
||||
if ( ImGui::SliderFloat( "Exposure", &ev, -8.0f, 4.0f, "%.2f" ) )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2832,14 +2832,14 @@ public:
|
|||
if ( index == 0 )
|
||||
{
|
||||
material.friction = 0.2f;
|
||||
material.customColor = b3_colorGoldenRod;
|
||||
material.customColor = b3_colorCadetBlue;
|
||||
return material;
|
||||
}
|
||||
|
||||
if ( index == m_slideMaterial )
|
||||
{
|
||||
material.friction = m_slideFriction;
|
||||
material.customColor = b3_colorSteelBlue;
|
||||
material.customColor = b3_colorSilver;
|
||||
return material;
|
||||
}
|
||||
|
||||
|
|
@ -2847,7 +2847,7 @@ public:
|
|||
float yaw = -B3_PI + 2.0f * B3_PI * (float)( index - m_firstBeltMaterial ) / (float)m_yawBinCount;
|
||||
material.friction = 0.8f;
|
||||
material.tangentVelocity = { m_beltSpeed * cosf( yaw ), 0.0f, m_beltSpeed * sinf( yaw ) };
|
||||
material.customColor = b3_colorSlateGray;
|
||||
material.customColor = b3_colorLightSteelBlue;
|
||||
return material;
|
||||
}
|
||||
|
||||
|
|
@ -3541,7 +3541,7 @@ public:
|
|||
|
||||
b3Vec3 p = m_stations[k] + 0.05f * m_ups[k];
|
||||
b3Vec3 t = m_tangents[k];
|
||||
DrawArrow( b3ToPos( p ), b3ToPos( p + 0.25f * m_beltSpeed * t ), MakeColor( b3_colorBlueViolet ) );
|
||||
DrawArrow( b3ToPos( p ), b3ToPos( p + 0.25f * m_beltSpeed * t ), MakeColor( b3_colorGold ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue