64-bit hashes (#126)
- ContactEvent sample - Improved shadows - #120 - Triangle collision fixes
This commit is contained in:
parent
3fc20f5b45
commit
f42be210a2
49 changed files with 19835 additions and 17544 deletions
|
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Copies documentation to blog
|
||||
cp -R build/docs/html/. ../box2d_blog/public/documentation3d/
|
||||
4
docs/deploy_docs.sh
Normal file
4
docs/deploy_docs.sh
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Copies documentation to blog
|
||||
cp -R build/docs/html/. ../blog/public/documentation3d/
|
||||
18
docs/faq.md
18
docs/faq.md
|
|
@ -44,6 +44,24 @@ for orientation and 3x3 inertia tensors for rotational dynamics. If you come acr
|
|||
understand, please read about it on Wikipedia. Visit this [page](https://box2d.org/publications/) if you want a deeper
|
||||
knowledge of the algorithms used in Box3D.
|
||||
|
||||
### Working with Unreal
|
||||
|
||||
You can use Box3D in Unreal as a plug-in. Here is the module file I use:
|
||||
|
||||
[Box3D module](https://gist.github.com/erincatto/6f08df5f1e6e9a79fb4be6298a3e1125)
|
||||
|
||||
Unreal uses centimeters as units while Box3D has tolerances tuned for meters. You can either scale dimensions you send and recieve from Box3D or you can use this to set the length units:
|
||||
|
||||
```c
|
||||
b3SetLengthUnitsPerMeter(100.0f);
|
||||
```
|
||||
|
||||
This doesn't scale the units. Instead it scales the tolerances used internally in Box3D to be more appropriate for centimeters.
|
||||
|
||||
Another issue is that Box3D is right-handed while Unreal is left-handed. Box3D has way too much math for it to be reasonable to support a left-handed option. However, it doesn't matter. In practice you don't need to do any conversions. Box3D will run in a mirrored world and the outputs from Box3D are fully compatible with the Unreal coordinates.
|
||||
|
||||
I would just be careful about using Box3D math functions like `b3Cross` and expecting it to give the same result as the Unreal cross product.
|
||||
|
||||
## API
|
||||
|
||||
### What units does Box3D use?
|
||||
|
|
|
|||
|
|
@ -42,11 +42,13 @@ printf("Box3D version %d.%d.%d\n", version.major, version.minor, version.revisio
|
|||
```
|
||||
|
||||
## Vector Math
|
||||
|
||||
Box3D includes a vector math library covering types `b3Vec3`, `b3Quat`, `b3Transform`,
|
||||
`b3Matrix3`, and `b3AABB`. The library is designed to suit the internal needs of Box3D
|
||||
and its interface. All members are exposed, so you can use them freely in your application.
|
||||
|
||||
### b3Vec3
|
||||
|
||||
Three-component float vector with fields `x`, `y`, `z`. Useful constants and operations:
|
||||
|
||||
```c
|
||||
|
|
@ -64,6 +66,7 @@ b3Vec3 q = b3Lerp(a, b, 0.5f); // linear interpolation
|
|||
```
|
||||
|
||||
### b3Quat
|
||||
|
||||
Unit quaternion representing orientation. Stored as a vector part `q.v` (x, y, z) and a
|
||||
scalar part `q.s`. The identity quaternion is `b3Quat_identity`.
|
||||
|
||||
|
|
@ -103,6 +106,7 @@ Because orientation in 3D is three-dimensional, there is no single scalar angle
|
|||
in 2D. Always work with the full quaternion or the derived matrix.
|
||||
|
||||
### b3Transform
|
||||
|
||||
A rigid transform: a position vector `t.p` (`b3Vec3`) combined with an orientation `t.q`
|
||||
(`b3Quat`). The identity transform is `b3Transform_identity`.
|
||||
|
||||
|
|
|
|||
|
|
@ -323,10 +323,10 @@ typedef struct b3RecPlayerInfo
|
|||
/// Replaying at a different count re-partitions the constraint graph, so the StateHash check
|
||||
/// becomes a cross-thread determinism test. Adjustable later with b3RecPlayer_SetWorkerCount.
|
||||
/// @return a new player, or NULL on bad header or deserialization failure
|
||||
B3_API b3RecPlayer* b3RecPlayer_Create( const void* data, int size, int workerCount );
|
||||
B3_API b3RecPlayer* b3CreatePlayer( const void* data, int size, int workerCount );
|
||||
|
||||
/// Destroy the player and free all memory. Restores the previous global length scale.
|
||||
B3_API void b3RecPlayer_Destroy( b3RecPlayer* player );
|
||||
B3_API void b3DestroyPlayer( b3RecPlayer* player );
|
||||
|
||||
/// Advance one frame. dispatch ops until the next Step completes.
|
||||
/// @return true when a frame was stepped, false at end-of-recording
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ B3_INLINE float b3DistanceSquared( b3Vec3 a, b3Vec3 b )
|
|||
}
|
||||
|
||||
/// Normalize a vector. Returns a zero vector if the input vector is very small.
|
||||
B3_INLINE b3Vec3 b3Normalize( b3Vec3 a )
|
||||
B3_FORCE_INLINE b3Vec3 b3Normalize( b3Vec3 a )
|
||||
{
|
||||
float lengthSquared = a.x * a.x + a.y * a.y + a.z * a.z;
|
||||
|
||||
|
|
@ -571,7 +571,7 @@ B3_INLINE float b3GetTwistAngle( b3Quat q )
|
|||
}
|
||||
|
||||
/// Swing angle used for cone limit
|
||||
B3_INLINE float b3GetSwingAngle( b3Quat q )
|
||||
B3_FORCE_INLINE float b3GetSwingAngle( b3Quat q )
|
||||
{
|
||||
// Polarity should not matter because all terms are squared.
|
||||
float x = sqrtf( q.v.z * q.v.z + q.s * q.s );
|
||||
|
|
@ -629,7 +629,7 @@ B3_INLINE b3Transform b3InvertTransform( b3Transform t )
|
|||
}
|
||||
|
||||
/// Transform a point.
|
||||
B3_INLINE b3Vec3 b3TransformPoint( b3Transform t, b3Vec3 v )
|
||||
B3_FORCE_INLINE b3Vec3 b3TransformPoint( b3Transform t, b3Vec3 v )
|
||||
{
|
||||
b3Vec3 rv = b3RotateVector( t.q, v );
|
||||
return b3Add( rv, t.p );
|
||||
|
|
@ -718,18 +718,8 @@ B3_INLINE b3Vec3 b3InvTransformWorldPoint( b3WorldTransform t, b3Pos p )
|
|||
return b3InvRotateVector( t.q, d );
|
||||
}
|
||||
|
||||
/// Relative transform of frame B in frame A. The narrow phase boundary.
|
||||
B3_INLINE b3Transform b3InvMulWorldTransforms( b3WorldTransform A, b3WorldTransform B )
|
||||
{
|
||||
b3Transform C;
|
||||
C.q = b3InvMulQuat( A.q, B.q );
|
||||
b3Vec3 d = { (float)( B.p.x - A.p.x ), (float)( B.p.y - A.p.y ), (float)( B.p.z - A.p.z ) };
|
||||
C.p = b3InvRotateVector( A.q, d );
|
||||
return C;
|
||||
}
|
||||
|
||||
/// Compose a world transform with a local transform.
|
||||
B3_INLINE b3WorldTransform b3MulWorldTransforms( b3WorldTransform A, b3Transform B )
|
||||
B3_FORCE_INLINE b3WorldTransform b3MulWorldTransforms( b3WorldTransform A, b3Transform B )
|
||||
{
|
||||
b3WorldTransform C;
|
||||
C.q = b3MulQuat( A.q, B.q );
|
||||
|
|
@ -738,6 +728,16 @@ B3_INLINE b3WorldTransform b3MulWorldTransforms( b3WorldTransform A, b3Transform
|
|||
return C;
|
||||
}
|
||||
|
||||
/// Relative transform of frame B in frame A. The narrow phase boundary.
|
||||
B3_FORCE_INLINE b3Transform b3InvMulWorldTransforms( b3WorldTransform A, b3WorldTransform B )
|
||||
{
|
||||
b3Transform C;
|
||||
C.q = b3InvMulQuat( A.q, B.q );
|
||||
b3Vec3 d = { (float)( B.p.x - A.p.x ), (float)( B.p.y - A.p.y ), (float)( B.p.z - A.p.z ) };
|
||||
C.p = b3InvRotateVector( A.q, d );
|
||||
return C;
|
||||
}
|
||||
|
||||
/// Shift a world transform into the frame of a base position.
|
||||
B3_INLINE b3Transform b3ToRelativeTransform( b3WorldTransform t, b3Pos base )
|
||||
{
|
||||
|
|
@ -872,7 +872,7 @@ B3_INLINE b3Matrix3 b3InvertMatrix( b3Matrix3 m )
|
|||
|
||||
/// Solve a matrix equation.
|
||||
/// @return inv(m) * a
|
||||
B3_INLINE b3Vec3 b3Solve3( b3Matrix3 m, b3Vec3 a )
|
||||
B3_FORCE_INLINE b3Vec3 b3Solve3( b3Matrix3 m, b3Vec3 a )
|
||||
{
|
||||
float det = b3Det( m );
|
||||
if ( b3AbsFloat( det ) > 1000.0f * FLT_MIN )
|
||||
|
|
@ -1037,7 +1037,7 @@ B3_INLINE bool b3AABB_Overlaps( b3AABB a, b3AABB b )
|
|||
/// Transform an axis-aligned bounding box. This can create a larger box
|
||||
/// than if you recomputed the AABB of the original shape with the transform
|
||||
/// applied.
|
||||
B3_INLINE b3AABB b3AABB_Transform( b3Transform transform, b3AABB a )
|
||||
B3_FORCE_INLINE b3AABB b3AABB_Transform( b3Transform transform, b3AABB a )
|
||||
{
|
||||
b3Vec3 center = b3TransformPoint( transform, b3AABB_Center( a ) );
|
||||
b3Matrix3 m = b3MakeMatrixFromQuat( transform.q );
|
||||
|
|
|
|||
|
|
@ -1968,7 +1968,7 @@ typedef struct b3HullFace
|
|||
} b3HullFace;
|
||||
|
||||
/// 64-bit hull version. Useful for validating serialized data.
|
||||
#define B3_HULL_VERSION 0xDA5150191B994C01ull
|
||||
#define B3_HULL_VERSION 0xE3BD07365000417Cull
|
||||
|
||||
/// A convex hull.
|
||||
/// @note This data structure has data hanging off the end and cannot be directly copied.
|
||||
|
|
@ -1977,11 +1977,8 @@ typedef struct b3HullData
|
|||
/// Version must be first and match B3_HULL_VERSION
|
||||
uint64_t version;
|
||||
|
||||
/// The total number of bytes for this hull.
|
||||
int byteCount;
|
||||
|
||||
/// Hash of this hull (this field is zero when the hash is computed).
|
||||
uint32_t hash;
|
||||
uint64_t hash;
|
||||
|
||||
/// Axis-aligned box in local space.
|
||||
b3AABB aabb;
|
||||
|
|
@ -2002,38 +1999,39 @@ typedef struct b3HullData
|
|||
b3Matrix3 centralInertia;
|
||||
|
||||
/// The vertex count.
|
||||
int vertexCount;
|
||||
int32_t vertexCount;
|
||||
|
||||
/// Offset of the vertex array in bytes from the struct address.
|
||||
int vertexOffset;
|
||||
int32_t vertexOffset;
|
||||
|
||||
/// Offset of the point array in bytes from the struct address.
|
||||
int pointOffset;
|
||||
int32_t pointOffset;
|
||||
|
||||
/// This is the half-edge count (double the edge count)
|
||||
int edgeCount;
|
||||
int32_t edgeCount;
|
||||
|
||||
/// Offset of the edge array in bytes from the struct address.
|
||||
int edgeOffset;
|
||||
int32_t edgeOffset;
|
||||
|
||||
/// The face count. Hulls faces are convex polygons.
|
||||
int faceCount;
|
||||
int32_t faceCount;
|
||||
|
||||
/// Offset of the face plane array in bytes from the struct address.
|
||||
int planeOffset;
|
||||
int32_t planeOffset;
|
||||
|
||||
/// Offset of the face array in bytes from the struct address.
|
||||
int faceOffset;
|
||||
int32_t faceOffset;
|
||||
|
||||
/// Offset of structure of array (SOA) vertices
|
||||
int soaVertexOffset;
|
||||
int32_t soaVertexOffset;
|
||||
|
||||
/// Offset of structure of array (SOA) unit normal vectors
|
||||
int soaNormalOffset;
|
||||
int32_t soaNormalOffset;
|
||||
|
||||
/// Explicit padding. Hull identity is a content hash and memcmp over raw bytes,
|
||||
/// so there must be no unnamed padding for struct copies to scramble.
|
||||
int padding;
|
||||
/// The total number of bytes for this hull.
|
||||
int32_t byteCount;
|
||||
|
||||
/// Any padding must be explicit.
|
||||
} b3HullData;
|
||||
|
||||
/// Efficient box hull
|
||||
|
|
@ -2046,7 +2044,7 @@ typedef struct b3BoxHull
|
|||
b3HullHalfEdge boxEdges[24]; ///< Box half-edges.
|
||||
b3Plane boxPlanes[6]; ///< Box face planes.
|
||||
b3HullFace boxFaces[6]; ///< Box faces.
|
||||
uint8_t padding[10]; ///< Explicit padding, see b3HullData::padding.
|
||||
uint8_t padding[2]; ///< Explicit padding.
|
||||
float vx[8]; ///< vertex x
|
||||
float vy[8]; ///< vertex y
|
||||
float vz[8]; ///< vertex z
|
||||
|
|
@ -2063,10 +2061,11 @@ typedef struct b3BoxHull
|
|||
* @{
|
||||
*/
|
||||
|
||||
/// This is used to create a re-usable collision mesh.
|
||||
/// This is used to create a re-usable collision mesh. No pointers
|
||||
/// are held to this data in b3MeshData. So all this data can be temporary.
|
||||
typedef struct b3MeshDef
|
||||
{
|
||||
/// Triangle vertices
|
||||
/// Triangle vertices.
|
||||
b3Vec3* vertices;
|
||||
|
||||
/// Triangle vertex indices. 3 for each triangle. CCW winding.
|
||||
|
|
@ -2098,7 +2097,7 @@ typedef struct b3MeshDef
|
|||
} b3MeshDef;
|
||||
|
||||
/// 64-bit mesh version. Useful for validating serialized data.
|
||||
#define B3_MESH_VERSION 0xABD11AB62A6E886Dull
|
||||
#define B3_MESH_VERSION 0xA661B13E6655156Full
|
||||
|
||||
/// Triangle mesh edge flags.
|
||||
typedef enum b3MeshEdgeFlags
|
||||
|
|
@ -2172,11 +2171,11 @@ typedef struct b3MeshData
|
|||
/// Version must be first.
|
||||
uint64_t version;
|
||||
|
||||
/// The total number of bytes for this mesh.
|
||||
int byteCount;
|
||||
|
||||
/// Hash of this mesh (this field is zero when the hash is computed)
|
||||
uint32_t hash;
|
||||
uint64_t hash;
|
||||
|
||||
/// The total number of bytes for this mesh.
|
||||
int32_t byteCount;
|
||||
|
||||
/// Local axis-aligned box.
|
||||
b3AABB bounds;
|
||||
|
|
@ -2185,37 +2184,40 @@ typedef struct b3MeshData
|
|||
float surfaceArea;
|
||||
|
||||
/// The height of the bounding volume hierarchy.
|
||||
int treeHeight;
|
||||
int32_t treeHeight;
|
||||
|
||||
/// The number of degenerate triangles. Diagnostic.
|
||||
int degenerateCount;
|
||||
int32_t degenerateCount;
|
||||
|
||||
/// Offset of the node array in bytes from the struct address.
|
||||
int nodeOffset;
|
||||
int32_t nodeOffset;
|
||||
|
||||
/// The number of BVH nodes.
|
||||
int nodeCount;
|
||||
int32_t nodeCount;
|
||||
|
||||
/// Offset of the vertex array in bytes from the struct address.
|
||||
int vertexOffset;
|
||||
int32_t vertexOffset;
|
||||
|
||||
/// The number of vertices.
|
||||
int vertexCount;
|
||||
int32_t vertexCount;
|
||||
|
||||
/// Offset of the triangle array in bytes from the struct address.
|
||||
int triangleOffset;
|
||||
int32_t triangleOffset;
|
||||
|
||||
/// The number of triangles.
|
||||
int triangleCount;
|
||||
int32_t triangleCount;
|
||||
|
||||
/// Offset of the material array in bytes from the struct address.
|
||||
int materialOffset;
|
||||
int32_t materialOffset;
|
||||
|
||||
/// The number of materials.
|
||||
int materialCount;
|
||||
int32_t materialCount;
|
||||
|
||||
/// Offset of the triangle flag array in bytes from the struct address.
|
||||
int flagsOffset;
|
||||
int32_t flagsOffset;
|
||||
|
||||
/// Explicit padding.
|
||||
int32_t padding;
|
||||
} b3MeshData;
|
||||
|
||||
/// This allows mesh data to be re-used with different scales.
|
||||
|
|
@ -2237,7 +2239,7 @@ typedef struct b3Mesh
|
|||
* @{
|
||||
*/
|
||||
|
||||
/// Data used to create a height field
|
||||
/// Data used to create a height field. No pointers are held to this data.
|
||||
typedef struct b3HeightFieldDef
|
||||
{
|
||||
/// Grid point heights
|
||||
|
|
@ -2276,7 +2278,7 @@ typedef struct b3HeightFieldDef
|
|||
#define B3_HEIGHT_FIELD_HOLE 0xFF
|
||||
|
||||
/// 64-bit height-field version. Useful for validating serialized data.
|
||||
#define B3_HEIGHT_FIELD_VERSION 0x8B18CBD138A6BC84ull
|
||||
#define B3_HEIGHT_FIELD_VERSION 0x9FEE70DB5A860835ull
|
||||
|
||||
/// A height field with compressed storage.
|
||||
/// @note This data structure has data hanging off the end and cannot be directly copied.
|
||||
|
|
@ -2285,12 +2287,12 @@ typedef struct b3HeightFieldData
|
|||
/// Version must be first and match B3_HEIGHT_FIELD_VERSION
|
||||
uint64_t version;
|
||||
|
||||
/// Hash of this height field (this field is zero when the hash is computed).
|
||||
uint64_t hash;
|
||||
|
||||
/// The total number of bytes for this height field.
|
||||
int byteCount;
|
||||
|
||||
/// Hash of this height field (this field is zero when the hash is computed).
|
||||
uint32_t hash;
|
||||
|
||||
/// The local axis-aligned bounding box.
|
||||
b3AABB aabb;
|
||||
|
||||
|
|
@ -2307,29 +2309,28 @@ typedef struct b3HeightFieldData
|
|||
b3Vec3 scale;
|
||||
|
||||
/// The number of grid columns along the local x-axis.
|
||||
int columnCount;
|
||||
int32_t columnCount;
|
||||
|
||||
/// The number of grid rows along the local z-axis.
|
||||
int rowCount;
|
||||
int32_t rowCount;
|
||||
|
||||
/// Offset of the compressed height array in bytes from the struct address.
|
||||
/// uint16_t, one per grid point.
|
||||
int heightsOffset;
|
||||
int32_t heightsOffset;
|
||||
|
||||
/// Offset of the material index array in bytes from the struct address.
|
||||
/// uint8_t, one per cell.
|
||||
int materialOffset;
|
||||
int32_t materialOffset;
|
||||
|
||||
/// Offset of the flag array in bytes from the struct address.
|
||||
/// uint8_t, one per triangle.
|
||||
int flagsOffset;
|
||||
int32_t flagsOffset;
|
||||
|
||||
/// Triangle winding.
|
||||
bool clockwise;
|
||||
uint8_t clockwise;
|
||||
|
||||
/// Explicit padding. Identity is a content hash over raw bytes, so there must
|
||||
/// be no unnamed padding for struct copies to scramble.
|
||||
uint8_t padding[3];
|
||||
/// Explicit padding.
|
||||
uint8_t padding[7];
|
||||
} b3HeightFieldData;
|
||||
|
||||
/**@}*/ // height_field
|
||||
|
|
@ -2973,7 +2974,7 @@ typedef struct b3DebugShape
|
|||
typedef struct b3DebugDraw
|
||||
{
|
||||
/// Draws a user shape. The userShape pointer is owned by the application and is known to Box3D as
|
||||
/// an opaque pointer returned from b3CreateDebugShapeCallback. When this is called the drawn shape has
|
||||
/// an opaque pointer returned from b3CreateDebugShapeCallback. When this is called the drawn shape has
|
||||
/// passed a culling test against drawingBounds below.
|
||||
void ( *DrawShapeFcn )( void* userShape, b3WorldTransform transform, b3HexColor color, void* context );
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "gfx/qsort.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -301,7 +302,7 @@ static MeshHandle BuildHull( const b3HullData* hull )
|
|||
const b3Plane* planes = b3GetHullPlanes( hull );
|
||||
if ( !points || !edges || !faces || !planes )
|
||||
{
|
||||
fprintf( stderr, "error: hull missing arrays (hash=0x%08x)\n", hull->hash );
|
||||
fprintf( stderr, "error: hull missing arrays (hash=0x%016" PRIx64 ")\n", hull->hash );
|
||||
return InvalidMeshHandle();
|
||||
}
|
||||
|
||||
|
|
@ -330,7 +331,7 @@ static MeshHandle BuildHull( const b3HullData* hull )
|
|||
e = edges[e].next;
|
||||
if ( loopLen > 256 )
|
||||
{
|
||||
fprintf( stderr, "error: hull face loop runaway (hash=0x%08x)\n", hull->hash );
|
||||
fprintf( stderr, "error: hull face loop runaway (hash=0x%016" PRIx64 ")\n", hull->hash );
|
||||
BufferFree( &buf );
|
||||
return InvalidMeshHandle();
|
||||
}
|
||||
|
|
@ -426,7 +427,7 @@ static MeshHandle BuildMeshData( const b3MeshData* meshData )
|
|||
const uint8_t* flags = b3GetMeshFlags( meshData );
|
||||
if ( !verts || !tris || meshData->triangleCount <= 0 )
|
||||
{
|
||||
fprintf( stderr, "error: mesh missing arrays or empty (hash=0x%08x)\n", meshData->hash );
|
||||
fprintf( stderr, "error: mesh missing arrays or empty (hash=0x%016" PRIx64 ")\n", meshData->hash );
|
||||
return InvalidMeshHandle();
|
||||
}
|
||||
|
||||
|
|
@ -559,7 +560,7 @@ static MeshHandle BuildHeightField( const b3HeightFieldData* hf )
|
|||
{
|
||||
if ( hf->columnCount < 2 || hf->rowCount < 2 )
|
||||
{
|
||||
fprintf( stderr, "error: heightfield degenerate (hash=0x%08x)\n", hf->hash );
|
||||
fprintf( stderr, "error: heightfield degenerate (hash=0x%016" PRIx64 ")\n", hf->hash );
|
||||
return InvalidMeshHandle();
|
||||
}
|
||||
|
||||
|
|
@ -791,7 +792,7 @@ static MeshHandle BuildHeightField( const b3HeightFieldData* hf )
|
|||
|
||||
MeshHandle FindOrAddHull( const b3HullData* hull )
|
||||
{
|
||||
if ( !hull || hull->hash == 0u )
|
||||
if ( !hull || hull->hash == 0 )
|
||||
{
|
||||
return InvalidMeshHandle();
|
||||
}
|
||||
|
|
@ -808,7 +809,7 @@ MeshHandle FindOrAddHull( const b3HullData* hull )
|
|||
|
||||
MeshHandle FindOrAddMesh( const b3MeshData* meshData )
|
||||
{
|
||||
if ( !meshData || meshData->hash == 0u )
|
||||
if ( !meshData || meshData->hash == 0 )
|
||||
{
|
||||
return InvalidMeshHandle();
|
||||
}
|
||||
|
|
@ -825,7 +826,7 @@ MeshHandle FindOrAddMesh( const b3MeshData* meshData )
|
|||
|
||||
MeshHandle FindOrAddHeightField( const b3HeightFieldData* heightField )
|
||||
{
|
||||
if ( !heightField || heightField->hash == 0u )
|
||||
if ( !heightField || heightField->hash == 0 )
|
||||
{
|
||||
return InvalidMeshHandle();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
typedef struct Entry
|
||||
{
|
||||
uint32_t hash;
|
||||
uint64_t hash;
|
||||
int refCount; // 0 means free
|
||||
sg_buffer vbo;
|
||||
sg_buffer ibo;
|
||||
|
|
@ -164,7 +164,7 @@ void DestroyMeshRegistry( void )
|
|||
sg_destroy_buffer( s_geom.instBuf );
|
||||
}
|
||||
|
||||
MeshHandle FindMesh( uint32_t hash )
|
||||
MeshHandle FindMesh( uint64_t hash )
|
||||
{
|
||||
if ( hash == 0u )
|
||||
{
|
||||
|
|
@ -200,10 +200,10 @@ static int FindFreeSlot( void )
|
|||
return s_geom.entryCount++;
|
||||
}
|
||||
|
||||
MeshHandle RegisterMesh( uint32_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices,
|
||||
MeshHandle RegisterMesh( uint64_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices,
|
||||
int indexCount, const char* debugLabel )
|
||||
{
|
||||
assert( hash != 0u );
|
||||
assert( hash != 0 );
|
||||
assert( vertexCount > 0 );
|
||||
assert( indexCount > 0 );
|
||||
|
||||
|
|
@ -428,7 +428,7 @@ void ReleaseMeshReference( MeshHandle h )
|
|||
sg_destroy_view( e->edgeStorageView );
|
||||
sg_destroy_buffer( e->edgeBuf );
|
||||
}
|
||||
e->hash = 0u;
|
||||
e->hash = 0;
|
||||
e->indexCount = 0;
|
||||
e->edgeBuf.id = SG_INVALID_ID;
|
||||
e->edgeStorageView.id = SG_INVALID_ID;
|
||||
|
|
|
|||
|
|
@ -52,12 +52,12 @@ extern "C"
|
|||
typedef struct MeshHandle
|
||||
{
|
||||
int index; // -1 means invalid
|
||||
uint32_t hash; // for cheap validation against index reuse
|
||||
uint64_t hash; // for cheap validation against index reuse
|
||||
} MeshHandle;
|
||||
|
||||
static inline MeshHandle InvalidMeshHandle( void )
|
||||
{
|
||||
MeshHandle h = { -1, 0u };
|
||||
MeshHandle h = { -1, 0ull };
|
||||
return h;
|
||||
}
|
||||
|
||||
|
|
@ -142,9 +142,9 @@ typedef struct MeshXpInstance
|
|||
void CreateMeshRegistry( void );
|
||||
void DestroyMeshRegistry( void );
|
||||
|
||||
MeshHandle FindMesh( uint32_t hash );
|
||||
MeshHandle FindMesh( uint64_t hash );
|
||||
|
||||
MeshHandle RegisterMesh( uint32_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices,
|
||||
MeshHandle RegisterMesh( uint64_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices,
|
||||
int indexCount, const char* debugLabel );
|
||||
|
||||
// Optional: register an edge list for a geometry already registered via
|
||||
|
|
|
|||
|
|
@ -88,24 +88,12 @@ static struct
|
|||
sg_pipeline shadowGeomPipeline;
|
||||
sg_pipeline shadowGeomPipelineMirror;
|
||||
|
||||
// Shadow caster pipeline (sphere). The lit sphere pipeline is an
|
||||
// analytic impostor, too expensive for the shadow pass, so the
|
||||
// caster rasterizes a low-poly icosphere proxy generated at InitRenderer.
|
||||
// The icosphere vbo/ibo live here, the sphere instance buffer is
|
||||
// shared with the lit pipeline.
|
||||
sg_buffer icosphereVbuf;
|
||||
sg_buffer icosphereIbuf;
|
||||
int icosphereIndexCount;
|
||||
// Shadow caster pipelines (sphere, capsule). Both rasterize the same
|
||||
// bounding proxy the lit impostor uses and ray-cast the exact surface,
|
||||
// so they borrow the cube's vbuf/ibuf and share the lit pipeline's
|
||||
// instance buffers.
|
||||
sg_shader shadowSphereShader;
|
||||
sg_pipeline shadowSpherePipeline;
|
||||
|
||||
// Shadow caster pipeline (capsule). Cylinder-plus-caps proxy mesh
|
||||
// built once at InitRenderer, the capsule instance buffer is shared with
|
||||
// the lit pipeline. Per-vertex format is two vec3s: in_axis (scaled
|
||||
// by halfLength) + in_radial (scaled by radius).
|
||||
sg_buffer capsuleProxyVbuf;
|
||||
sg_buffer capsuleProxyIbuf;
|
||||
int capsuleProxyIndexCount;
|
||||
sg_shader shadowCapsuleShader;
|
||||
sg_pipeline shadowCapsulePipeline;
|
||||
|
||||
|
|
@ -254,307 +242,6 @@ static const uint16_t CUBE_INDICES[36] = {
|
|||
4, 5, 7, 4, 7, 6, // +Z
|
||||
};
|
||||
|
||||
// Ico-sphere shadow proxy
|
||||
// N-level subdivided ico-sphere built from a 12-vert icosahedron: each
|
||||
// subdivision step splits every face into 4 by inserting edge midpoints,
|
||||
// then renormalizes every new vertex to the unit sphere. After L levels:
|
||||
// verts = 10 * 4^L + 2, tris = 20 * 4^L. Built once at InitRenderer and uploaded
|
||||
// to dedicated vbuf/ibuf for the shadow_caster_sphere pipeline.
|
||||
//
|
||||
// We use L=2 (162 verts, 320 tris), subdiv-1 gave visibly polygonal
|
||||
// shadow silhouettes when the sun grazed a sphere, subdiv-2 reads as
|
||||
// round at any zoom we're likely to use. Subdiv-3 (1280 tris) is overkill.
|
||||
//
|
||||
// The icosahedron's golden-ratio coordinates produce a remarkably even
|
||||
// vertex distribution, better silhouette quality than a UV sphere
|
||||
// comparable triangle count.
|
||||
#define ICO_SPHERE_SUBDIV_LEVEL 2
|
||||
#define ICO_SPHERE_VERTICES 162 // 10 * 4^L + 2 for L=2
|
||||
#define ICO_SPHERE_INDICES ( 320 * 3 ) // 20 * 4^L for L=2
|
||||
|
||||
static void BuildIcosphere( float ( *outVerts )[3], uint32_t* outIndices )
|
||||
{
|
||||
const float phi = ( 1.0f + sqrtf( 5.0f ) ) * 0.5f;
|
||||
const float invLen = 1.0f / sqrtf( 1.0f + phi * phi );
|
||||
|
||||
// 12 icosahedron vertices, normalized to the unit sphere.
|
||||
const float baseVerts[12][3] = {
|
||||
{ -1.0f, phi, 0.0f }, { 1.0f, phi, 0.0f }, { -1.0f, -phi, 0.0f }, { 1.0f, -phi, 0.0f },
|
||||
{ 0.0f, -1.0f, phi }, { 0.0f, 1.0f, phi }, { 0.0f, -1.0f, -phi }, { 0.0f, 1.0f, -phi },
|
||||
{ phi, 0.0f, -1.0f }, { phi, 0.0f, 1.0f }, { -phi, 0.0f, -1.0f }, { -phi, 0.0f, 1.0f },
|
||||
};
|
||||
for ( int i = 0; i < 12; ++i )
|
||||
{
|
||||
outVerts[i][0] = baseVerts[i][0] * invLen;
|
||||
outVerts[i][1] = baseVerts[i][1] * invLen;
|
||||
outVerts[i][2] = baseVerts[i][2] * invLen;
|
||||
}
|
||||
|
||||
// 20 base faces, CCW from outside.
|
||||
static const uint32_t baseTris[20 * 3] = {
|
||||
0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
|
||||
3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1,
|
||||
};
|
||||
|
||||
// Ping-pong tri buffers. Each level reads `cur` and writes `nxt`, then
|
||||
// swaps. Static so the ~7.5 KB doesn't pressure the call-site stack.
|
||||
static uint32_t triA[ICO_SPHERE_INDICES];
|
||||
static uint32_t triB[ICO_SPHERE_INDICES];
|
||||
uint32_t* cur = triA;
|
||||
uint32_t* nxt = triB;
|
||||
int triCount = 20;
|
||||
for ( int i = 0; i < 20 * 3; ++i )
|
||||
cur[i] = baseTris[i];
|
||||
|
||||
int vertCount = 12;
|
||||
|
||||
// Edge midpoint cache, sized for the final vertex count. Each edge
|
||||
// the *current* tri set pairs exactly two faces, so a midpoint computed
|
||||
// for one face is reused by exactly one other. Cleared per level so
|
||||
// midpoint indices from earlier levels don't leak in. ~104 KB static.
|
||||
static int midCache[ICO_SPHERE_VERTICES][ICO_SPHERE_VERTICES];
|
||||
|
||||
for ( int L = 0; L < ICO_SPHERE_SUBDIV_LEVEL; ++L )
|
||||
{
|
||||
for ( int i = 0; i < ICO_SPHERE_VERTICES; ++i )
|
||||
{
|
||||
for ( int j = 0; j < ICO_SPHERE_VERTICES; ++j )
|
||||
{
|
||||
midCache[i][j] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int nxtCount = 0;
|
||||
for ( int t = 0; t < triCount; ++t )
|
||||
{
|
||||
const uint32_t v[3] = { cur[t * 3 + 0], cur[t * 3 + 1], cur[t * 3 + 2] };
|
||||
|
||||
uint32_t mid[3];
|
||||
for ( int e = 0; e < 3; ++e )
|
||||
{
|
||||
uint32_t a = v[e];
|
||||
uint32_t b = v[( e + 1 ) % 3];
|
||||
if ( a > b )
|
||||
{
|
||||
uint32_t tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
if ( midCache[a][b] < 0 )
|
||||
{
|
||||
const int index = vertCount++;
|
||||
float mx = 0.5f * ( outVerts[a][0] + outVerts[b][0] );
|
||||
float my = 0.5f * ( outVerts[a][1] + outVerts[b][1] );
|
||||
float mz = 0.5f * ( outVerts[a][2] + outVerts[b][2] );
|
||||
const float len = sqrtf( mx * mx + my * my + mz * mz );
|
||||
if ( len > 0.0f )
|
||||
{
|
||||
mx /= len;
|
||||
my /= len;
|
||||
mz /= len;
|
||||
}
|
||||
outVerts[index][0] = mx;
|
||||
outVerts[index][1] = my;
|
||||
outVerts[index][2] = mz;
|
||||
midCache[a][b] = index;
|
||||
}
|
||||
mid[e] = (uint32_t)midCache[a][b];
|
||||
}
|
||||
|
||||
// Subdivide one tri (v0,v1,v2) into four:
|
||||
// (v0, m01, m20), (v1, m12, m01), (v2, m20, m12), (m01, m12, m20).
|
||||
// mid[0] = m01, mid[1] = m12, mid[2] = m20.
|
||||
nxt[nxtCount++] = v[0];
|
||||
nxt[nxtCount++] = mid[0];
|
||||
nxt[nxtCount++] = mid[2];
|
||||
nxt[nxtCount++] = v[1];
|
||||
nxt[nxtCount++] = mid[1];
|
||||
nxt[nxtCount++] = mid[0];
|
||||
nxt[nxtCount++] = v[2];
|
||||
nxt[nxtCount++] = mid[2];
|
||||
nxt[nxtCount++] = mid[1];
|
||||
nxt[nxtCount++] = mid[0];
|
||||
nxt[nxtCount++] = mid[1];
|
||||
nxt[nxtCount++] = mid[2];
|
||||
}
|
||||
triCount = nxtCount / 3;
|
||||
uint32_t* tmp = cur;
|
||||
cur = nxt;
|
||||
nxt = tmp;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < triCount * 3; ++i )
|
||||
outIndices[i] = cur[i];
|
||||
}
|
||||
|
||||
// Capsule proxy for shadows
|
||||
// Lat/long mesh: CAPSULE_SLICES azimuthal slices around the long axis, a
|
||||
// cylinder body, and two hemispherical caps with CAPSULE_CAP_RINGS interior
|
||||
// latitude rings plus a pole each. Verts are encoded with two vec3s, in_axis
|
||||
// (scaled by halfLength) and in_radial (scaled by radius), so the same proxy
|
||||
// mesh works for any (halfLength, radius) pair.
|
||||
//
|
||||
// An inscribed facet mesh casts a shadow up to 1 - cos(halfAz) cos(halfLat)
|
||||
// too small and its outline shows the slices. Scaling the radial vectors so
|
||||
// facets straddle the true surface halves the max silhouette error, at 32
|
||||
// slices it lands under 0.5% of radius, below a cascade texel.
|
||||
//
|
||||
// Vertex layout:
|
||||
// - body ring -X, then body ring +X (these double as the caps' equators)
|
||||
// - +X cap: interior rings equator->pole order, then the pole
|
||||
// - -X cap: same
|
||||
//
|
||||
// Caps share their equator ring with the body's end ring, saves a ring of
|
||||
// verts per cap and avoids any seam in the depth render.
|
||||
#define CAPSULE_SLICES 32
|
||||
#define CAPSULE_CAP_RINGS 7
|
||||
#define CAPSULE_VERTICES ( 2 * CAPSULE_SLICES + 2 * ( CAPSULE_CAP_RINGS * CAPSULE_SLICES + 1 ) )
|
||||
#define CAPSULE_INDICES ( 12 * CAPSULE_SLICES * ( CAPSULE_CAP_RINGS + 1 ) )
|
||||
|
||||
typedef struct CapsuleVertex
|
||||
{
|
||||
float axis[3];
|
||||
float radial[3];
|
||||
} CapsuleVertex;
|
||||
|
||||
// Helper macro: emit two triangles for a quad with corners
|
||||
// bl, br, tr, tl (CCW outside-front).
|
||||
#define CAPSULE_QUAD( bl, br, tr, tl ) \
|
||||
do \
|
||||
{ \
|
||||
outIndices[index++] = (uint32_t)( bl ); \
|
||||
outIndices[index++] = (uint32_t)( br ); \
|
||||
outIndices[index++] = (uint32_t)( tr ); \
|
||||
outIndices[index++] = (uint32_t)( bl ); \
|
||||
outIndices[index++] = (uint32_t)( tr ); \
|
||||
outIndices[index++] = (uint32_t)( tl ); \
|
||||
} \
|
||||
while ( 0 )
|
||||
|
||||
static void BuildCapsuleProxy( CapsuleVertex* outVerts, uint32_t* outIndices )
|
||||
{
|
||||
const float TWO_PI = 6.28318530717958647692f;
|
||||
|
||||
// Quad centers of an inscribed lat/long mesh dip below the true surface
|
||||
// by cos(halfAz) cos(halfLat). Scale all radials so facets straddle the
|
||||
// surface, halving the max silhouette error. Uniform scale keeps the
|
||||
// proxy a true capsule of radius scale * r, no seam at the equators.
|
||||
const float halfAz = B3_PI / (float)CAPSULE_SLICES;
|
||||
const float halfLat = 0.25f * B3_PI / (float)( CAPSULE_CAP_RINGS + 1 );
|
||||
const float scale = 2.0f / ( 1.0f + cosf( halfAz ) * cosf( halfLat ) );
|
||||
|
||||
// Vertices
|
||||
int v = 0;
|
||||
// Body rings, -X then +X. These double as the caps' equators.
|
||||
for ( int side = 0; side < 2; ++side )
|
||||
{
|
||||
const float sx = ( side == 0 ) ? -1.0f : +1.0f;
|
||||
for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v )
|
||||
{
|
||||
const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES;
|
||||
outVerts[v].axis[0] = sx;
|
||||
outVerts[v].axis[1] = 0.0f;
|
||||
outVerts[v].axis[2] = 0.0f;
|
||||
outVerts[v].radial[0] = 0.0f;
|
||||
outVerts[v].radial[1] = scale * cosf( beta );
|
||||
outVerts[v].radial[2] = scale * sinf( beta );
|
||||
}
|
||||
}
|
||||
// Caps, +X then -X: interior latitude rings equator->pole, then the pole.
|
||||
// Ring r sits at latitude alpha = r * (pi/2) / (rings + 1).
|
||||
for ( int side = 0; side < 2; ++side )
|
||||
{
|
||||
const float sx = ( side == 0 ) ? +1.0f : -1.0f;
|
||||
for ( int r = 1; r <= CAPSULE_CAP_RINGS; ++r )
|
||||
{
|
||||
const float alpha = 0.5f * B3_PI * (float)r / (float)( CAPSULE_CAP_RINGS + 1 );
|
||||
for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v )
|
||||
{
|
||||
const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES;
|
||||
outVerts[v].axis[0] = sx;
|
||||
outVerts[v].axis[1] = 0.0f;
|
||||
outVerts[v].axis[2] = 0.0f;
|
||||
outVerts[v].radial[0] = scale * sx * sinf( alpha );
|
||||
outVerts[v].radial[1] = scale * cosf( alpha ) * cosf( beta );
|
||||
outVerts[v].radial[2] = scale * cosf( alpha ) * sinf( beta );
|
||||
}
|
||||
}
|
||||
outVerts[v].axis[0] = sx;
|
||||
outVerts[v].axis[1] = 0.0f;
|
||||
outVerts[v].axis[2] = 0.0f;
|
||||
outVerts[v].radial[0] = scale * sx;
|
||||
outVerts[v].radial[1] = 0.0f;
|
||||
outVerts[v].radial[2] = 0.0f;
|
||||
++v;
|
||||
}
|
||||
|
||||
// Indices
|
||||
int index = 0;
|
||||
|
||||
// Body: ring -X to ring +X. For slice i and i+1, the outward face winds
|
||||
// from -X[i] up the slice direction (beta increasing) to -X[i+1], across
|
||||
// to +X[i+1], down to +X[i].
|
||||
for ( int i = 0; i < CAPSULE_SLICES; ++i )
|
||||
{
|
||||
const int next = ( i + 1 ) % CAPSULE_SLICES;
|
||||
CAPSULE_QUAD( i, next, CAPSULE_SLICES + next, CAPSULE_SLICES + i );
|
||||
}
|
||||
|
||||
// +X cap: quad bands march outward from the equator (the +X body ring)
|
||||
// through the latitude rings, then a fan to the pole. Going outward the
|
||||
// face winds prev[i] -> prev[i+1] -> cur[i+1] -> cur[i].
|
||||
{
|
||||
int prev = CAPSULE_SLICES;
|
||||
int cur = 2 * CAPSULE_SLICES;
|
||||
for ( int r = 0; r < CAPSULE_CAP_RINGS; ++r )
|
||||
{
|
||||
for ( int i = 0; i < CAPSULE_SLICES; ++i )
|
||||
{
|
||||
const int next = ( i + 1 ) % CAPSULE_SLICES;
|
||||
CAPSULE_QUAD( prev + i, prev + next, cur + next, cur + i );
|
||||
}
|
||||
prev = cur;
|
||||
cur += CAPSULE_SLICES;
|
||||
}
|
||||
const int pole = cur;
|
||||
for ( int i = 0; i < CAPSULE_SLICES; ++i )
|
||||
{
|
||||
const int next = ( i + 1 ) % CAPSULE_SLICES;
|
||||
outIndices[index++] = (uint32_t)( prev + i );
|
||||
outIndices[index++] = (uint32_t)( prev + next );
|
||||
outIndices[index++] = (uint32_t)pole;
|
||||
}
|
||||
}
|
||||
|
||||
// -X cap: winding flipped relative to +X because the outward normal
|
||||
// points toward -X, the "outside-front" side of each quad swaps slice
|
||||
// order.
|
||||
{
|
||||
int prev = 0;
|
||||
int cur = 2 * CAPSULE_SLICES + CAPSULE_CAP_RINGS * CAPSULE_SLICES + 1;
|
||||
for ( int r = 0; r < CAPSULE_CAP_RINGS; ++r )
|
||||
{
|
||||
for ( int i = 0; i < CAPSULE_SLICES; ++i )
|
||||
{
|
||||
const int next = ( i + 1 ) % CAPSULE_SLICES;
|
||||
CAPSULE_QUAD( prev + next, prev + i, cur + i, cur + next );
|
||||
}
|
||||
prev = cur;
|
||||
cur += CAPSULE_SLICES;
|
||||
}
|
||||
const int pole = cur;
|
||||
for ( int i = 0; i < CAPSULE_SLICES; ++i )
|
||||
{
|
||||
const int next = ( i + 1 ) % CAPSULE_SLICES;
|
||||
outIndices[index++] = (uint32_t)( prev + next );
|
||||
outIndices[index++] = (uint32_t)( prev + i );
|
||||
outIndices[index++] = (uint32_t)pole;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef CAPSULE_QUAD
|
||||
|
||||
// On the GL backend, set clip-space Z to [0,1] so the rasterizer's
|
||||
// gl_FragCoord.z matches what the impostor shaders write into gl_FragDepth
|
||||
// (hit_clip.z / hit_clip.w). Default GL clip space is [-1,1], remapped by
|
||||
|
|
@ -888,30 +575,10 @@ void InitRenderer( const sg_environment* env )
|
|||
s_gfx.shadowGeomPipelineMirror = sg_make_pipeline( &shadowGeomMirrorPdesc );
|
||||
|
||||
// Shadow caster pipeline: spheres
|
||||
// Build the ico-sphere proxy once and upload to a
|
||||
// dedicated vbo/ibo. Position-only vertex layout (no normals, the
|
||||
// caster shader never reads them).
|
||||
{
|
||||
float icoVerts[ICO_SPHERE_VERTICES][3];
|
||||
uint32_t icoIndices[ICO_SPHERE_INDICES];
|
||||
BuildIcosphere( icoVerts, icoIndices );
|
||||
s_gfx.icosphereIndexCount = ICO_SPHERE_INDICES;
|
||||
|
||||
sg_buffer_desc ivdesc = { 0 };
|
||||
ivdesc.usage.vertex_buffer = true;
|
||||
ivdesc.data.ptr = icoVerts;
|
||||
ivdesc.data.size = sizeof( icoVerts );
|
||||
ivdesc.label = "icosphere_verts";
|
||||
s_gfx.icosphereVbuf = sg_make_buffer( &ivdesc );
|
||||
|
||||
sg_buffer_desc iidesc = { 0 };
|
||||
iidesc.usage.index_buffer = true;
|
||||
iidesc.data.ptr = icoIndices;
|
||||
iidesc.data.size = sizeof( icoIndices );
|
||||
iidesc.label = "icosphere_indices";
|
||||
s_gfx.icosphereIbuf = sg_make_buffer( &iidesc );
|
||||
}
|
||||
|
||||
// Rasterizes the bounding cube the lit impostor uses, so it borrows the
|
||||
// cube's buffers and vertex format. Culling stays on back faces: the
|
||||
// shader's conservative-depth promise only holds while the rasterized
|
||||
// surface is the light-facing one.
|
||||
s_gfx.shadowSphereShader = sg_make_shader( shadow_sphere_caster_shader_desc( sg_query_backend() ) );
|
||||
|
||||
sg_pipeline_desc shadowSpherePdesc = { 0 };
|
||||
|
|
@ -919,7 +586,7 @@ void InitRenderer( const sg_environment* env )
|
|||
shadowSpherePdesc.layout.buffers[0].stride = sizeof( float ) * 3;
|
||||
shadowSpherePdesc.layout.attrs[ATTR_shadow_sphere_caster_in_pos].format = SG_VERTEXFORMAT_FLOAT3;
|
||||
shadowSpherePdesc.layout.attrs[ATTR_shadow_sphere_caster_in_pos].buffer_index = 0;
|
||||
shadowSpherePdesc.index_type = SG_INDEXTYPE_UINT32;
|
||||
shadowSpherePdesc.index_type = SG_INDEXTYPE_UINT16;
|
||||
shadowSpherePdesc.colors[0].pixel_format = SG_PIXELFORMAT_NONE;
|
||||
shadowSpherePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH;
|
||||
shadowSpherePdesc.depth.compare = SG_COMPAREFUNC_LESS;
|
||||
|
|
@ -930,40 +597,16 @@ void InitRenderer( const sg_environment* env )
|
|||
shadowSpherePdesc.label = "shadow_sphere_pipeline";
|
||||
s_gfx.shadowSpherePipeline = sg_make_pipeline( &shadowSpherePdesc );
|
||||
|
||||
// Shadow caster pipeline: capsules
|
||||
{
|
||||
CapsuleVertex capsVerts[CAPSULE_VERTICES];
|
||||
uint32_t capsIndices[CAPSULE_INDICES];
|
||||
BuildCapsuleProxy( capsVerts, capsIndices );
|
||||
s_gfx.capsuleProxyIndexCount = CAPSULE_INDICES;
|
||||
|
||||
sg_buffer_desc cvdesc = { 0 };
|
||||
cvdesc.usage.vertex_buffer = true;
|
||||
cvdesc.data.ptr = capsVerts;
|
||||
cvdesc.data.size = sizeof( capsVerts );
|
||||
cvdesc.label = "capsule_proxy_verts";
|
||||
s_gfx.capsuleProxyVbuf = sg_make_buffer( &cvdesc );
|
||||
|
||||
sg_buffer_desc cidesc = { 0 };
|
||||
cidesc.usage.index_buffer = true;
|
||||
cidesc.data.ptr = capsIndices;
|
||||
cidesc.data.size = sizeof( capsIndices );
|
||||
cidesc.label = "capsule_proxy_indices";
|
||||
s_gfx.capsuleProxyIbuf = sg_make_buffer( &cidesc );
|
||||
}
|
||||
|
||||
// Shadow caster pipeline: capsules, see the sphere caster above. The
|
||||
// OBB comes from the same cube buffers.
|
||||
s_gfx.shadowCapsuleShader = sg_make_shader( shadow_capsule_caster_shader_desc( sg_query_backend() ) );
|
||||
|
||||
sg_pipeline_desc shadowCapsulePdesc = { 0 };
|
||||
shadowCapsulePdesc.shader = s_gfx.shadowCapsuleShader;
|
||||
shadowCapsulePdesc.layout.buffers[0].stride = sizeof( float ) * 6;
|
||||
shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_axis].format = SG_VERTEXFORMAT_FLOAT3;
|
||||
shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_axis].buffer_index = 0;
|
||||
shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_axis].offset = 0;
|
||||
shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_radial].format = SG_VERTEXFORMAT_FLOAT3;
|
||||
shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_radial].buffer_index = 0;
|
||||
shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_radial].offset = sizeof( float ) * 3;
|
||||
shadowCapsulePdesc.index_type = SG_INDEXTYPE_UINT32;
|
||||
shadowCapsulePdesc.layout.buffers[0].stride = sizeof( float ) * 3;
|
||||
shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_pos].format = SG_VERTEXFORMAT_FLOAT3;
|
||||
shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_pos].buffer_index = 0;
|
||||
shadowCapsulePdesc.index_type = SG_INDEXTYPE_UINT16;
|
||||
shadowCapsulePdesc.colors[0].pixel_format = SG_PIXELFORMAT_NONE;
|
||||
shadowCapsulePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH;
|
||||
shadowCapsulePdesc.depth.compare = SG_COMPAREFUNC_LESS;
|
||||
|
|
@ -1291,6 +934,35 @@ static b3Vec3 TransformDir( Mat4 m, b3Vec3 v )
|
|||
return (b3Vec3){ r.x, r.y, r.z };
|
||||
}
|
||||
|
||||
// The lit shaders carry their own SHADOW_CASCADE_COUNT, and nothing links it
|
||||
// to the one here. Check the generated layout instead, so a half-finished
|
||||
// change is a build error rather than a cascade that silently never receives
|
||||
// its matrix, or a fill loop that runs off the end of the array into the
|
||||
// uniforms behind it. Every shader that takes cascades needs its own check,
|
||||
// since they are generated one at a time. Tripping this means regenerating
|
||||
// the shaders.
|
||||
_Static_assert( sizeof( ( (ub_pass_t*)0 )->cascade_matrices ) / sizeof( Mat4 ) == SHADOW_CASCADE_COUNT,
|
||||
"cube shader cascade count differs from SHADOW_CASCADE_COUNT" );
|
||||
_Static_assert( sizeof( ( (sphere_ub_pass_t*)0 )->cascade_matrices ) / sizeof( Mat4 ) == SHADOW_CASCADE_COUNT,
|
||||
"sphere shader cascade count differs from SHADOW_CASCADE_COUNT" );
|
||||
_Static_assert( sizeof( ( (capsule_ub_pass_t*)0 )->cascade_matrices ) / sizeof( Mat4 ) == SHADOW_CASCADE_COUNT,
|
||||
"capsule shader cascade count differs from SHADOW_CASCADE_COUNT" );
|
||||
_Static_assert( sizeof( ( (geom_ub_pass_t*)0 )->cascade_matrices ) / sizeof( Mat4 ) == SHADOW_CASCADE_COUNT,
|
||||
"geom shader cascade count differs from SHADOW_CASCADE_COUNT" );
|
||||
|
||||
// One vec4 lane per cascade, which is what caps the count at four. Lanes past
|
||||
// the count stay zero, so a shader built for more would read unlit rather than
|
||||
// garbage.
|
||||
static Vec4 PackCascades( float ( *get )( int cascade ) )
|
||||
{
|
||||
float lanes[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
{
|
||||
lanes[i] = get( i );
|
||||
}
|
||||
return MakeVec4( lanes[0], lanes[1], lanes[2], lanes[3] );
|
||||
}
|
||||
|
||||
static sg_pass_action MakeSceneClear( void )
|
||||
{
|
||||
sg_pass_action a = { 0 };
|
||||
|
|
@ -1366,6 +1038,17 @@ static void DrawShadowCascade( int cascade )
|
|||
const Mat4 lightVP = GetCascadeMatrix( cascade );
|
||||
bool viewportApplied = false;
|
||||
|
||||
// Impostor casters march along the light from the proxy face they
|
||||
// rasterized, then turn the hit into clip depth themselves. Both
|
||||
// quantities come out of the projection's depth row, which under an
|
||||
// orthographic light varies only along the light axis: its gradient
|
||||
// is the direction light travels, and it is the row that maps a
|
||||
// world position to depth. Reading the direction back off the matrix
|
||||
// rather than off the sun keeps the two from drifting apart.
|
||||
const Vec4 lightDepthRow = MakeVec4( lightVP.cx.z, lightVP.cy.z, lightVP.cz.z, lightVP.cw.z );
|
||||
const b3Vec3 lightDir = b3Normalize( ( b3Vec3 ){ lightDepthRow.x, lightDepthRow.y, lightDepthRow.z } );
|
||||
const Vec4 lightDirPacked = MakeVec4( lightDir.x, lightDir.y, lightDir.z, 0.0f );
|
||||
|
||||
// Cubes
|
||||
if ( s_gfx.cubeCount > 0 )
|
||||
{
|
||||
|
|
@ -1392,7 +1075,7 @@ static void DrawShadowCascade( int cascade )
|
|||
sg_pop_debug_group();
|
||||
}
|
||||
|
||||
// Spheres (low-poly icosphere proxy)
|
||||
// Spheres
|
||||
if ( s_gfx.sphereCount > 0 )
|
||||
{
|
||||
sg_push_debug_group( "caster_sphere" );
|
||||
|
|
@ -1403,22 +1086,26 @@ static void DrawShadowCascade( int cascade )
|
|||
}
|
||||
sg_apply_pipeline( s_gfx.shadowSpherePipeline );
|
||||
sg_bindings bindings = { 0 };
|
||||
bindings.vertex_buffers[0] = s_gfx.icosphereVbuf;
|
||||
bindings.index_buffer = s_gfx.icosphereIbuf;
|
||||
bindings.vertex_buffers[0] = s_gfx.vbuf;
|
||||
bindings.index_buffer = s_gfx.ibuf;
|
||||
bindings.views[VIEW_shadow_sphere_instances] = s_gfx.sphereInstView;
|
||||
sg_apply_bindings( &bindings );
|
||||
|
||||
shadow_sphere_ub_frame_t sub = { 0 };
|
||||
sub.light_view_proj = lightVP;
|
||||
sg_apply_uniforms( UB_shadow_sphere_ub_frame, &SG_RANGE( sub ) );
|
||||
shadow_sphere_ub_pass_t supass = { 0 };
|
||||
supass.light_dir = lightDirPacked;
|
||||
supass.depth_row = lightDepthRow;
|
||||
sg_apply_uniforms( UB_shadow_sphere_ub_pass, &SG_RANGE( supass ) );
|
||||
shadow_sphere_ub_draw_t sudraw = { 0 };
|
||||
sg_apply_uniforms( UB_shadow_sphere_ub_draw, &SG_RANGE( sudraw ) );
|
||||
|
||||
sg_draw( 0, s_gfx.icosphereIndexCount, (int)s_gfx.sphereCount );
|
||||
sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.sphereCount );
|
||||
sg_pop_debug_group();
|
||||
}
|
||||
|
||||
// Capsules (cylinder + caps proxy)
|
||||
// Capsules
|
||||
if ( s_gfx.capsuleCount > 0 )
|
||||
{
|
||||
sg_push_debug_group( "caster_capsule" );
|
||||
|
|
@ -1429,18 +1116,22 @@ static void DrawShadowCascade( int cascade )
|
|||
}
|
||||
sg_apply_pipeline( s_gfx.shadowCapsulePipeline );
|
||||
sg_bindings bindings = { 0 };
|
||||
bindings.vertex_buffers[0] = s_gfx.capsuleProxyVbuf;
|
||||
bindings.index_buffer = s_gfx.capsuleProxyIbuf;
|
||||
bindings.vertex_buffers[0] = s_gfx.vbuf;
|
||||
bindings.index_buffer = s_gfx.ibuf;
|
||||
bindings.views[VIEW_shadow_capsule_instances] = s_gfx.capsuleInstView;
|
||||
sg_apply_bindings( &bindings );
|
||||
|
||||
shadow_capsule_ub_frame_t cub = { 0 };
|
||||
cub.light_view_proj = lightVP;
|
||||
sg_apply_uniforms( UB_shadow_capsule_ub_frame, &SG_RANGE( cub ) );
|
||||
shadow_capsule_ub_pass_t cupass = { 0 };
|
||||
cupass.light_dir = lightDirPacked;
|
||||
cupass.depth_row = lightDepthRow;
|
||||
sg_apply_uniforms( UB_shadow_capsule_ub_pass, &SG_RANGE( cupass ) );
|
||||
shadow_capsule_ub_draw_t cudraw = { 0 };
|
||||
sg_apply_uniforms( UB_shadow_capsule_ub_draw, &SG_RANGE( cudraw ) );
|
||||
|
||||
sg_draw( 0, s_gfx.capsuleProxyIndexCount, (int)s_gfx.capsuleCount );
|
||||
sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.capsuleCount );
|
||||
sg_pop_debug_group();
|
||||
}
|
||||
|
||||
|
|
@ -1539,14 +1230,18 @@ static void DrawShadowCascade( int cascade )
|
|||
}
|
||||
sg_apply_pipeline( s_gfx.shadowSpherePipeline );
|
||||
sg_bindings bindings = { 0 };
|
||||
bindings.vertex_buffers[0] = s_gfx.icosphereVbuf;
|
||||
bindings.index_buffer = s_gfx.icosphereIbuf;
|
||||
bindings.vertex_buffers[0] = s_gfx.vbuf;
|
||||
bindings.index_buffer = s_gfx.ibuf;
|
||||
bindings.views[VIEW_shadow_sphere_instances] = s_gfx.sphereInstViewXp;
|
||||
sg_apply_bindings( &bindings );
|
||||
|
||||
shadow_sphere_ub_frame_t sub = { 0 };
|
||||
sub.light_view_proj = lightVP;
|
||||
sg_apply_uniforms( UB_shadow_sphere_ub_frame, &SG_RANGE( sub ) );
|
||||
shadow_sphere_ub_pass_t supass = { 0 };
|
||||
supass.light_dir = lightDirPacked;
|
||||
supass.depth_row = lightDepthRow;
|
||||
sg_apply_uniforms( UB_shadow_sphere_ub_pass, &SG_RANGE( supass ) );
|
||||
|
||||
for ( size_t i = 0; i < s_gfx.sphereCountXp; ++i )
|
||||
{
|
||||
|
|
@ -1555,7 +1250,7 @@ static void DrawShadowCascade( int cascade )
|
|||
shadow_sphere_ub_draw_t sudraw = { 0 };
|
||||
sudraw.inst_base[0] = (int)i;
|
||||
sg_apply_uniforms( UB_shadow_sphere_ub_draw, &SG_RANGE( sudraw ) );
|
||||
sg_draw( 0, s_gfx.icosphereIndexCount, 1 );
|
||||
sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), 1 );
|
||||
}
|
||||
sg_pop_debug_group();
|
||||
}
|
||||
|
|
@ -1570,14 +1265,18 @@ static void DrawShadowCascade( int cascade )
|
|||
}
|
||||
sg_apply_pipeline( s_gfx.shadowCapsulePipeline );
|
||||
sg_bindings bindings = { 0 };
|
||||
bindings.vertex_buffers[0] = s_gfx.capsuleProxyVbuf;
|
||||
bindings.index_buffer = s_gfx.capsuleProxyIbuf;
|
||||
bindings.vertex_buffers[0] = s_gfx.vbuf;
|
||||
bindings.index_buffer = s_gfx.ibuf;
|
||||
bindings.views[VIEW_shadow_capsule_instances] = s_gfx.capsuleInstViewXp;
|
||||
sg_apply_bindings( &bindings );
|
||||
|
||||
shadow_capsule_ub_frame_t cub = { 0 };
|
||||
cub.light_view_proj = lightVP;
|
||||
sg_apply_uniforms( UB_shadow_capsule_ub_frame, &SG_RANGE( cub ) );
|
||||
shadow_capsule_ub_pass_t cupass = { 0 };
|
||||
cupass.light_dir = lightDirPacked;
|
||||
cupass.depth_row = lightDepthRow;
|
||||
sg_apply_uniforms( UB_shadow_capsule_ub_pass, &SG_RANGE( cupass ) );
|
||||
|
||||
for ( size_t i = 0; i < s_gfx.capsuleCountXp; ++i )
|
||||
{
|
||||
|
|
@ -1586,7 +1285,7 @@ static void DrawShadowCascade( int cascade )
|
|||
shadow_capsule_ub_draw_t cudraw = { 0 };
|
||||
cudraw.inst_base[0] = (int)i;
|
||||
sg_apply_uniforms( UB_shadow_capsule_ub_draw, &SG_RANGE( cudraw ) );
|
||||
sg_draw( 0, s_gfx.capsuleProxyIndexCount, 1 );
|
||||
sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), 1 );
|
||||
}
|
||||
sg_pop_debug_group();
|
||||
}
|
||||
|
|
@ -1669,10 +1368,12 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram
|
|||
// flip). The shader multiplies NDC.y by this before mapping to UV.y.
|
||||
const sg_backend backend = sg_query_backend();
|
||||
const float uvYSign = ( backend == SG_BACKEND_GLCORE || backend == SG_BACKEND_GLES3 ) ? 1.0f : -1.0f;
|
||||
const Vec4 cascadeFarViewZ = MakeVec4( GetCascadeFarViewZ( 0 ), GetCascadeFarViewZ( 1 ), GetCascadeFarViewZ( 2 ), uvYSign );
|
||||
const Vec4 cascadePcfScale = MakeVec4( GetCascadePcfScale( 0 ), GetCascadePcfScale( 1 ), GetCascadePcfScale( 2 ), 0.0f );
|
||||
Mat4 cascadeMatrices[3];
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
const Vec4 shadowParams = MakeVec4( uvYSign, GetShadowTexelSize(), 0.0f, 0.0f );
|
||||
const Vec4 cascadeFarViewZ = PackCascades( GetCascadeFarViewZ );
|
||||
const Vec4 cascadeTexelWorld = PackCascades( GetCascadeTexelWorld );
|
||||
const Vec4 cascadeDepthBias = PackCascades( GetCascadeDepthBias );
|
||||
Mat4 cascadeMatrices[SHADOW_CASCADE_COUNT];
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
{
|
||||
cascadeMatrices[i] = GetCascadeMatrix( i );
|
||||
}
|
||||
|
|
@ -1716,8 +1417,10 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram
|
|||
up.sun_color = sunColor;
|
||||
up.flags[0] = frame->debugMode;
|
||||
up.cascade_far_view_z = cascadeFarViewZ;
|
||||
up.cascade_pcf_scale = cascadePcfScale;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
up.cascade_texel_world = cascadeTexelWorld;
|
||||
up.cascade_depth_bias = cascadeDepthBias;
|
||||
up.shadow_params = shadowParams;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
up.cascade_matrices[i] = cascadeMatrices[i];
|
||||
up.view = frame->view;
|
||||
up.camera_pos_world = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f );
|
||||
|
|
@ -1765,8 +1468,10 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram
|
|||
sup.view_proj = viewProj;
|
||||
sup.view = frame->view;
|
||||
sup.cascade_far_view_z = cascadeFarViewZ;
|
||||
sup.cascade_pcf_scale = cascadePcfScale;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
sup.cascade_texel_world = cascadeTexelWorld;
|
||||
sup.cascade_depth_bias = cascadeDepthBias;
|
||||
sup.shadow_params = shadowParams;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
sup.cascade_matrices[i] = cascadeMatrices[i];
|
||||
for ( int i = 0; i < 9; ++i )
|
||||
{
|
||||
|
|
@ -1809,8 +1514,10 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram
|
|||
cup.view_proj = viewProj;
|
||||
cup.view = frame->view;
|
||||
cup.cascade_far_view_z = cascadeFarViewZ;
|
||||
cup.cascade_pcf_scale = cascadePcfScale;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
cup.cascade_texel_world = cascadeTexelWorld;
|
||||
cup.cascade_depth_bias = cascadeDepthBias;
|
||||
cup.shadow_params = shadowParams;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
cup.cascade_matrices[i] = cascadeMatrices[i];
|
||||
for ( int i = 0; i < 9; ++i )
|
||||
{
|
||||
|
|
@ -1862,8 +1569,10 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram
|
|||
gup.grid_offset = MakeVec4( frame->gridWrap.x, frame->gridWrap.y, frame->drawOrigin.x, frame->drawOrigin.z );
|
||||
gup.view = frame->view;
|
||||
gup.cascade_far_view_z = cascadeFarViewZ;
|
||||
gup.cascade_pcf_scale = cascadePcfScale;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
gup.cascade_texel_world = cascadeTexelWorld;
|
||||
gup.cascade_depth_bias = cascadeDepthBias;
|
||||
gup.shadow_params = shadowParams;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
gup.cascade_matrices[i] = cascadeMatrices[i];
|
||||
for ( int i = 0; i < 9; ++i )
|
||||
{
|
||||
|
|
@ -2272,10 +1981,12 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput*
|
|||
|
||||
const sg_backend backend = sg_query_backend();
|
||||
const float uvYSign = ( backend == SG_BACKEND_GLCORE || backend == SG_BACKEND_GLES3 ) ? 1.0f : -1.0f;
|
||||
const Vec4 cascadeFarViewZ = MakeVec4( GetCascadeFarViewZ( 0 ), GetCascadeFarViewZ( 1 ), GetCascadeFarViewZ( 2 ), uvYSign );
|
||||
const Vec4 cascadePcfScale = MakeVec4( GetCascadePcfScale( 0 ), GetCascadePcfScale( 1 ), GetCascadePcfScale( 2 ), 0.0f );
|
||||
Mat4 cascadeMatrices[3];
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
const Vec4 shadowParams = MakeVec4( uvYSign, GetShadowTexelSize(), 0.0f, 0.0f );
|
||||
const Vec4 cascadeFarViewZ = PackCascades( GetCascadeFarViewZ );
|
||||
const Vec4 cascadeTexelWorld = PackCascades( GetCascadeTexelWorld );
|
||||
const Vec4 cascadeDepthBias = PackCascades( GetCascadeDepthBias );
|
||||
Mat4 cascadeMatrices[SHADOW_CASCADE_COUNT];
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
{
|
||||
cascadeMatrices[i] = GetCascadeMatrix( i );
|
||||
}
|
||||
|
|
@ -2308,8 +2019,10 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput*
|
|||
cubePass.sun_color = sunColor;
|
||||
cubePass.flags[0] = frame->debugMode;
|
||||
cubePass.cascade_far_view_z = cascadeFarViewZ;
|
||||
cubePass.cascade_pcf_scale = cascadePcfScale;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
cubePass.cascade_texel_world = cascadeTexelWorld;
|
||||
cubePass.cascade_depth_bias = cascadeDepthBias;
|
||||
cubePass.shadow_params = shadowParams;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
{
|
||||
cubePass.cascade_matrices[i] = cascadeMatrices[i];
|
||||
}
|
||||
|
|
@ -2331,8 +2044,10 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput*
|
|||
spherePass.view_proj = view_proj;
|
||||
spherePass.view = frame->view;
|
||||
spherePass.cascade_far_view_z = cascadeFarViewZ;
|
||||
spherePass.cascade_pcf_scale = cascadePcfScale;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
spherePass.cascade_texel_world = cascadeTexelWorld;
|
||||
spherePass.cascade_depth_bias = cascadeDepthBias;
|
||||
spherePass.shadow_params = shadowParams;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
spherePass.cascade_matrices[i] = cascadeMatrices[i];
|
||||
for ( int i = 0; i < 9; ++i )
|
||||
spherePass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f );
|
||||
|
|
@ -2348,8 +2063,10 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput*
|
|||
capsulePass.view_proj = view_proj;
|
||||
capsulePass.view = frame->view;
|
||||
capsulePass.cascade_far_view_z = cascadeFarViewZ;
|
||||
capsulePass.cascade_pcf_scale = cascadePcfScale;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
capsulePass.cascade_texel_world = cascadeTexelWorld;
|
||||
capsulePass.cascade_depth_bias = cascadeDepthBias;
|
||||
capsulePass.shadow_params = shadowParams;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
capsulePass.cascade_matrices[i] = cascadeMatrices[i];
|
||||
for ( int i = 0; i < 9; ++i )
|
||||
capsulePass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f );
|
||||
|
|
@ -2366,8 +2083,10 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput*
|
|||
geomPass.grid_offset = MakeVec4( frame->gridWrap.x, frame->gridWrap.y, frame->drawOrigin.x, frame->drawOrigin.z );
|
||||
geomPass.view = frame->view;
|
||||
geomPass.cascade_far_view_z = cascadeFarViewZ;
|
||||
geomPass.cascade_pcf_scale = cascadePcfScale;
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
geomPass.cascade_texel_world = cascadeTexelWorld;
|
||||
geomPass.cascade_depth_bias = cascadeDepthBias;
|
||||
geomPass.shadow_params = shadowParams;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
geomPass.cascade_matrices[i] = cascadeMatrices[i];
|
||||
for ( int i = 0; i < 9; ++i )
|
||||
geomPass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f );
|
||||
|
|
@ -2870,12 +2589,8 @@ void ShutdownRenderer( void )
|
|||
ShutdownSky();
|
||||
sg_destroy_pipeline( s_gfx.shadowCapsulePipeline );
|
||||
sg_destroy_shader( s_gfx.shadowCapsuleShader );
|
||||
sg_destroy_buffer( s_gfx.capsuleProxyIbuf );
|
||||
sg_destroy_buffer( s_gfx.capsuleProxyVbuf );
|
||||
sg_destroy_pipeline( s_gfx.shadowSpherePipeline );
|
||||
sg_destroy_shader( s_gfx.shadowSphereShader );
|
||||
sg_destroy_buffer( s_gfx.icosphereIbuf );
|
||||
sg_destroy_buffer( s_gfx.icosphereVbuf );
|
||||
sg_destroy_pipeline( s_gfx.shadowGeomPipelineMirror );
|
||||
sg_destroy_pipeline( s_gfx.shadowGeomPipeline );
|
||||
sg_destroy_shader( s_gfx.shadowGeomShader );
|
||||
|
|
|
|||
|
|
@ -3,44 +3,52 @@
|
|||
|
||||
#include "gfx/shadow.h"
|
||||
|
||||
#include "gfx/draw.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Cascade fitting parameters. SHADOW_SPLIT_NEAR and the default far
|
||||
// (SHADOW_SPLIT_FAR, in shadow.h) are *view-space* distances from the camera
|
||||
// Cascade fitting parameters. The split range defaults (SHADOW_SPLIT_NEAR /
|
||||
// SHADOW_SPLIT_FAR, in shadow.h) are *view-space* distances from the camera
|
||||
// (positive). CSM quality at distance falls off fast, so cascades focus on
|
||||
// near content.
|
||||
//
|
||||
// PSSM_LAMBDA blends the uniform split scheme (each cascade covers an
|
||||
// equal slice of view-space distance) and the logarithmic scheme (each
|
||||
// cascade covers an equal multiplicative range). 0 = pure uniform,
|
||||
// 1 = pure log. 0.5 is the sweet spot at the default range. The blend is
|
||||
// pushed toward log up to PSSM_LAMBDA_MAX as the range widens, otherwise a
|
||||
// large far would balloon the near cascade and coarsen close-up shadows.
|
||||
// 1 = pure log, 0.5 is the standard sweet spot. Raising it tightens the
|
||||
// near cascades but drags the boundaries inward, so the last cascade
|
||||
// takes over closer to the camera where its coarser texels show. This is
|
||||
// the starting value, SetShadowSplitLambda overrides it.
|
||||
//
|
||||
// CASTER_MARGIN_M expands the orthographic light frustum's near edge
|
||||
// toward the sun so casters above the camera frustum slice (e.g. the
|
||||
// building roof at y=3 when the slice itself only reaches y=1) still cast
|
||||
// onto receivers inside the slice.
|
||||
#define SHADOW_SPLIT_NEAR 0.1f
|
||||
// DEPTH_BIAS_TEXELS is what remains of the comparison bias once the lit
|
||||
// shaders offset the lookup along the surface normal. It only has to
|
||||
// cover depth quantization, so it is measured in texels of the cascade
|
||||
// that owns it rather than in a fixed world size that would be wrong at
|
||||
// one end or the other of a wide split range.
|
||||
#define PSSM_LAMBDA 0.5f
|
||||
#define PSSM_LAMBDA_MAX 0.9f
|
||||
#define CASTER_MARGIN_M 50.0f
|
||||
#define DEPTH_BIAS_TEXELS 0.5f
|
||||
|
||||
static struct
|
||||
{
|
||||
b3Vec3 sunDir; // world-space dir TO sun, normalized
|
||||
float splitNear; // PSSM split range near (positive view-Z)
|
||||
float splitFar; // PSSM split range far (positive view-Z)
|
||||
float splitLambda; // uniform/log split blend, widens with range
|
||||
float splitLambda; // uniform/log blend for the split scheme
|
||||
sg_image depthArray; // D32F, cascade layers
|
||||
sg_view cascadeAttachmentViews[SHADOW_CASCADE_COUNT]; // depth-stencil view per cascade
|
||||
sg_view sampleView; // full-array texture-sample view
|
||||
sg_sampler sampler; // comparison sampler (LESS_EQUAL, linear PCF)
|
||||
Mat4 cascadeMatrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade
|
||||
float cascadeFarViewZ[SHADOW_CASCADE_COUNT]; // far end (positive view-Z) per cascade
|
||||
float cascadeRadius[SHADOW_CASCADE_COUNT]; // bounding-sphere radius = ortho half-extent
|
||||
float cascadeTexelWorld[SHADOW_CASCADE_COUNT]; // one shadow texel in world length units
|
||||
float cascadeDepthBias[SHADOW_CASCADE_COUNT]; // residual bias in shadow clip-Z units
|
||||
bool inPass; // safety against unbalanced begin/end
|
||||
} s_shadow;
|
||||
|
||||
|
|
@ -52,16 +60,24 @@ static inline float ComputeSplitDistance( int i, int cascadeCount, float nearZ,
|
|||
const float fi = (float)i / (float)cascadeCount;
|
||||
const float u = nearZ + ( farZ - nearZ ) * fi;
|
||||
const float l = nearZ * powf( farZ / nearZ, fi );
|
||||
return s_shadow.splitLambda * l + ( 1.0f - s_shadow.splitLambda ) * u;
|
||||
const float lambda = s_shadow.splitLambda;
|
||||
return lambda * l + ( 1.0f - lambda ) * u;
|
||||
}
|
||||
|
||||
// Push the uniform/log blend toward log as the split range widens, so the near
|
||||
// cascade stays tight when far is large. Anchored at the default range so the
|
||||
// reference scenes keep the 0.5 sweet spot.
|
||||
static inline float SplitLambdaForRange( float nearZ, float farZ )
|
||||
// MakePerspectiveAndInverse puts proj[1][1] = 1/tan(fovY/2) and
|
||||
// proj[0][0] = proj[1][1] / aspect. The analytic inverse stores both
|
||||
// quantities directly, so callers holding either matrix can recover the
|
||||
// frustum shape.
|
||||
static inline void PerspectiveShape( const Mat4* proj, float* tanHalfFovY, float* aspect )
|
||||
{
|
||||
float decades = log10f( ( farZ / nearZ ) / ( SHADOW_SPLIT_FAR / SHADOW_SPLIT_NEAR ) );
|
||||
return b3ClampFloat( PSSM_LAMBDA + 0.4f * decades, PSSM_LAMBDA, PSSM_LAMBDA_MAX );
|
||||
*tanHalfFovY = ( proj->cy.y != 0.0f ) ? ( 1.0f / proj->cy.y ) : 1.0f;
|
||||
*aspect = ( proj->cx.x != 0.0f ) ? ( proj->cy.y / proj->cx.x ) : 1.0f;
|
||||
}
|
||||
|
||||
static inline void PerspectiveShapeFromInverse( const Mat4* projInv, float* tanHalfFovY, float* aspect )
|
||||
{
|
||||
*tanHalfFovY = projInv->cy.y;
|
||||
*aspect = ( projInv->cy.y != 0.0f ) ? ( projInv->cx.x / projInv->cy.y ) : 1.0f;
|
||||
}
|
||||
|
||||
// Fill cornersOut with the 8 world-space corners of the camera frustum
|
||||
|
|
@ -71,18 +87,14 @@ static inline float SplitLambdaForRange( float nearZ, float farZ )
|
|||
// Camera basis comes straight from `viewInv` (the camera's world matrix
|
||||
// produced by mat4ViewAndInverse): column 0 is right, column 1 is up,
|
||||
// column 2 is back (i.e., -forward), column 3 is eye, no inversion.
|
||||
// FovY and aspect are read from the projection matrix: mat4Perspective
|
||||
// puts proj[1][1] = 1/tan(fovY/2) and proj[0][0] = proj[1][1] / aspect.
|
||||
static void FrustumSliceCornersWorld( const Mat4* viewInv, const Mat4* proj, float nearZ, float farZ, b3Vec3 cornersOut[8] )
|
||||
static void FrustumSliceCornersWorld( const Mat4* viewInv, float tanHalfFovY, float aspect, float nearZ, float farZ,
|
||||
b3Vec3 cornersOut[8] )
|
||||
{
|
||||
const b3Vec3 eye = { viewInv->cw.x, viewInv->cw.y, viewInv->cw.z };
|
||||
const b3Vec3 right = { viewInv->cx.x, viewInv->cx.y, viewInv->cx.z };
|
||||
const b3Vec3 up = { viewInv->cy.x, viewInv->cy.y, viewInv->cy.z };
|
||||
const b3Vec3 forward = { -viewInv->cz.x, -viewInv->cz.y, -viewInv->cz.z };
|
||||
|
||||
const float tanHalfFovY = ( proj->cy.y != 0.0f ) ? ( 1.0f / proj->cy.y ) : 1.0f;
|
||||
const float aspect = ( proj->cx.x != 0.0f ) ? ( proj->cy.y / proj->cx.x ) : 1.0f;
|
||||
|
||||
const float distances[2] = { nearZ, farZ };
|
||||
for ( int s = 0; s < 2; ++s )
|
||||
{
|
||||
|
|
@ -101,29 +113,16 @@ static void FrustumSliceCornersWorld( const Mat4* viewInv, const Mat4* proj, flo
|
|||
}
|
||||
}
|
||||
|
||||
// Fit one cascade's light-space view-projection matrix to the camera
|
||||
// frustum slice [nearZ, farZ] for the configured sun direction.
|
||||
//
|
||||
// The slice is bounded by a *world-space sphere* (centroid + max radius
|
||||
// from centroid to any slice corner). The sphere is rotation-invariant.
|
||||
// Rotating the camera around its eye doesn't move it, which is the key
|
||||
// property that lets the texel-snap stabilization avoid swimming edges.
|
||||
//
|
||||
// Light view: orthonormal frame whose -Z axis points toward the sun.
|
||||
// Light proj: orthographic, sized to enclose the sphere. The near plane
|
||||
// is pushed back along +sun by CASTER_MARGIN_M so casters between the
|
||||
// slice and the sun are not clipped.
|
||||
//
|
||||
// Texel-snap: after the unsnapped lightVP is built, transform the slice
|
||||
// center through it to clip space, round the resulting clip-space xy to
|
||||
// the nearest texel grid step, and apply the rounding delta as a
|
||||
// post-translation. This pins the cascade to a fixed grid in light
|
||||
// space, small camera motions no longer cause the shadow texels to
|
||||
// drift relative to the casters.
|
||||
static Mat4 FitCascade( const Mat4* viewInv, const Mat4* proj, b3Vec3 dirToSun, float nearZ, float farZ, float* radiusOut )
|
||||
// Bound a frustum slice by a world-space sphere: centroid of the 8
|
||||
// corners, plus the max distance from it to any of them. The sphere is
|
||||
// rotation-invariant. Rotating the camera around its eye doesn't change
|
||||
// the radius, which is the key property that lets the texel-snap
|
||||
// stabilization avoid swimming edges.
|
||||
static void SliceBoundingSphere( const Mat4* viewInv, float tanHalfFovY, float aspect, float nearZ, float farZ,
|
||||
b3Vec3* centerOut, float* radiusOut )
|
||||
{
|
||||
b3Vec3 corners[8];
|
||||
FrustumSliceCornersWorld( viewInv, proj, nearZ, farZ, corners );
|
||||
FrustumSliceCornersWorld( viewInv, tanHalfFovY, aspect, nearZ, farZ, corners );
|
||||
|
||||
b3Vec3 center = b3Vec3_zero;
|
||||
for ( int i = 0; i < 8; ++i )
|
||||
|
|
@ -146,7 +145,34 @@ static Mat4 FitCascade( const Mat4* viewInv, const Mat4* proj, b3Vec3 dirToSun,
|
|||
{
|
||||
radius = 0.01f;
|
||||
}
|
||||
|
||||
*centerOut = center;
|
||||
*radiusOut = radius;
|
||||
}
|
||||
|
||||
// Fit one cascade's light-space view-projection matrix to the camera
|
||||
// frustum slice [nearZ, farZ] for the configured sun direction.
|
||||
//
|
||||
// Light view: orthonormal frame whose -Z axis points toward the sun.
|
||||
// Light proj: orthographic, sized to enclose the sphere. The near plane
|
||||
// is pushed back along +sun by CASTER_MARGIN_M so casters between the
|
||||
// slice and the sun are not clipped.
|
||||
//
|
||||
// Texel-snap: quantize the sphere center onto a world-anchored lattice
|
||||
// aligned with the light's own axes, one texel of world per step, then
|
||||
// build the light matrices around the snapped center. Camera motion now
|
||||
// slides the cascade in whole texels, so shadow edges step instead of
|
||||
// crawling.
|
||||
//
|
||||
// It has to happen here, on the center, and not by projecting the center
|
||||
// through the finished lightVP: the center is the look-at target, so it
|
||||
// lands on clip (0, 0) by construction and rounding it is a no-op.
|
||||
static Mat4 FitCascade( const Mat4* viewInv, float tanHalfFovY, float aspect, b3Vec3 dirToSun, float nearZ, float farZ,
|
||||
float* radiusOut )
|
||||
{
|
||||
b3Vec3 center;
|
||||
float radius;
|
||||
SliceBoundingSphere( viewInv, tanHalfFovY, aspect, nearZ, farZ, ¢er, &radius );
|
||||
|
||||
// Avoid a degenerate up vector when the sun is straight up/down.
|
||||
b3Vec3 up = b3Vec3_axisY;
|
||||
|
|
@ -155,28 +181,47 @@ static Mat4 FitCascade( const Mat4* viewInv, const Mat4* proj, b3Vec3 dirToSun,
|
|||
up = b3Vec3_axisZ;
|
||||
}
|
||||
|
||||
// Light axes, matching the basis MakeLookAt derives below. The eye sits
|
||||
// along +sun from the target, so the light looks along -sun. These
|
||||
// depend only on the sun and the up choice, never on the camera, which
|
||||
// is what makes the lattice hold still.
|
||||
const b3Vec3 forward = { -dirToSun.x, -dirToSun.y, -dirToSun.z };
|
||||
const b3Vec3 lightRight = b3Normalize( b3Cross( forward, up ) );
|
||||
const b3Vec3 lightUp = b3Cross( lightRight, forward );
|
||||
|
||||
// Radius is fixed for a given split, field of view and aspect, so the
|
||||
// lattice step is fixed too and the same world points keep landing on
|
||||
// the same texels frame to frame.
|
||||
const float texelWorld = 2.0f * radius / (float)SHADOW_RESOLUTION;
|
||||
|
||||
// Geometry reaches the GPU shifted against the draw origin, which
|
||||
// tracks the camera, so the eye sits at this frame's origin and the
|
||||
// frame slides whenever the camera does. Anchoring the lattice here
|
||||
// would drag it along and quantize against a moving reference, which
|
||||
// is the crawl the snap exists to remove. Fold the draw origin back in
|
||||
// and snap the absolute coordinate, in double so the fractional part
|
||||
// within a texel survives far from the origin.
|
||||
const b3Pos drawOrigin = GetDrawOrigin();
|
||||
const double ox = (double)lightRight.x * (double)drawOrigin.x + (double)lightRight.y * (double)drawOrigin.y +
|
||||
(double)lightRight.z * (double)drawOrigin.z;
|
||||
const double oy = (double)lightUp.x * (double)drawOrigin.x + (double)lightUp.y * (double)drawOrigin.y +
|
||||
(double)lightUp.z * (double)drawOrigin.z;
|
||||
|
||||
const double step = (double)texelWorld;
|
||||
const double ax = ox + (double)b3Dot( lightRight, center );
|
||||
const double ay = oy + (double)b3Dot( lightUp, center );
|
||||
center = b3MulAdd( center, (float)( round( ax / step ) * step - ax ), lightRight );
|
||||
center = b3MulAdd( center, (float)( round( ay / step ) * step - ay ), lightUp );
|
||||
|
||||
// Place the light eye behind the sphere along +sun. Far clip extends
|
||||
// past the sphere's back face. Near clip pulls forward by
|
||||
// CASTER_MARGIN_M to admit casters above the slice.
|
||||
const b3Vec3 eyeWorld = b3MulAdd( center, radius + CASTER_MARGIN_M, dirToSun );
|
||||
const Mat4 lightView = MakeLookAt( eyeWorld, center, up );
|
||||
const Mat4 lightProj = MakeOrthographic( -radius, radius, -radius, radius, 0.0f, 2.0f * radius + CASTER_MARGIN_M );
|
||||
Mat4 lightVP = MulMM4( lightProj, lightView );
|
||||
|
||||
// Texel-snap stabilization. Transform the sphere center through the
|
||||
// unsnapped lightVP. Project to texel coords, round, convert the
|
||||
// delta back to clip space, and add as a post-translation.
|
||||
const Vec4 centerClip = MulMV4( lightVP, MakeVec4( center.x, center.y, center.z, 1.0f ) );
|
||||
const float halfRes = (float)SHADOW_RESOLUTION * 0.5f;
|
||||
const float texX = centerClip.x * halfRes;
|
||||
const float texY = centerClip.y * halfRes;
|
||||
const float dx = ( roundf( texX ) - texX ) / halfRes;
|
||||
const float dy = ( roundf( texY ) - texY ) / halfRes;
|
||||
|
||||
Mat4 snapMat = MakeIdentity();
|
||||
snapMat.cw.x = dx;
|
||||
snapMat.cw.y = dy;
|
||||
return MulMM4( snapMat, lightVP );
|
||||
*radiusOut = radius;
|
||||
return MulMM4( lightProj, lightView );
|
||||
}
|
||||
|
||||
void InitShadows( void )
|
||||
|
|
@ -184,12 +229,15 @@ void InitShadows( void )
|
|||
s_shadow.sunDir = b3Normalize( (b3Vec3){ 0.5f, 0.8f, 0.4f } );
|
||||
s_shadow.splitNear = SHADOW_SPLIT_NEAR;
|
||||
s_shadow.splitFar = SHADOW_SPLIT_FAR;
|
||||
s_shadow.splitLambda = SplitLambdaForRange( s_shadow.splitNear, s_shadow.splitFar );
|
||||
s_shadow.splitLambda = PSSM_LAMBDA;
|
||||
|
||||
// Sane ratios if a getter runs before the first FitShadows
|
||||
// The lit shaders divide by the texel size to scale the filter against
|
||||
// cascade zero, so leaving these zero until the first FitShadows would
|
||||
// render a frame of NaN. This is what a unit cascade radius works out to,
|
||||
// which makes every ratio one.
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
{
|
||||
s_shadow.cascadeRadius[i] = 1.0f;
|
||||
s_shadow.cascadeTexelWorld[i] = 2.0f / (float)SHADOW_RESOLUTION;
|
||||
}
|
||||
|
||||
sg_image_desc desc = { 0 };
|
||||
|
|
@ -228,13 +276,22 @@ void InitShadows( void )
|
|||
// the receiver's reference depth is <= the stored depth, i.e., the
|
||||
// receiver is the closest surface to the light. Linear PCF: each
|
||||
// texture call returns a 2x2 weighted compare-result mix.
|
||||
//
|
||||
// White border means taps past a cascade edge compare against the far
|
||||
// plane and come back lit, which dissolves the boundary across the
|
||||
// filter kernel. That is what lets the lit shaders drop their hard
|
||||
// bounds test, and the hard test is what used to flip whole pixels
|
||||
// between sampled and lit as the texel snap stepped the map. Clamping
|
||||
// to edge instead would smear the border texel outward and streak
|
||||
// shadows across everything past the cascade.
|
||||
sg_sampler_desc sdesc = { 0 };
|
||||
sdesc.min_filter = SG_FILTER_LINEAR;
|
||||
sdesc.mag_filter = SG_FILTER_LINEAR;
|
||||
sdesc.mipmap_filter = SG_FILTER_NEAREST;
|
||||
sdesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE;
|
||||
sdesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE;
|
||||
sdesc.wrap_u = SG_WRAP_CLAMP_TO_BORDER;
|
||||
sdesc.wrap_v = SG_WRAP_CLAMP_TO_BORDER;
|
||||
sdesc.wrap_w = SG_WRAP_CLAMP_TO_EDGE;
|
||||
sdesc.border_color = SG_BORDERCOLOR_OPAQUE_WHITE;
|
||||
sdesc.compare = SG_COMPAREFUNC_LESS_EQUAL;
|
||||
sdesc.label = "shadow_compare_sampler";
|
||||
s_shadow.sampler = sg_make_sampler( &sdesc );
|
||||
|
|
@ -264,7 +321,6 @@ void SetShadowSplits( float nearViewZ, float farViewZ )
|
|||
|
||||
s_shadow.splitNear = nearViewZ;
|
||||
s_shadow.splitFar = farViewZ;
|
||||
s_shadow.splitLambda = SplitLambdaForRange( nearViewZ, farViewZ );
|
||||
}
|
||||
|
||||
void SetShadowSplitFar( float farViewZ )
|
||||
|
|
@ -272,6 +328,26 @@ void SetShadowSplitFar( float farViewZ )
|
|||
SetShadowSplits( s_shadow.splitNear, farViewZ );
|
||||
}
|
||||
|
||||
float GetShadowSplitNear( void )
|
||||
{
|
||||
return s_shadow.splitNear;
|
||||
}
|
||||
|
||||
float GetShadowSplitFar( void )
|
||||
{
|
||||
return s_shadow.splitFar;
|
||||
}
|
||||
|
||||
void SetShadowSplitLambda( float lambda )
|
||||
{
|
||||
s_shadow.splitLambda = b3ClampFloat( lambda, 0.0f, 1.0f );
|
||||
}
|
||||
|
||||
float GetShadowSplitLambda( void )
|
||||
{
|
||||
return s_shadow.splitLambda;
|
||||
}
|
||||
|
||||
void SetShadowSunDir( b3Vec3 dirToSun )
|
||||
{
|
||||
const float lenSq = dirToSun.x * dirToSun.x + dirToSun.y * dirToSun.y + dirToSun.z * dirToSun.z;
|
||||
|
|
@ -291,13 +367,65 @@ void FitShadows( const Mat4* viewInv, const Mat4* proj )
|
|||
splits[i] = ComputeSplitDistance( i, SHADOW_CASCADE_COUNT, s_shadow.splitNear, s_shadow.splitFar );
|
||||
}
|
||||
|
||||
float tanHalfFovY, aspect;
|
||||
PerspectiveShape( proj, &tanHalfFovY, &aspect );
|
||||
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
{
|
||||
s_shadow.cascadeMatrices[i] = FitCascade( viewInv, proj, s_shadow.sunDir, splits[i], splits[i + 1], &s_shadow.cascadeRadius[i] );
|
||||
float radius = 0.0f;
|
||||
s_shadow.cascadeMatrices[i] =
|
||||
FitCascade( viewInv, tanHalfFovY, aspect, s_shadow.sunDir, splits[i], splits[i + 1], &radius );
|
||||
s_shadow.cascadeFarViewZ[i] = splits[i + 1];
|
||||
|
||||
// The ortho half-extent is the sphere radius, so the map covers
|
||||
// 2 * radius of world across its resolution.
|
||||
const float texelWorld = 2.0f * radius / (float)SHADOW_RESOLUTION;
|
||||
s_shadow.cascadeTexelWorld[i] = texelWorld;
|
||||
|
||||
// Shadow clip-Z spans the whole orthographic depth range, and the
|
||||
// caster margin inflates that range without covering any more
|
||||
// receiver. Sizing the bias in world units here decouples it, so
|
||||
// the margin costs caster headroom and nothing else.
|
||||
const float depthRange = 2.0f * radius + CASTER_MARGIN_M;
|
||||
s_shadow.cascadeDepthBias[i] = ( DEPTH_BIAS_TEXELS * texelWorld ) / depthRange;
|
||||
}
|
||||
}
|
||||
|
||||
void GetShadowCasterBounds( const Mat4* viewInv, const Mat4* projInv, b3Vec3* loOut, b3Vec3* hiOut )
|
||||
{
|
||||
float tanHalfFovY, aspect;
|
||||
PerspectiveShapeFromInverse( projInv, &tanHalfFovY, &aspect );
|
||||
|
||||
b3Vec3 lo = { FLT_MAX, FLT_MAX, FLT_MAX };
|
||||
b3Vec3 hi = { -FLT_MAX, -FLT_MAX, -FLT_MAX };
|
||||
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
{
|
||||
const float nearZ = ComputeSplitDistance( i, SHADOW_CASCADE_COUNT, s_shadow.splitNear, s_shadow.splitFar );
|
||||
const float farZ = ComputeSplitDistance( i + 1, SHADOW_CASCADE_COUNT, s_shadow.splitNear, s_shadow.splitFar );
|
||||
|
||||
b3Vec3 center;
|
||||
float radius;
|
||||
SliceBoundingSphere( viewInv, tanHalfFovY, aspect, nearZ, farZ, ¢er, &radius );
|
||||
|
||||
// A caster can only darken a receiver in this sphere if it sits
|
||||
// between the two, so sweep the sphere toward the sun rather than
|
||||
// growing it in every direction. Sweeping by the caster margin
|
||||
// lands the front face exactly on the cascade's near plane.
|
||||
const b3Vec3 swept = b3MulAdd( center, CASTER_MARGIN_M, s_shadow.sunDir );
|
||||
|
||||
lo.x = b3MinFloat( lo.x, b3MinFloat( center.x, swept.x ) - radius );
|
||||
lo.y = b3MinFloat( lo.y, b3MinFloat( center.y, swept.y ) - radius );
|
||||
lo.z = b3MinFloat( lo.z, b3MinFloat( center.z, swept.z ) - radius );
|
||||
hi.x = b3MaxFloat( hi.x, b3MaxFloat( center.x, swept.x ) + radius );
|
||||
hi.y = b3MaxFloat( hi.y, b3MaxFloat( center.y, swept.y ) + radius );
|
||||
hi.z = b3MaxFloat( hi.z, b3MaxFloat( center.z, swept.z ) + radius );
|
||||
}
|
||||
|
||||
*loOut = lo;
|
||||
*hiOut = hi;
|
||||
}
|
||||
|
||||
void BeginShadowPass( int cascade )
|
||||
{
|
||||
if ( cascade < 0 || cascade >= SHADOW_CASCADE_COUNT )
|
||||
|
|
@ -342,18 +470,22 @@ float GetCascadeFarViewZ( int cascade )
|
|||
return s_shadow.cascadeFarViewZ[cascade];
|
||||
}
|
||||
|
||||
float GetCascadePcfScale( int cascade )
|
||||
float GetCascadeTexelWorld( int cascade )
|
||||
{
|
||||
if ( cascade < 0 || cascade >= SHADOW_CASCADE_COUNT )
|
||||
{
|
||||
return 1.0f;
|
||||
return 0.0f;
|
||||
}
|
||||
// Texel world size is proportional to the cascade's ortho half-extent,
|
||||
// so the radius ratio is the texel-size ratio. The floor keeps the
|
||||
// shrunken kernel at least ~2 texels wide so bilinear smoothing still
|
||||
// gets some support in the far cascades.
|
||||
const float scale = s_shadow.cascadeRadius[0] / s_shadow.cascadeRadius[cascade];
|
||||
return b3ClampFloat( scale, 0.25f, 1.0f );
|
||||
return s_shadow.cascadeTexelWorld[cascade];
|
||||
}
|
||||
|
||||
float GetCascadeDepthBias( int cascade )
|
||||
{
|
||||
if ( cascade < 0 || cascade >= SHADOW_CASCADE_COUNT )
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
return s_shadow.cascadeDepthBias[cascade];
|
||||
}
|
||||
|
||||
sg_view GetShadowSampleView( void )
|
||||
|
|
|
|||
|
|
@ -42,13 +42,41 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
#define SHADOW_CASCADE_COUNT 3
|
||||
// Must match SHADOW_CASCADE_COUNT in shaders/common/shadow_cascade.glsl,
|
||||
// which the renderer static asserts against the generated uniform layout.
|
||||
// Changing it needs a shader regen (BOX3D_BUILD_SHADERS=ON) to reach the
|
||||
// committed headers. Four is the ceiling: per-cascade values ride in vec4
|
||||
// lanes and a fifth would need a second vec4 for each of them.
|
||||
//
|
||||
// More cascades cannot sharpen the last one. It always has to reach the far
|
||||
// split, so its texel is pinned near 2 * k * far / resolution with k set by
|
||||
// the field of view. What they buy is a finer near cascade and a smaller
|
||||
// step at each boundary, both at the cost of another shadow pass.
|
||||
#define SHADOW_CASCADE_COUNT 4
|
||||
#define SHADOW_RESOLUTION 4096
|
||||
|
||||
// Default cascade far split, view-space distance from the camera. Scenes
|
||||
// smaller than this keep the default range, larger ones widen it.
|
||||
// Default cascade split range, view-space distance from the camera. Scenes
|
||||
// smaller than the far end keep the default range, larger ones widen it.
|
||||
//
|
||||
// The near end sits nowhere near the camera near plane on purpose. It says
|
||||
// where the split distribution starts, not where shadows start: the first
|
||||
// cascade's bounding sphere reaches back past the eye whatever this is, so
|
||||
// close content is covered either way. Starting out at working distance is
|
||||
// what puts the whole volume being looked at inside the first cascade,
|
||||
// rather than spending it on the metre in front of the lens and leaving two
|
||||
// boundaries sitting in the middle of the scene. The cost is a first cascade
|
||||
// stretched to reach that far, so it trades sharpness for uniformity.
|
||||
#define SHADOW_SPLIT_NEAR 10.0f
|
||||
#define SHADOW_SPLIT_FAR 50.0f
|
||||
|
||||
// Ceiling on that widening. The last cascade always has to reach the far
|
||||
// split, so its texel size is set by this number alone and nothing else
|
||||
// in the fit affects it. Letting a scene push it out coarsens the far
|
||||
// cascade until its shadows read as blocks, and widens the step from the
|
||||
// cascade before it. A scene that genuinely needs more reach should ask
|
||||
// for it rather than have it inferred from how big its ground is.
|
||||
#define SHADOW_SPLIT_FAR_MAX 80.0f
|
||||
|
||||
void InitShadows( void );
|
||||
void ShutdownShadows( void );
|
||||
|
||||
|
|
@ -56,15 +84,26 @@ void ShutdownShadows( void );
|
|||
void SetShadowSunDir( b3Vec3 dirToSun );
|
||||
|
||||
// Override the view-space distance range PSSM splits over. Defaults to
|
||||
// (0.1, SHADOW_SPLIT_FAR), sufficient for the reference scenes but too short
|
||||
// for larger ones. The split blend is derived from the range, so a wider far
|
||||
// keeps the near cascade tight. Pass (0, 0) to restore defaults.
|
||||
// (SHADOW_SPLIT_NEAR, SHADOW_SPLIT_FAR), sufficient for the reference scenes
|
||||
// but wrong for a scene watched from far off, where the near end wastes whole
|
||||
// cascades on the empty space in front of the camera. Pass (0, 0) to restore
|
||||
// defaults.
|
||||
void SetShadowSplits( float nearViewZ, float farViewZ );
|
||||
|
||||
// Fit the cascade far split to a scene of this view-space depth, keeping the
|
||||
// current near and recomputing the split blend.
|
||||
// current near.
|
||||
void SetShadowSplitFar( float farViewZ );
|
||||
|
||||
float GetShadowSplitNear( void );
|
||||
float GetShadowSplitFar( void );
|
||||
|
||||
// Blend between the two PSSM split schemes. 0 puts every boundary at an
|
||||
// equal slice of distance, 1 at an equal multiplicative step. Raising it
|
||||
// tightens the near cascades at the cost of dragging every boundary toward
|
||||
// the camera, so the coarse far cascade takes over sooner.
|
||||
void SetShadowSplitLambda( float lambda );
|
||||
float GetShadowSplitLambda( void );
|
||||
|
||||
// Recompute per-cascade light-space matrices and split distances for the
|
||||
// camera frustum described by viewInv + proj. viewInv (the camera's world
|
||||
// matrix) supplies eye + basis directly, so the slice-corner walk does no
|
||||
|
|
@ -73,6 +112,18 @@ void SetShadowSplitFar( float farViewZ );
|
|||
// boundaries to avoid swimming edges as the camera moves.
|
||||
void FitShadows( const Mat4* viewInv, const Mat4* proj );
|
||||
|
||||
// World-space AABB enclosing every shape that can cast into the cascades:
|
||||
// each slice's bounding sphere swept toward the sun by the caster margin.
|
||||
// It reaches well outside the camera frustum, which is the point. A host
|
||||
// culling its draw submission to the visible volume drops casters that
|
||||
// belong in the shadow map, and their shadows vanish.
|
||||
//
|
||||
// Derived from the camera alone, so it can be queried before FitShadows
|
||||
// runs for the frame. Takes projInv because that is what the draw path
|
||||
// already carries. Bounds come back in the same frame viewInv maps into,
|
||||
// so a caller working against a shifted draw origin must offset them.
|
||||
void GetShadowCasterBounds( const Mat4* viewInv, const Mat4* projInv, b3Vec3* loOut, b3Vec3* hiOut );
|
||||
|
||||
// Begin / end the depth-only render pass for a cascade. Bind this as
|
||||
// the surrounding pass before issuing caster draws into the cascade.
|
||||
void BeginShadowPass( int cascade );
|
||||
|
|
@ -87,12 +138,19 @@ Mat4 GetCascadeMatrix( int cascade );
|
|||
// these to pick which cascade to sample.
|
||||
float GetCascadeFarViewZ( int cascade );
|
||||
|
||||
// PCF tap-offset multiplier for a cascade, in (0, 1]. The kernel is
|
||||
// authored in texels of cascade 0, farther cascades cover more world per
|
||||
// texel, so their tap offsets shrink by the texel-size ratio. This keeps
|
||||
// the penumbra a constant world width, without it the shadow edge blur
|
||||
// visibly jumps at every cascade boundary.
|
||||
float GetCascadePcfScale( int cascade );
|
||||
// One shadow texel measured in world length units for a cascade. Lit
|
||||
// shaders scale the normal offset by this so every cascade biases by the
|
||||
// same visual amount regardless of how much world it covers. The ratio
|
||||
// against cascade 0 also shrinks the PCF kernel in the coarser cascades,
|
||||
// which keeps the penumbra a constant world width instead of jumping at
|
||||
// every cascade boundary.
|
||||
float GetCascadeTexelWorld( int cascade );
|
||||
|
||||
// Residual comparison bias for a cascade, in shadow clip-Z units. The
|
||||
// normal offset carries the slope term, this only has to cover depth
|
||||
// quantization. Sized on the CPU because shadow clip-Z spans the whole
|
||||
// orthographic range, which differs per cascade.
|
||||
float GetCascadeDepthBias( int cascade );
|
||||
|
||||
// Bound by lit pipelines once for sampling across all cascades. The view
|
||||
// is the depth array's full-array sampling view. Per-cascade selection
|
||||
|
|
@ -100,8 +158,8 @@ float GetCascadePcfScale( int cascade );
|
|||
sg_view GetShadowSampleView( void );
|
||||
sg_sampler GetShadowSampler( void );
|
||||
|
||||
// One-texel size in shadow space (1 / SHADOW_RESOLUTION). Lit shaders
|
||||
// use this to size PCF taps and slope-scale bias.
|
||||
// One-texel size in shadow UV space (1 / SHADOW_RESOLUTION). Lit shaders
|
||||
// use this to size PCF taps and the cascade-edge reject.
|
||||
float GetShadowTexelSize( void );
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ void SampleContext::Save()
|
|||
fprintf( file, " \"enableIbl\": %s,\n", GetIblEnabled() ? "true" : "false" );
|
||||
fprintf( file, " \"exposure\": %g,\n", GetExposure() );
|
||||
fprintf( file, " \"sunStrength\": %g,\n", GetSun().strength );
|
||||
fprintf( file, " \"shadowSplitLambda\": %g,\n", GetShadowSplitLambda() );
|
||||
fprintf( file, " \"debugView\": %d,\n", debugView );
|
||||
fprintf( file, " \"drawDistance\": %g,\n", drawDistance );
|
||||
fprintf( file, " \"showHullEdges\": %s,\n", GetEdgeOverlayParams().showHulls ? "true" : "false" );
|
||||
|
|
@ -138,6 +139,34 @@ static int jsoneq( const char* json, jsmntok_t* tok, const char* s )
|
|||
return -1;
|
||||
}
|
||||
|
||||
// Tokens are not terminated, so copy before handing one to strtof or strtol.
|
||||
// The settings file is hand editable, so truncate a long token rather than
|
||||
// trusting it to fit.
|
||||
static void CopyToken( char* buffer, int capacity, const char* json, const jsmntok_t& tok )
|
||||
{
|
||||
int count = tok.end - tok.start;
|
||||
if ( count > capacity - 1 )
|
||||
{
|
||||
count = capacity - 1;
|
||||
}
|
||||
memcpy( buffer, json + tok.start, count );
|
||||
buffer[count] = 0;
|
||||
}
|
||||
|
||||
static float ParseFloat( const char* json, const jsmntok_t& tok )
|
||||
{
|
||||
char buffer[32];
|
||||
CopyToken( buffer, (int)sizeof( buffer ), json, tok );
|
||||
return strtof( buffer, nullptr );
|
||||
}
|
||||
|
||||
static int ParseInt( const char* json, const jsmntok_t& tok )
|
||||
{
|
||||
char buffer[32];
|
||||
CopyToken( buffer, (int)sizeof( buffer ), json, tok );
|
||||
return (int)strtol( buffer, nullptr, 10 );
|
||||
}
|
||||
|
||||
void SampleContext::Load()
|
||||
{
|
||||
recycleDistance = B3_CONTACT_RECYCLE_DISTANCE;
|
||||
|
|
@ -158,19 +187,12 @@ void SampleContext::Load()
|
|||
jsmn_init( &parser );
|
||||
|
||||
int tokenCount = jsmn_parse( &parser, data, size, tokens, MAX_TOKENS );
|
||||
char buffer[32];
|
||||
|
||||
for ( int i = 0; i < tokenCount; ++i )
|
||||
{
|
||||
if ( jsoneq( data, &tokens[i], "sampleIndex" ) == 0 )
|
||||
{
|
||||
int count = tokens[i + 1].end - tokens[i + 1].start;
|
||||
assert( count < 32 );
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
strncpy( buffer, s, count );
|
||||
buffer[count] = 0;
|
||||
char* dummy;
|
||||
sampleIndex = (int)strtol( buffer, &dummy, 10 );
|
||||
sampleIndex = ParseInt( data, tokens[i + 1] );
|
||||
|
||||
if ( sampleIndex < 0 )
|
||||
{
|
||||
|
|
@ -198,12 +220,7 @@ void SampleContext::Load()
|
|||
}
|
||||
else if ( jsoneq( data, &tokens[i], "gtaoQuality" ) == 0 )
|
||||
{
|
||||
int count = tokens[i + 1].end - tokens[i + 1].start;
|
||||
assert( count < 32 );
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
strncpy( buffer, s, count );
|
||||
buffer[count] = 0;
|
||||
int quality = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 0, 2 );
|
||||
int quality = b3ClampInt( ParseInt( data, tokens[i + 1] ), 0, 2 );
|
||||
|
||||
GtaoTraceParams p = GetGtaoTraceParams();
|
||||
p.quality = (AmbientOcclusionQuality)quality;
|
||||
|
|
@ -216,41 +233,25 @@ void SampleContext::Load()
|
|||
}
|
||||
else if ( jsoneq( data, &tokens[i], "exposure" ) == 0 )
|
||||
{
|
||||
int count = tokens[i + 1].end - tokens[i + 1].start;
|
||||
assert( count < 32 );
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
strncpy( buffer, s, count );
|
||||
buffer[count] = 0;
|
||||
SetExposure( strtof( buffer, nullptr ) );
|
||||
SetExposure( ParseFloat( data, tokens[i + 1] ) );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "sunStrength" ) == 0 )
|
||||
{
|
||||
int count = tokens[i + 1].end - tokens[i + 1].start;
|
||||
assert( count < 32 );
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
strncpy( buffer, s, count );
|
||||
buffer[count] = 0;
|
||||
Sun sun = GetSun();
|
||||
sun.strength = strtof( buffer, nullptr );
|
||||
sun.strength = ParseFloat( data, tokens[i + 1] );
|
||||
SetSun( sun );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "shadowSplitLambda" ) == 0 )
|
||||
{
|
||||
SetShadowSplitLambda( ParseFloat( data, tokens[i + 1] ) );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "debugView" ) == 0 )
|
||||
{
|
||||
int count = tokens[i + 1].end - tokens[i + 1].start;
|
||||
assert( count < 32 );
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
strncpy( buffer, s, count );
|
||||
buffer[count] = 0;
|
||||
debugView = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 0, 4 );
|
||||
debugView = b3ClampInt( ParseInt( data, tokens[i + 1] ), 0, 4 );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "drawDistance" ) == 0 )
|
||||
{
|
||||
int count = tokens[i + 1].end - tokens[i + 1].start;
|
||||
assert( count < 32 );
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
strncpy( buffer, s, count );
|
||||
buffer[count] = 0;
|
||||
drawDistance = b3ClampFloat( strtof( buffer, nullptr ), 1.0f, Camera::kViewDistance );
|
||||
drawDistance = b3ClampFloat( ParseFloat( data, tokens[i + 1] ), 1.0f, Camera::kViewDistance );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "showHullEdges" ) == 0 )
|
||||
{
|
||||
|
|
@ -268,27 +269,11 @@ void SampleContext::Load()
|
|||
}
|
||||
else if ( jsoneq( data, &tokens[i], "replayKeyframeBudgetMB" ) == 0 )
|
||||
{
|
||||
int count = tokens[i + 1].end - tokens[i + 1].start;
|
||||
if ( count > (int)sizeof( buffer ) - 1 )
|
||||
{
|
||||
count = (int)sizeof( buffer ) - 1;
|
||||
}
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
memcpy( buffer, s, count );
|
||||
buffer[count] = 0;
|
||||
replayKeyframeBudgetMB = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 64, 4096 );
|
||||
replayKeyframeBudgetMB = b3ClampInt( ParseInt( data, tokens[i + 1] ), 64, 4096 );
|
||||
}
|
||||
else if ( jsoneq( data, &tokens[i], "replayKeyframeMinInterval" ) == 0 )
|
||||
{
|
||||
int count = tokens[i + 1].end - tokens[i + 1].start;
|
||||
if ( count > (int)sizeof( buffer ) - 1 )
|
||||
{
|
||||
count = (int)sizeof( buffer ) - 1;
|
||||
}
|
||||
const char* s = data + tokens[i + 1].start;
|
||||
memcpy( buffer, s, count );
|
||||
buffer[count] = 0;
|
||||
replayKeyframeMinInterval = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 1, 1024 );
|
||||
replayKeyframeMinInterval = b3ClampInt( ParseInt( data, tokens[i + 1] ), 1, 1024 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,6 +319,9 @@ Sample::Sample( SampleContext* context )
|
|||
m_mouseDelta = { 0.0f, 0.0f };
|
||||
m_launchSpeedScale = 5.0f;
|
||||
|
||||
m_shadowSplitNear = 0.0f;
|
||||
m_shadowSplitFar = 0.0f;
|
||||
|
||||
g_randomSeed = RAND_SEED;
|
||||
|
||||
b3Capacity capacity = {};
|
||||
|
|
@ -510,10 +498,23 @@ void Sample::Step()
|
|||
// Box3D uses this to decide which shapes enter the draw set and lazily fire
|
||||
// createDebugShape. The camera derives it from the view distance, in length units
|
||||
// around the simulation eye, matching the broad-phase tree and the far plane.
|
||||
debugDraw.drawingBounds = m_camera->DrawBounds();
|
||||
const b3AABB drawBox = m_camera->DrawBounds();
|
||||
|
||||
// Same view box drives compound child culling in the adapter.
|
||||
SetViewBounds( debugDraw.drawingBounds );
|
||||
// A caster between the view and the sun is off screen but still darkens what
|
||||
// is on screen, so the draw set has to reach past the view box. Bounds come
|
||||
// back in the eye-relative frame the view inverse maps into, hence the offset.
|
||||
b3Vec3 casterLo, casterHi;
|
||||
const Mat4 viewInv = m_camera->ViewInverse();
|
||||
const Mat4 projInv = m_camera->ProjInverse();
|
||||
GetShadowCasterBounds( &viewInv, &projInv, &casterLo, &casterHi );
|
||||
const b3AABB casterBox = b3OffsetAABB( { casterLo, casterHi }, m_camera->DrawOrigin() );
|
||||
|
||||
debugDraw.drawingBounds.lowerBound = b3Min( drawBox.lowerBound, casterBox.lowerBound );
|
||||
debugDraw.drawingBounds.upperBound = b3Max( drawBox.upperBound, casterBox.upperBound );
|
||||
|
||||
// Compound child culling keeps the tighter view box. Widening it there would
|
||||
// cull nothing.
|
||||
SetViewBounds( drawBox );
|
||||
|
||||
ApplyGuiFlags( &debugDraw );
|
||||
|
||||
|
|
@ -1355,10 +1356,25 @@ void SelectSample( SampleContext* context, int selection, bool restart )
|
|||
context->restart = restart;
|
||||
context->sample = g_sampleEntries[selection].CreateFcn( context );
|
||||
|
||||
// Fit the shadow cascade range to the world bounds.
|
||||
b3AABB bounds = b3World_GetBounds( context->sample->m_worldId );
|
||||
float diagonal = b3Distance( bounds.lowerBound, bounds.upperBound );
|
||||
SetShadowSplitFar( b3ClampFloat( diagonal, SHADOW_SPLIT_FAR, 200.0f ) );
|
||||
// A sample that knows where its content sits relative to its camera says
|
||||
// so, and is taken at its word. The ceiling below guards a guess, not a
|
||||
// measurement, so capping an explicit request would only hide it.
|
||||
if ( context->sample->m_shadowSplitFar > 0.0f )
|
||||
{
|
||||
// A sample wanting only more reach leaves the near end at zero.
|
||||
float splitNear = context->sample->m_shadowSplitNear;
|
||||
SetShadowSplits( splitNear > 0.0f ? splitNear : SHADOW_SPLIT_NEAR, context->sample->m_shadowSplitFar );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise fit the range to the world bounds. The bounds are a poor
|
||||
// proxy for how far shadows need to reach: a ground plate stretches
|
||||
// the diagonal well past anything worth shadowing, so the ceiling
|
||||
// matters more than the estimate.
|
||||
b3AABB bounds = b3World_GetBounds( context->sample->m_worldId );
|
||||
float diagonal = b3Distance( bounds.lowerBound, bounds.upperBound );
|
||||
SetShadowSplits( SHADOW_SPLIT_NEAR, b3ClampFloat( diagonal, SHADOW_SPLIT_FAR, SHADOW_SPLIT_FAR_MAX ) );
|
||||
}
|
||||
|
||||
// Samples read restart only while constructing, to keep the camera across a
|
||||
// restart. Clear it so a later switch starts fresh.
|
||||
|
|
@ -1522,6 +1538,61 @@ static void DrawRenderMenu( SampleContext& ctx )
|
|||
{
|
||||
ImGui::MenuItem( "Shadows", nullptr, &ctx.enableShadows );
|
||||
|
||||
if ( ImGui::BeginMenu( "Cascades" ) )
|
||||
{
|
||||
ImGui::PushItemWidth( 8.0f * ImGui::GetFontSize() );
|
||||
|
||||
// Where the split distribution starts, not where shadows start. Raising
|
||||
// it hands the whole working volume to the first cascade and coarsens
|
||||
// it to suit. The c0 row below is what to steer by: it says how far the
|
||||
// sharp cascade reaches and what one of its texels costs.
|
||||
float splitNear = GetShadowSplitNear();
|
||||
if ( ImGui::SliderFloat( "Start", &splitNear, 0.1f, 30.0f, "%.1f m" ) )
|
||||
{
|
||||
SetShadowSplits( splitNear, GetShadowSplitFar() );
|
||||
}
|
||||
|
||||
// Selecting a sample refits the range to the world, so a value dialed
|
||||
// in here survives only until the next sample switch.
|
||||
float splitFar = GetShadowSplitFar();
|
||||
if ( ImGui::SliderFloat( "Range", &splitFar, 10.0f, 200.0f, "%.0f m" ) )
|
||||
{
|
||||
SetShadowSplitFar( splitFar );
|
||||
}
|
||||
|
||||
float lambda = GetShadowSplitLambda();
|
||||
if ( ImGui::SliderFloat( "Distribution", &lambda, 0.0f, 1.0f, "%.2f" ) )
|
||||
{
|
||||
SetShadowSplitLambda( lambda );
|
||||
}
|
||||
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
// Where each cascade ends and how much world one of its texels covers.
|
||||
// A quality cliff at a boundary is the step between two neighboring
|
||||
// texel sizes, which is easier to read here than off the image.
|
||||
if ( ImGui::BeginTable( "cascades", 3, ImGuiTableFlags_SizingFixedFit ) )
|
||||
{
|
||||
ImGui::TableSetupColumn( "csm" );
|
||||
ImGui::TableSetupColumn( "far" );
|
||||
ImGui::TableSetupColumn( "texel" );
|
||||
ImGui::TableHeadersRow();
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i )
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex( 0 );
|
||||
ImGui::Text( "%d", i );
|
||||
ImGui::TableSetColumnIndex( 1 );
|
||||
ImGui::Text( "%.1f m", GetCascadeFarViewZ( i ) );
|
||||
ImGui::TableSetColumnIndex( 2 );
|
||||
ImGui::Text( "%.0f mm", 1000.0f * GetCascadeTexelWorld( i ) );
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if ( ImGui::BeginMenu( "GTAO" ) )
|
||||
{
|
||||
ImGui::MenuItem( "Enable", nullptr, &ctx.enableGtao );
|
||||
|
|
|
|||
|
|
@ -226,6 +226,18 @@ public:
|
|||
int m_profileReadIndex;
|
||||
int m_profileWriteIndex;
|
||||
|
||||
// View-space distance range the shadow cascades split over, set during
|
||||
// construction. Left at zero the range is guessed from the world bounds,
|
||||
// which only works when the camera sits close to the content. A scene
|
||||
// viewed from far off wants an explicit range: the guess spends every
|
||||
// cascade on the empty space in front of the camera and the shadows stop
|
||||
// partway into the scene.
|
||||
//
|
||||
// Authored against the sample's opening camera, so flying well away from
|
||||
// it can still outrun the far end.
|
||||
float m_shadowSplitNear;
|
||||
float m_shadowSplitFar;
|
||||
|
||||
b3Vec2 m_mouseLast;
|
||||
b3Vec2 m_mouseDelta;
|
||||
bool m_didStep;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ public:
|
|||
m_camera->SetView( 40.0f, -10.0f, 110.0f, { 0.0f, 40.0f, 0.0f } );
|
||||
}
|
||||
|
||||
m_shadowSplitFar = 180.0f;
|
||||
|
||||
CreateLargePyramid( m_worldId );
|
||||
|
||||
SetGroundShape( GetGroundShapeId() );
|
||||
|
|
@ -1034,13 +1036,12 @@ public:
|
|||
|
||||
g_randomSeed = 42;
|
||||
|
||||
m_count = 64;
|
||||
for ( int i = 0; i < m_count; ++i )
|
||||
for ( int i = 0; i < m_capacity; ++i )
|
||||
{
|
||||
m_points[i] = RandomVec3( { -1.0f, -1.0f, -1.0f }, { 1.0f, 1.0f, 1.0f } );
|
||||
}
|
||||
|
||||
m_hull = b3CreateHull( m_points, m_count, m_count );
|
||||
m_hull = b3CreateHull( m_points, m_capacity, m_count );
|
||||
m_scale = { -1.0f, 1.0f, 1.0f };
|
||||
m_transformedHull = b3CloneAndTransformHull( m_hull, b3Transform_identity, m_scale );
|
||||
}
|
||||
|
|
@ -1070,7 +1071,7 @@ public:
|
|||
|
||||
for ( int i = 0; i < trials; ++i )
|
||||
{
|
||||
b3HullData* hull = b3CreateHull( m_points, m_count, m_count );
|
||||
b3HullData* hull = b3CreateHull( m_points, m_capacity, m_count );
|
||||
area += hull->surfaceArea;
|
||||
b3DestroyHull( hull );
|
||||
}
|
||||
|
|
@ -1099,12 +1100,12 @@ public:
|
|||
return new BenchmarkHull( sampleContext );
|
||||
}
|
||||
|
||||
static constexpr int m_capacity = 64;
|
||||
static constexpr int m_capacity = 100;
|
||||
static constexpr int m_count = 16;
|
||||
b3HullData* m_hull;
|
||||
b3HullData* m_transformedHull;
|
||||
b3Vec3 m_scale;
|
||||
b3Vec3 m_points[m_capacity];
|
||||
int m_count;
|
||||
};
|
||||
|
||||
static int sampleBenchmarkHull = RegisterSample( "Benchmark", "Hull", BenchmarkHull::Create );
|
||||
|
|
@ -1465,6 +1466,10 @@ public:
|
|||
m_camera->SetView( 45.0f, 20.0f, 150.0f, { 0.0f, 15.0f, 0.0f } );
|
||||
}
|
||||
|
||||
// Watched from 150 m out, so the settled pile sits between 100 and 180 m
|
||||
// of view depth and the guessed range stops less than halfway into it.
|
||||
m_shadowSplitFar = 180.0f;
|
||||
|
||||
b3Capacity capacity = {};
|
||||
GetConvexPileCapacity( &capacity );
|
||||
CreateWorld( &capacity );
|
||||
|
|
|
|||
|
|
@ -399,7 +399,11 @@ public:
|
|||
hullPoints[numSegs] = b3Vec3_zero;
|
||||
b3HullData* hull = b3CreateHull( hullPoints, numSegs + 1, numSegs + 1 );
|
||||
|
||||
// Capsule for testing alternate shapes. Keep this.
|
||||
//b3Capsule capsule = {{0.0f, -0.6f, 0.0f}, {0.0f, 0.6f, 0.0f }, 0.4f};
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.rollingResistance = 0.1f;
|
||||
|
||||
// Tilt the top, then spin it about its own symmetry axis. Gravity does the rest.
|
||||
b3Quat rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 15.0f * B3_PI / 180.0f );
|
||||
|
|
@ -422,6 +426,8 @@ public:
|
|||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( bodyId, &shapeDef, hull );
|
||||
|
||||
//b3CreateCapsuleShape( bodyId, &shapeDef, &capsule );
|
||||
|
||||
b3Body_SetAngularVelocity( bodyId, angularVelocity );
|
||||
|
||||
if ( x == 0 && z == 0 )
|
||||
|
|
@ -1276,3 +1282,54 @@ public:
|
|||
};
|
||||
|
||||
static int sampleClassRing = RegisterSample( "Bodies", "Class Ring", ClassRing::Create );
|
||||
|
||||
/*
|
||||
mandude — 9:34 AM
|
||||
I've run into a minor, and admittedly pretty niche, issue with kinematic bodies. Because box3d will skip mass computations on
|
||||
kinematic bodies, the center of mass is never set. This means if the origin of a shape attached to the body isn't in the center of
|
||||
the shape, and you add an angular velocity, the shape will rotate about whatever the shape's origin is. For a simple example, if
|
||||
you have a cube as a mesh, with opposing corners at (0, 0, 0) and (1, 1, 1), rotation will happen about the corner of the cube.
|
||||
It's possible to work around this by calling setMassData with zero mass, a custom center of mass, and an identity matrix for the
|
||||
inertia tensor. That function tries to preserve momentum, so it can have unexpected effects on the velocity if the body is already
|
||||
moving, so perhaps it would be useful to have a more direct way to specify a custom offset for the origin of a kinematic body?
|
||||
*/
|
||||
class OffsetKinematic : public Sample
|
||||
{
|
||||
public:
|
||||
explicit OffsetKinematic( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( m_context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 30.0f, 10.0f, { 0.0f, 1.5f, 0.0f } );
|
||||
}
|
||||
|
||||
AddGroundBox( 20.0f );
|
||||
|
||||
{
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.name = "kinematic";
|
||||
bodyDef.type = b3_kinematicBody;
|
||||
bodyDef.position.y = 3.0;
|
||||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3Vec3 offset = { 0.5f, 0.5f, 1.0f };
|
||||
b3BoxHull box = b3MakeTransformedBoxHull( 0.5f, 0.5f, 1.0f, { .p = offset, .q = b3Quat_identity} );
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
b3CreateHullShape( bodyId, &shapeDef, &box.base );
|
||||
|
||||
b3MassData massData = b3Body_GetMassData( bodyId );
|
||||
massData.center = offset;
|
||||
b3Body_SetMassData( bodyId, massData );
|
||||
|
||||
b3Vec3 angularVelocity = {1.0f, -1.0f, 2.0f};
|
||||
b3Body_SetAngularVelocity( bodyId, angularVelocity );
|
||||
}
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new OffsetKinematic( context );
|
||||
}
|
||||
};
|
||||
|
||||
static int sampleOffsetKinematic = RegisterSample( "Bodies", "Offset Kinematic", OffsetKinematic::Create );
|
||||
|
|
|
|||
|
|
@ -571,6 +571,368 @@ public:
|
|||
|
||||
static int sampleJointEvent = RegisterSample( "Events", "Joint", JointEvent::Create );
|
||||
|
||||
struct BodyUserData
|
||||
{
|
||||
int index;
|
||||
};
|
||||
|
||||
// This shows how to use contact events to transfer shapes from one body to another.
|
||||
class ContactEvent : public Sample
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
e_count = 200
|
||||
};
|
||||
|
||||
explicit ContactEvent( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( m_context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 35.0f, 60.0f, b3Pos_zero );
|
||||
}
|
||||
|
||||
m_groundExtent = 80.0f;
|
||||
AddGroundBox( m_groundExtent );
|
||||
|
||||
// The walls live on their own body so a contact can be told apart from the floor. The player
|
||||
// rides on the floor at all times, so treating every non-debris body as a wall would strip
|
||||
// each pickup the moment it dragged along the ground.
|
||||
{
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.name = "walls";
|
||||
m_wallsId = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
|
||||
float extent = m_groundExtent + 0.5f;
|
||||
float height = 5.0f;
|
||||
float thickness = 0.5f;
|
||||
|
||||
b3BoxHull wall =
|
||||
b3MakeTransformedBoxHull( thickness, height, extent, { { extent, height, 0.0f }, b3Quat_identity } );
|
||||
b3CreateHullShape( m_wallsId, &shapeDef, &wall.base );
|
||||
|
||||
wall = b3MakeTransformedBoxHull( thickness, height, extent, { { -extent, height, 0.0f }, b3Quat_identity } );
|
||||
b3CreateHullShape( m_wallsId, &shapeDef, &wall.base );
|
||||
|
||||
wall = b3MakeTransformedBoxHull( extent, height, thickness, { { 0.0f, height, extent }, b3Quat_identity } );
|
||||
b3CreateHullShape( m_wallsId, &shapeDef, &wall.base );
|
||||
|
||||
wall = b3MakeTransformedBoxHull( extent, height, thickness, { { 0.0f, height, -extent }, b3Quat_identity } );
|
||||
b3CreateHullShape( m_wallsId, &shapeDef, &wall.base );
|
||||
}
|
||||
|
||||
// Player
|
||||
{
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.name = "player";
|
||||
bodyDef.position = { 0.0f, 1.0f, 0.0f };
|
||||
bodyDef.angularDamping = 0.1f;
|
||||
m_playerId = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
|
||||
// Contact events fire when either shape enables them, so opting in the player alone
|
||||
// still reports every collision it has while debris hitting debris stays silent.
|
||||
shapeDef.enableContactEvents = true;
|
||||
|
||||
// Friction is what turns the drive torque into motion
|
||||
shapeDef.baseMaterial.friction = 0.6f;
|
||||
shapeDef.baseMaterial.rollingResistance = 0.1f;
|
||||
shapeDef.baseMaterial.customColor = b3MakeDebugColor( b3_colorPlum, b3_debugMaterialMetallic );
|
||||
|
||||
b3Sphere sphere = { b3Vec3_zero, 1.0f };
|
||||
m_coreShapeId = b3CreateSphereShape( m_playerId, &shapeDef, &sphere );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < e_count; ++i )
|
||||
{
|
||||
m_debrisIds[i] = b3_nullBodyId;
|
||||
m_bodyUserData[i].index = i;
|
||||
}
|
||||
|
||||
b3AABB bounds = b3Body_ComputeAABB( m_playerId );
|
||||
b3Vec3 extents = b3AABB_Extents( bounds );
|
||||
float mass = b3Body_GetMass( m_playerId );
|
||||
m_massExtent = ( mass / 3.0f ) * ( extents.x + extents.y + extents.z );
|
||||
m_torque = 30000.0f;
|
||||
m_wait = 0.5f;
|
||||
}
|
||||
|
||||
void SpawnDebris()
|
||||
{
|
||||
int index = -1;
|
||||
for ( int i = 0; i < e_count; ++i )
|
||||
{
|
||||
if ( B3_IS_NULL( m_debrisIds[i] ) )
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( index == -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float a = m_groundExtent - 2.0f;
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.position = RandomPos( { -a, 1.0f, -a }, { a, 6.0f, a } );
|
||||
bodyDef.rotation = RandomQuat();
|
||||
bodyDef.linearVelocity = RandomVec3Uniform( -2.0f, 2.0f );
|
||||
bodyDef.angularVelocity = RandomVec3Uniform( -1.0f, 1.0f );
|
||||
bodyDef.userData = m_bodyUserData + index;
|
||||
m_debrisIds[index] = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.restitution = 0.3f;
|
||||
|
||||
if ( ( index + 1 ) % 3 == 0 )
|
||||
{
|
||||
b3Sphere sphere = { b3Vec3_zero, 0.5f };
|
||||
b3CreateSphereShape( m_debrisIds[index], &shapeDef, &sphere );
|
||||
}
|
||||
else if ( ( index + 1 ) % 2 == 0 )
|
||||
{
|
||||
b3Capsule capsule = { { 0.0f, -0.25f, 0.0f }, { 0.0f, 0.25f, 0.0f }, 0.25f };
|
||||
b3CreateCapsuleShape( m_debrisIds[index], &shapeDef, &capsule );
|
||||
}
|
||||
else
|
||||
{
|
||||
b3BoxHull box = b3MakeBoxHull( 0.4f, 0.6f, 0.5f );
|
||||
b3CreateHullShape( m_debrisIds[index], &shapeDef, &box.base );
|
||||
}
|
||||
}
|
||||
|
||||
// Rebuild a debris shape in the player frame and destroy the body it came from
|
||||
void AttachDebris( int index )
|
||||
{
|
||||
b3BodyId debrisId = m_debrisIds[index];
|
||||
if ( B3_IS_NULL( debrisId ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3WorldTransform playerTransform = b3Body_GetTransform( m_playerId );
|
||||
b3WorldTransform debrisTransform = b3Body_GetTransform( debrisId );
|
||||
b3Transform relativeTransform = b3InvMulWorldTransforms( playerTransform, debrisTransform );
|
||||
|
||||
b3ShapeId shapeId;
|
||||
if ( b3Body_GetShapes( debrisId, &shapeId, 1 ) == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.enableContactEvents = true;
|
||||
shapeDef.baseMaterial.customColor = b3_colorGold;
|
||||
|
||||
// Several shapes may land in one step, so take the mass update once at the end
|
||||
shapeDef.updateBodyMass = false;
|
||||
|
||||
switch ( b3Shape_GetType( shapeId ) )
|
||||
{
|
||||
case b3_sphereShape:
|
||||
{
|
||||
b3Sphere sphere = b3Shape_GetSphere( shapeId );
|
||||
sphere.center = b3TransformPoint( relativeTransform, sphere.center );
|
||||
|
||||
b3CreateSphereShape( m_playerId, &shapeDef, &sphere );
|
||||
}
|
||||
break;
|
||||
|
||||
case b3_capsuleShape:
|
||||
{
|
||||
b3Capsule capsule = b3Shape_GetCapsule( shapeId );
|
||||
capsule.center1 = b3TransformPoint( relativeTransform, capsule.center1 );
|
||||
capsule.center2 = b3TransformPoint( relativeTransform, capsule.center2 );
|
||||
|
||||
b3CreateCapsuleShape( m_playerId, &shapeDef, &capsule );
|
||||
}
|
||||
break;
|
||||
|
||||
case b3_hullShape:
|
||||
{
|
||||
// The hull is cloned and baked, so the source body can go away right after
|
||||
const b3HullData* hull = b3Shape_GetHull( shapeId );
|
||||
b3CreateTransformedHullShape( m_playerId, &shapeDef, hull, relativeTransform, b3Vec3_one );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
assert( false );
|
||||
}
|
||||
|
||||
b3DestroyBody( debrisId );
|
||||
m_debrisIds[index] = b3_nullBodyId;
|
||||
}
|
||||
|
||||
bool DrawControls() override
|
||||
{
|
||||
ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() );
|
||||
ImGui::SliderFloat( "torque", &m_torque, 0.0f, 60000.0f, "%.0f" );
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Step() override
|
||||
{
|
||||
// Drive relative to the camera so the controls hold up as the view orbits
|
||||
b3Vec2 throttle = { 0.0f, 0.0f };
|
||||
|
||||
if ( IsKeyDown( KEY_W ) )
|
||||
{
|
||||
throttle.x += 1.0f;
|
||||
}
|
||||
|
||||
if ( IsKeyDown( KEY_S ) )
|
||||
{
|
||||
throttle.x -= 1.0f;
|
||||
}
|
||||
|
||||
if ( IsKeyDown( KEY_A ) )
|
||||
{
|
||||
throttle.y -= 1.0f;
|
||||
}
|
||||
|
||||
if ( IsKeyDown( KEY_D ) )
|
||||
{
|
||||
throttle.y += 1.0f;
|
||||
}
|
||||
|
||||
b3Vec3 forward = -m_camera->GetForward();
|
||||
forward.y = 0.0f;
|
||||
forward = b3Normalize( forward );
|
||||
|
||||
b3Vec3 right = m_camera->GetRight();
|
||||
right.y = 0.0f;
|
||||
right = b3Normalize( right );
|
||||
|
||||
b3Vec3 direction = throttle.x * forward + throttle.y * right;
|
||||
if ( b3LengthSquared( direction ) > 0.0f )
|
||||
{
|
||||
b3AABB bounds = b3Body_ComputeAABB( m_playerId );
|
||||
b3Vec3 extents = b3AABB_Extents( bounds );
|
||||
float mass = b3Body_GetMass( m_playerId );
|
||||
float massExtent = ( mass / 3.0f ) * ( extents.x + extents.y + extents.z );
|
||||
float scale = massExtent / m_massExtent;
|
||||
|
||||
// Rolling without slipping spins about up cross velocity
|
||||
b3Vec3 axis = b3Cross( b3Vec3_axisY, b3Normalize( direction ) );
|
||||
b3Body_ApplyTorque( m_playerId, (scale * m_torque) * axis, true );
|
||||
}
|
||||
|
||||
Sample::Step();
|
||||
|
||||
int debrisToAttach[e_count] = {};
|
||||
b3ShapeId shapesToDestroy[e_count] = {};
|
||||
int attachCount = 0;
|
||||
int destroyCount = 0;
|
||||
|
||||
b3ContactEvents contactEvents = b3World_GetContactEvents( m_worldId );
|
||||
for ( int i = 0; i < contactEvents.beginCount; ++i )
|
||||
{
|
||||
b3ContactBeginTouchEvent event = contactEvents.beginEvents[i];
|
||||
|
||||
b3ShapeId playerShapeId = event.shapeIdA;
|
||||
b3ShapeId otherShapeId = event.shapeIdB;
|
||||
if ( B3_ID_EQUALS( b3Shape_GetBody( playerShapeId ), m_playerId ) == false )
|
||||
{
|
||||
playerShapeId = event.shapeIdB;
|
||||
otherShapeId = event.shapeIdA;
|
||||
}
|
||||
|
||||
// Only the player enables contact events, so one side is always the player
|
||||
assert( B3_ID_EQUALS( b3Shape_GetBody( playerShapeId ), m_playerId ) );
|
||||
|
||||
b3BodyId otherBodyId = b3Shape_GetBody( otherShapeId );
|
||||
BodyUserData* userData = static_cast<BodyUserData*>( b3Body_GetUserData( otherBodyId ) );
|
||||
|
||||
if ( userData != nullptr )
|
||||
{
|
||||
if ( attachCount < e_count )
|
||||
{
|
||||
debrisToAttach[attachCount] = userData->index;
|
||||
attachCount += 1;
|
||||
}
|
||||
}
|
||||
else if ( B3_ID_EQUALS( otherBodyId, m_wallsId ) && B3_ID_EQUALS( playerShapeId, m_coreShapeId ) == false )
|
||||
{
|
||||
// An accreted shape scraped a wall. The core is exempt or the player would dissolve.
|
||||
bool found = false;
|
||||
for ( int j = 0; j < destroyCount; ++j )
|
||||
{
|
||||
if ( B3_ID_EQUALS( playerShapeId, shapesToDestroy[j] ) )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid double deletion
|
||||
if ( found == false && destroyCount < e_count )
|
||||
{
|
||||
shapesToDestroy[destroyCount] = playerShapeId;
|
||||
destroyCount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < attachCount; ++i )
|
||||
{
|
||||
AttachDebris( debrisToAttach[i] );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < destroyCount; ++i )
|
||||
{
|
||||
bool updateMass = false;
|
||||
b3DestroyShape( shapesToDestroy[i], updateMass );
|
||||
}
|
||||
|
||||
if ( attachCount > 0 || destroyCount > 0 )
|
||||
{
|
||||
b3Body_ApplyMassFromShapes( m_playerId );
|
||||
}
|
||||
|
||||
if ( m_context->hertz > 0.0f && m_context->pause == false )
|
||||
{
|
||||
m_wait -= 1.0f / m_context->hertz;
|
||||
if ( m_wait < 0.0f )
|
||||
{
|
||||
SpawnDebris();
|
||||
m_wait += 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
DrawTextLine( "move using WASD" );
|
||||
DrawTextLine( "player shape count = %d", b3Body_GetShapeCount( m_playerId ) );
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new ContactEvent( context );
|
||||
}
|
||||
|
||||
static constexpr int m_capacity = 200;
|
||||
b3BodyId m_playerId;
|
||||
b3BodyId m_wallsId;
|
||||
b3ShapeId m_coreShapeId;
|
||||
b3BodyId m_debrisIds[m_capacity];
|
||||
BodyUserData m_bodyUserData[m_capacity];
|
||||
float m_groundExtent;
|
||||
float m_massExtent;
|
||||
float m_torque;
|
||||
float m_wait;
|
||||
};
|
||||
|
||||
static int sampleContactEvent = RegisterSample( "Events", "Contact", ContactEvent::Create );
|
||||
|
||||
class PersistentContact : public Sample
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "gfx/debug_adapter.h"
|
||||
#include "gfx/draw.h"
|
||||
#include "gfx/keycodes.h"
|
||||
#include "gfx/shadow.h"
|
||||
#include "gfx/text.h"
|
||||
#include "imgui.h"
|
||||
#include "sample.h"
|
||||
|
|
@ -300,7 +301,7 @@ public:
|
|||
{
|
||||
if ( m_player != nullptr )
|
||||
{
|
||||
b3RecPlayer_Destroy( m_player );
|
||||
b3DestroyPlayer( m_player );
|
||||
m_player = nullptr;
|
||||
}
|
||||
m_replayWorldId = b3_nullWorldId;
|
||||
|
|
@ -336,7 +337,7 @@ public:
|
|||
if ( recording != nullptr )
|
||||
{
|
||||
m_player =
|
||||
b3RecPlayer_Create( b3Recording_GetData( recording ), b3Recording_GetSize( recording ), m_context->workerCount );
|
||||
b3CreatePlayer( b3Recording_GetData( recording ), b3Recording_GetSize( recording ), m_context->workerCount );
|
||||
b3DestroyRecording( recording );
|
||||
}
|
||||
else
|
||||
|
|
@ -613,8 +614,19 @@ public:
|
|||
b3DebugDraw debugDraw;
|
||||
MakeDebugDraw( &debugDraw );
|
||||
ApplyGuiFlags( &debugDraw );
|
||||
debugDraw.drawingBounds = m_camera->DrawBounds(); // view-distance box in length units around the eye
|
||||
SetViewBounds( debugDraw.drawingBounds );
|
||||
const b3AABB drawBox = m_camera->DrawBounds(); // view-distance box in length units around the eye
|
||||
|
||||
// Reach past the view box for casters between it and the sun, see Sample::Draw.
|
||||
b3Vec3 casterLo, casterHi;
|
||||
const Mat4 viewInv = m_camera->ViewInverse();
|
||||
const Mat4 projInv = m_camera->ProjInverse();
|
||||
GetShadowCasterBounds( &viewInv, &projInv, &casterLo, &casterHi );
|
||||
const b3AABB casterBox = b3OffsetAABB( { casterLo, casterHi }, m_camera->DrawOrigin() );
|
||||
|
||||
debugDraw.drawingBounds.lowerBound = b3Min( drawBox.lowerBound, casterBox.lowerBound );
|
||||
debugDraw.drawingBounds.upperBound = b3Max( drawBox.upperBound, casterBox.upperBound );
|
||||
|
||||
SetViewBounds( drawBox );
|
||||
|
||||
// Drive the shared outline highlight from the selection. A shape selection outlines that
|
||||
// shape alone, a body selection outlines the whole body. Set before the draw so the mask
|
||||
|
|
|
|||
|
|
@ -3,13 +3,25 @@
|
|||
# Each .glsl file in shaders/ becomes a single C header in
|
||||
# generated/<name>.glsl.h that holds source/bytecode for every enabled backend
|
||||
# (D3D11, Metal, GL 4.5 core). The generated headers are committed so a fresh
|
||||
# clone builds without sokol-shdc. BOX3D_BUILD_SHADERS (default ON) recompiles
|
||||
# clone builds without sokol-shdc. BOX3D_BUILD_SHADERS (default OFF) recompiles
|
||||
# them in place when a .glsl changes; off builds straight from the committed
|
||||
# headers and fetches no tooling.
|
||||
|
||||
set(SHADER_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated"
|
||||
CACHE INTERNAL "Directory holding generated shader headers")
|
||||
|
||||
# Shared @include fragments - sokol-shdc's @include resolves relative to the
|
||||
# input file, so shaders include these via "../common/<name>.glsl". Listed in
|
||||
# the shaders target's SOURCES so they show up in IDE project trees, which is
|
||||
# the only way they get there - sokol-shdc never sees them as direct inputs.
|
||||
# Globbed unconditionally so they stay searchable when codegen is off, which
|
||||
# is the default. With codegen on they are also DEPENDS on every shader so an
|
||||
# edit to a shared file rebuilds everything that might include it.
|
||||
# CONFIGURE_DEPENDS re-globs when a new common file appears, at the cost of a
|
||||
# configure-step stat each build.
|
||||
file(GLOB SHADER_COMMON_INCLUDES CONFIGURE_DEPENDS
|
||||
"${CMAKE_CURRENT_LIST_DIR}/common/*.glsl")
|
||||
|
||||
if(BOX3D_BUILD_SHADERS)
|
||||
if(NOT SOKOL_SHDC_EXECUTABLE OR NOT EXISTS "${SOKOL_SHDC_EXECUTABLE}")
|
||||
message(FATAL_ERROR
|
||||
|
|
@ -17,17 +29,6 @@ if(BOX3D_BUILD_SHADERS)
|
|||
"${SOKOL_SHDC_EXECUTABLE}")
|
||||
endif()
|
||||
file(MAKE_DIRECTORY "${SHADER_OUTPUT_DIR}")
|
||||
|
||||
# Shared @include fragments - sokol-shdc's @include resolves relative to
|
||||
# the input file, so shaders include these via "../common/<name>.glsl".
|
||||
# Tracked as DEPENDS on every shader so an edit to a shared file triggers
|
||||
# a rebuild of everything that might include it, and listed in the shaders
|
||||
# target's SOURCES so they show up in IDE project trees - sokol-shdc never
|
||||
# sees them as direct inputs, so they would be invisible otherwise.
|
||||
# CONFIGURE_DEPENDS re-globs when a new common file appears, at the cost of
|
||||
# a configure-step stat each build.
|
||||
file(GLOB SHADER_COMMON_INCLUDES CONFIGURE_DEPENDS
|
||||
"${CMAKE_CURRENT_LIST_DIR}/common/*.glsl")
|
||||
endif()
|
||||
|
||||
# Reset the accumulators on every configure so stale entries from a prior
|
||||
|
|
@ -108,31 +109,31 @@ add_shader(world_text "overlays/world_text.glsl")
|
|||
get_property(_outputs GLOBAL PROPERTY SHADER_OUTPUTS)
|
||||
get_property(_inputs GLOBAL PROPERTY SHADER_INPUTS)
|
||||
|
||||
# SOURCES is purely an IDE hint - Visual Studio and Xcode show listed files in
|
||||
# the project tree even though nothing here is compiled. We list the leaf .glsl
|
||||
# shaders, the common/ @include fragments, and the generated .glsl.h.
|
||||
if(BOX3D_BUILD_SHADERS)
|
||||
# DEPENDS drives the build (run sokol-shdc when the .glsl inputs change).
|
||||
# SOURCES is purely an IDE hint - Visual Studio and Xcode show listed files
|
||||
# in the project tree even though nothing here is compiled. We list the leaf
|
||||
# .glsl shaders, the common/ @include fragments, and the generated .glsl.h.
|
||||
add_custom_target(shaders
|
||||
DEPENDS ${_outputs}
|
||||
SOURCES ${_inputs} ${SHADER_COMMON_INCLUDES} ${_outputs}
|
||||
)
|
||||
|
||||
# IDE grouping. TREE mirrors the on-disk shaders layout.
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
FILES ${_inputs} ${SHADER_COMMON_INCLUDES})
|
||||
source_group("Generated" FILES ${_outputs})
|
||||
|
||||
# The Visual Studio generator emits a build-stamp file named
|
||||
# CMakeFiles/<target> for each custom target. Left ungrouped it floats at
|
||||
# the project root as a stray "shaders" node with a can't-find-file icon -
|
||||
# file it under the build-rule machinery.
|
||||
source_group("CMake Rules" FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/shaders")
|
||||
else()
|
||||
# No codegen: the samples build straight from the committed headers.
|
||||
add_custom_target(shaders SOURCES ${_inputs} ${_outputs})
|
||||
add_custom_target(shaders SOURCES ${_inputs} ${SHADER_COMMON_INCLUDES} ${_outputs})
|
||||
endif()
|
||||
|
||||
# IDE grouping. TREE mirrors the on-disk shaders layout.
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
FILES ${_inputs} ${SHADER_COMMON_INCLUDES})
|
||||
source_group("Generated" FILES ${_outputs})
|
||||
|
||||
# The Visual Studio generator emits a build-stamp file named CMakeFiles/<target>
|
||||
# for each custom target. Left ungrouped it floats at the project root as a
|
||||
# stray "shaders" node with a can't-find-file icon - file it under the
|
||||
# build-rule machinery.
|
||||
source_group("CMake Rules" FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/shaders")
|
||||
|
||||
# shader_gen is the INTERFACE library consumers link to. It forwards the include
|
||||
# path for the generated headers (SYSTEM so /WX doesn't trip on shdc output) and
|
||||
# pulls in the shaders target so any link forces the headers to exist first.
|
||||
|
|
|
|||
51
samples/shaders/common/shadow_cascade.glsl
Normal file
51
samples/shaders/common/shadow_cascade.glsl
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Cascade count plus the parts of the cascaded lookup that touch no
|
||||
// uniform block, shared by the lit shape shaders via @include. Each
|
||||
// shader declares its own ub_pass, so the per-cascade values stay there
|
||||
// and arrive as parameters.
|
||||
|
||||
// Must match SHADOW_CASCADE_COUNT in gfx/shadow.h. The renderer static
|
||||
// asserts the two agree, so a mismatch fails the build instead of
|
||||
// rendering garbage. Changing it here only reaches the committed headers
|
||||
// after a shader regen, which needs BOX3D_BUILD_SHADERS=ON.
|
||||
//
|
||||
// Four is the ceiling. Per-cascade values ride in vec4 lanes and a fifth
|
||||
// cascade would need a second vec4 for each of them.
|
||||
#define SHADOW_CASCADE_COUNT 4
|
||||
|
||||
// Cascade whose slice holds this view depth. The last one is a fallback
|
||||
// rather than a range: its map footprint runs well past the final split,
|
||||
// so content past the split range still gets shadowed.
|
||||
int selectShadowCascade( vec4 far_view_z, float view_z )
|
||||
{
|
||||
int cascade = SHADOW_CASCADE_COUNT - 1;
|
||||
for ( int i = 0; i < SHADOW_CASCADE_COUNT - 1; ++i )
|
||||
{
|
||||
if ( view_z < far_view_z[i] )
|
||||
{
|
||||
cascade = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return cascade;
|
||||
}
|
||||
|
||||
// Debug view 2.
|
||||
vec3 shadowCascadeTint( int cascade )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
{
|
||||
return vec3( 1.0, 0.4, 0.4 );
|
||||
}
|
||||
if ( cascade == 1 )
|
||||
{
|
||||
return vec3( 0.4, 1.0, 0.4 );
|
||||
}
|
||||
if ( cascade == 2 )
|
||||
{
|
||||
return vec3( 0.4, 0.4, 1.0 );
|
||||
}
|
||||
return vec3( 1.0, 0.9, 0.3 );
|
||||
}
|
||||
|
|
@ -22,14 +22,17 @@ float sampleShadowTap( texture2DArray tex, samplerShadow smp, vec2 uv, float lay
|
|||
}
|
||||
|
||||
// scale multiplies the tap offsets. Cascades cover different world sizes
|
||||
// per texel, the caller passes GetCascadePcfScale's texel-size ratio so
|
||||
// the penumbra keeps a constant world width instead of jumping from
|
||||
// crisp to blurry at every cascade boundary. 1.0 = the full 7x7 kernel.
|
||||
float sampleShadowPCF( texture2DArray tex, samplerShadow smp, int cascade, vec3 light_uv, float bias, float scale )
|
||||
// per texel, so the caller passes the texel-size ratio against the near
|
||||
// cascade and the penumbra keeps a constant world width instead of
|
||||
// jumping from crisp to blurry at every cascade boundary. 1.0 = the full
|
||||
// 7x7 kernel.
|
||||
//
|
||||
// inv_size is one texel in UV. Passed in rather than baked in so the
|
||||
// kernel follows SHADOW_RESOLUTION without a second place to edit.
|
||||
float sampleShadowPCF( texture2DArray tex, samplerShadow smp, int cascade, vec3 light_uv, float bias, float scale,
|
||||
float inv_size )
|
||||
{
|
||||
// Must match SHADOW_RESOLUTION in shadow.h
|
||||
const float size = 4096.0;
|
||||
const float inv_size = 1.0 / size;
|
||||
float size = 1.0 / inv_size;
|
||||
|
||||
float ly = float( cascade );
|
||||
float rz = light_uv.z - bias;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -22,6 +22,9 @@
|
|||
Uniform block 'ub_frame':
|
||||
C struct: shadow_sphere_ub_frame_t
|
||||
Bind slot: UB_shadow_sphere_ub_frame => 0
|
||||
Uniform block 'ub_pass':
|
||||
C struct: shadow_sphere_ub_pass_t
|
||||
Bind slot: UB_shadow_sphere_ub_pass => 1
|
||||
Storage buffer 'instances':
|
||||
C struct: shadow_sphere_instance_t
|
||||
Bind slot: VIEW_shadow_sphere_instances => 0
|
||||
|
|
@ -40,6 +43,7 @@
|
|||
#define ATTR_shadow_sphere_caster_in_pos (0)
|
||||
#define UB_shadow_sphere_ub_draw (2)
|
||||
#define UB_shadow_sphere_ub_frame (0)
|
||||
#define UB_shadow_sphere_ub_pass (1)
|
||||
#define VIEW_shadow_sphere_instances (0)
|
||||
#pragma pack(push,1)
|
||||
SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_draw_t {
|
||||
|
|
@ -52,6 +56,12 @@ SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_frame_t {
|
|||
} shadow_sphere_ub_frame_t;
|
||||
#pragma pack(pop)
|
||||
#pragma pack(push,1)
|
||||
SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_pass_t {
|
||||
Vec4 light_dir;
|
||||
Vec4 depth_row;
|
||||
} shadow_sphere_ub_pass_t;
|
||||
#pragma pack(pop)
|
||||
#pragma pack(push,1)
|
||||
SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_instance_t {
|
||||
Vec4 xform_row0;
|
||||
Vec4 xform_row1;
|
||||
|
|
@ -82,15 +92,23 @@ SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_instance_t {
|
|||
uniform ivec4 ub_draw[1];
|
||||
uniform vec4 ub_frame[4];
|
||||
layout(location = 0) in vec3 in_pos;
|
||||
layout(location = 0) out vec3 v_world_pos_proxy;
|
||||
layout(location = 1) flat out vec3 v_center;
|
||||
layout(location = 2) flat out float v_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
int _30 = ub_draw[0].x + gl_InstanceID;
|
||||
gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + (in_pos * _15.items[_30].params.x), 1.0);
|
||||
vec3 _63 = vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w);
|
||||
vec3 _76 = _63 + (in_pos * (2.0 * _15.items[_30].params.x));
|
||||
v_world_pos_proxy = _76;
|
||||
v_center = _63;
|
||||
v_radius = _15.items[_30].params.x;
|
||||
gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_76, 1.0);
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t shadow_sphere_vs_source_glsl430[612] = {
|
||||
static const uint8_t shadow_sphere_vs_source_glsl430[889] = {
|
||||
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74,
|
||||
0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,
|
||||
|
|
@ -111,38 +129,102 @@ static const uint8_t shadow_sphere_vs_source_glsl430[612] = {
|
|||
0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,
|
||||
0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,
|
||||
0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,
|
||||
0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,
|
||||
0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,
|
||||
0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,
|
||||
0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,
|
||||
0x63,0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,
|
||||
0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f,
|
||||
0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,
|
||||
0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,
|
||||
0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29,
|
||||
0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,
|
||||
0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,
|
||||
0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,
|
||||
0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,
|
||||
0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,
|
||||
0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,
|
||||
0x2e,0x77,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,
|
||||
0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,
|
||||
0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,
|
||||
0x7d,0x0a,0x0a,0x00,
|
||||
0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,
|
||||
0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,
|
||||
0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,
|
||||
0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,
|
||||
0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,
|
||||
0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,
|
||||
0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,
|
||||
0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,
|
||||
0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,
|
||||
0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,
|
||||
0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,
|
||||
0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30,0x5d,0x2e,0x78,
|
||||
0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,
|
||||
0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,
|
||||
0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,
|
||||
0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,
|
||||
0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,
|
||||
0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,
|
||||
0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,0x36,0x33,
|
||||
0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,
|
||||
0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,
|
||||
0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,
|
||||
0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,
|
||||
0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,
|
||||
0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,
|
||||
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,
|
||||
0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,
|
||||
0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,
|
||||
0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,
|
||||
0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31,
|
||||
0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
#version 430
|
||||
layout(depth_greater) out float gl_FragDepth;
|
||||
|
||||
uniform vec4 ub_pass[2];
|
||||
layout(location = 0) in vec3 v_world_pos_proxy;
|
||||
layout(location = 1) flat in vec3 v_center;
|
||||
layout(location = 2) flat in float v_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 _28 = v_world_pos_proxy - v_center;
|
||||
float _33 = dot(_28, ub_pass[0].xyz);
|
||||
float _49 = (_33 * _33) - (dot(_28, _28) - (v_radius * v_radius));
|
||||
if (_49 < 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
gl_FragDepth = dot(ub_pass[1], vec4(v_world_pos_proxy + (ub_pass[0].xyz * max((-_33) - sqrt(_49), 0.0)), 1.0));
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
||||
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x76,0x6f,
|
||||
0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
|
||||
static const uint8_t shadow_sphere_fs_source_glsl430[563] = {
|
||||
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x6c,0x61,0x79,
|
||||
0x6f,0x75,0x74,0x28,0x64,0x65,0x70,0x74,0x68,0x5f,0x67,0x72,0x65,0x61,0x74,0x65,
|
||||
0x72,0x29,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,
|
||||
0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,
|
||||
0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,
|
||||
0x5b,0x32,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,
|
||||
0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,
|
||||
0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,
|
||||
0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,
|
||||
0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,
|
||||
0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,
|
||||
0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,
|
||||
0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x76,
|
||||
0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x38,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,
|
||||
0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,
|
||||
0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x20,0x5f,0x33,0x33,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,
|
||||
0x38,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x79,
|
||||
0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,
|
||||
0x39,0x20,0x3d,0x20,0x28,0x5f,0x33,0x33,0x20,0x2a,0x20,0x5f,0x33,0x33,0x29,0x20,
|
||||
0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,0x5f,0x32,0x38,0x29,
|
||||
0x20,0x2d,0x20,0x28,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,
|
||||
0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,
|
||||
0x66,0x20,0x28,0x5f,0x34,0x39,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,
|
||||
0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x67,
|
||||
0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,
|
||||
0x74,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x65,
|
||||
0x63,0x34,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,
|
||||
0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,
|
||||
0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x28,0x2d,0x5f,
|
||||
0x33,0x33,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x34,0x39,0x29,0x2c,
|
||||
0x20,0x30,0x2e,0x30,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d,
|
||||
0x0a,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
struct instance
|
||||
|
|
@ -163,13 +245,16 @@ static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
|||
|
||||
cbuffer ub_frame : register(b0)
|
||||
{
|
||||
row_major float4x4 _83_light_view_proj : packoffset(c0);
|
||||
row_major float4x4 _93_light_view_proj : packoffset(c0);
|
||||
};
|
||||
|
||||
|
||||
static float4 gl_Position;
|
||||
static int gl_InstanceIndex;
|
||||
static float3 in_pos;
|
||||
static float3 v_world_pos_proxy;
|
||||
static float3 v_center;
|
||||
static float v_radius;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
|
|
@ -179,6 +264,9 @@ static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
|||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float3 v_world_pos_proxy : TEXCOORD0;
|
||||
nointerpolation float3 v_center : TEXCOORD1;
|
||||
nointerpolation float v_radius : TEXCOORD2;
|
||||
float4 gl_Position : SV_Position;
|
||||
};
|
||||
|
||||
|
|
@ -191,7 +279,12 @@ static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
|||
_33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48));
|
||||
_33.params = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64));
|
||||
_33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80));
|
||||
gl_Position = mul(float4(float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w) + (in_pos * _33.params.x), 1.0f), _83_light_view_proj);
|
||||
float3 _63 = float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w);
|
||||
float3 _76 = _63 + (in_pos * (2.0f * _33.params.x));
|
||||
v_world_pos_proxy = _76;
|
||||
v_center = _63;
|
||||
v_radius = _33.params.x;
|
||||
gl_Position = mul(float4(_76, 1.0f), _93_light_view_proj);
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
|
|
@ -201,10 +294,13 @@ static const uint8_t shadow_sphere_fs_source_glsl430[32] = {
|
|||
vert_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_Position = gl_Position;
|
||||
stage_output.v_world_pos_proxy = v_world_pos_proxy;
|
||||
stage_output.v_center = v_center;
|
||||
stage_output.v_radius = v_radius;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = {
|
||||
static const uint8_t shadow_sphere_vs_source_hlsl5[2093] = {
|
||||
0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f,
|
||||
0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
|
|
@ -225,7 +321,7 @@ static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = {
|
|||
0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a,
|
||||
0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,
|
||||
0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x39,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,
|
||||
0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,
|
||||
0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,
|
||||
0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,
|
||||
|
|
@ -233,6 +329,11 @@ static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = {
|
|||
0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,
|
||||
0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,
|
||||
0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,
|
||||
0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,
|
||||
0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,
|
||||
0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,
|
||||
0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,
|
||||
0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,
|
||||
0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,
|
||||
|
|
@ -241,87 +342,219 @@ static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = {
|
|||
0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,
|
||||
0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,
|
||||
0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,
|
||||
0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
|
||||
0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,
|
||||
0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,
|
||||
0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,
|
||||
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,
|
||||
0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,
|
||||
0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,
|
||||
0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,
|
||||
0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,
|
||||
0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,
|
||||
0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,
|
||||
0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,
|
||||
0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,
|
||||
0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,
|
||||
0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,
|
||||
0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,
|
||||
0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,
|
||||
0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,
|
||||
0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,
|
||||
0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,
|
||||
0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,
|
||||
0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,
|
||||
0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,
|
||||
0x78,0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,
|
||||
0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,
|
||||
0x74,0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,
|
||||
0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,
|
||||
0x69,0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,
|
||||
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,
|
||||
0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,
|
||||
0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x33,0x33,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,
|
||||
0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,
|
||||
0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,
|
||||
0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,
|
||||
0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,
|
||||
0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,
|
||||
0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,
|
||||
0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,
|
||||
0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,
|
||||
0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,
|
||||
0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,
|
||||
0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,
|
||||
0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,
|
||||
0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,
|
||||
0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,
|
||||
0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,
|
||||
0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,
|
||||
0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,
|
||||
0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,
|
||||
0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x34,0x38,0x29,
|
||||
0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,
|
||||
0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,
|
||||
0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,
|
||||
0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,
|
||||
0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,
|
||||
0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,
|
||||
0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,
|
||||
0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,
|
||||
0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,
|
||||
0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,
|
||||
0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,
|
||||
0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,
|
||||
0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,
|
||||
0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,
|
||||
0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,
|
||||
0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,
|
||||
0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,
|
||||
0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,
|
||||
0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,
|
||||
0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x20,0x2b,0x20,
|
||||
0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,
|
||||
0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,
|
||||
0x5f,0x38,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,
|
||||
0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,
|
||||
0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,
|
||||
0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,
|
||||
0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,
|
||||
0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,
|
||||
0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,
|
||||
0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,
|
||||
0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,
|
||||
0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,
|
||||
0x36,0x33,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,
|
||||
0x32,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,
|
||||
0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,
|
||||
0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,
|
||||
0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,
|
||||
0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,
|
||||
0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,
|
||||
0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,
|
||||
0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x39,
|
||||
0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,
|
||||
0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,
|
||||
0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,
|
||||
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,
|
||||
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,
|
||||
0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,
|
||||
0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,
|
||||
0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,
|
||||
0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,
|
||||
0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,
|
||||
0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,
|
||||
0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,
|
||||
0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
|
||||
0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,
|
||||
0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,
|
||||
0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,
|
||||
0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,
|
||||
0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,
|
||||
0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,
|
||||
0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,
|
||||
0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,
|
||||
0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
cbuffer ub_pass : register(b1)
|
||||
{
|
||||
float4 _17_light_dir : packoffset(c0);
|
||||
float4 _17_depth_row : packoffset(c1);
|
||||
};
|
||||
|
||||
|
||||
static float gl_FragDepth;
|
||||
static float3 v_world_pos_proxy;
|
||||
static float3 v_center;
|
||||
static float v_radius;
|
||||
|
||||
struct SPIRV_Cross_Input
|
||||
{
|
||||
float3 v_world_pos_proxy : TEXCOORD0;
|
||||
nointerpolation float3 v_center : TEXCOORD1;
|
||||
nointerpolation float v_radius : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct SPIRV_Cross_Output
|
||||
{
|
||||
float gl_FragDepth : SV_DepthGreaterEqual;
|
||||
};
|
||||
|
||||
void frag_main()
|
||||
{
|
||||
float3 _28 = v_world_pos_proxy - v_center;
|
||||
float _33 = dot(_28, _17_light_dir.xyz);
|
||||
float _49 = (_33 * _33) - (dot(_28, _28) - (v_radius * v_radius));
|
||||
if (_49 < 0.0f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
gl_FragDepth = dot(_17_depth_row, float4(v_world_pos_proxy + (_17_light_dir.xyz * max((-_33) - sqrt(_49), 0.0f)), 1.0f));
|
||||
}
|
||||
|
||||
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
|
||||
{
|
||||
v_world_pos_proxy = stage_input.v_world_pos_proxy;
|
||||
v_center = stage_input.v_center;
|
||||
v_radius = stage_input.v_radius;
|
||||
frag_main();
|
||||
SPIRV_Cross_Output stage_output;
|
||||
stage_output.gl_FragDepth = gl_FragDepth;
|
||||
return stage_output;
|
||||
}
|
||||
*/
|
||||
static const uint8_t shadow_sphere_fs_source_hlsl5[1155] = {
|
||||
0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,
|
||||
0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x5f,
|
||||
0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,
|
||||
0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x5f,0x64,0x65,0x70,0x74,0x68,
|
||||
0x5f,0x72,0x6f,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,
|
||||
0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,
|
||||
0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,
|
||||
0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,
|
||||
0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,
|
||||
0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,
|
||||
0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,
|
||||
0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,
|
||||
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,
|
||||
0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,
|
||||
0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,
|
||||
0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,
|
||||
0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,
|
||||
0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,
|
||||
0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x7d,0x3b,
|
||||
0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,
|
||||
0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,
|
||||
0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70,0x74,0x68,0x47,
|
||||
0x72,0x65,0x61,0x74,0x65,0x72,0x45,0x71,0x75,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,
|
||||
0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,
|
||||
0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,
|
||||
0x32,0x38,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,
|
||||
0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,
|
||||
0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x33,
|
||||
0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,0x5f,0x31,0x37,0x5f,
|
||||
0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,
|
||||
0x28,0x5f,0x33,0x33,0x20,0x2a,0x20,0x5f,0x33,0x33,0x29,0x20,0x2d,0x20,0x28,0x64,
|
||||
0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,0x5f,0x32,0x38,0x29,0x20,0x2d,0x20,0x28,
|
||||
0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,
|
||||
0x69,0x75,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,
|
||||
0x34,0x39,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,
|
||||
0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,
|
||||
0x31,0x37,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x72,0x6f,0x77,0x2c,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,
|
||||
0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x31,0x37,0x5f,0x6c,0x69,
|
||||
0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x6d,0x61,
|
||||
0x78,0x28,0x28,0x2d,0x5f,0x33,0x33,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,
|
||||
0x5f,0x34,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x2c,0x20,0x31,0x2e,
|
||||
0x30,0x66,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,
|
||||
0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,
|
||||
0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,
|
||||
0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,
|
||||
0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,
|
||||
0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,
|
||||
0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,
|
||||
0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,
|
||||
0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,
|
||||
0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,
|
||||
0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,
|
||||
0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,
|
||||
0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
void frag_main()
|
||||
{
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
frag_main();
|
||||
}
|
||||
*/
|
||||
static const uint8_t shadow_sphere_fs_source_hlsl5[56] = {
|
||||
0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,
|
||||
0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,
|
||||
0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,
|
||||
0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,
|
||||
0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,
|
||||
0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,
|
||||
0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,
|
||||
0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,
|
||||
0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,
|
||||
0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,
|
||||
0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,
|
||||
0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,
|
||||
0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,
|
||||
0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,
|
||||
0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,
|
||||
0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,
|
||||
0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,
|
||||
0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,
|
||||
0x7d,0x0a,0x00,
|
||||
};
|
||||
/*
|
||||
#include <metal_stdlib>
|
||||
|
|
@ -356,6 +589,9 @@ static const uint8_t shadow_sphere_fs_source_hlsl5[56] = {
|
|||
|
||||
struct main0_out
|
||||
{
|
||||
float3 v_world_pos_proxy [[user(locn0)]];
|
||||
float3 v_center [[user(locn1)]];
|
||||
float v_radius [[user(locn2)]];
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
|
|
@ -364,16 +600,21 @@ static const uint8_t shadow_sphere_fs_source_hlsl5[56] = {
|
|||
float3 in_pos [[attribute(0)]];
|
||||
};
|
||||
|
||||
vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _83 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]])
|
||||
vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _93 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]])
|
||||
{
|
||||
main0_out out = {};
|
||||
int _30 = _21.inst_base.x + int(gl_InstanceIndex);
|
||||
out.gl_Position = _83.light_view_proj * float4(float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + (in.in_pos * _15.items[_30].params.x), 1.0);
|
||||
float3 _63 = float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w);
|
||||
float3 _76 = _63 + (in.in_pos * (2.0 * _15.items[_30].params.x));
|
||||
out.v_world_pos_proxy = _76;
|
||||
out.v_center = _63;
|
||||
out.v_radius = _15.items[_30].params.x;
|
||||
out.gl_Position = _93.light_view_proj * float4(_76, 1.0);
|
||||
return out;
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t shadow_sphere_vs_source_metal_macos[982] = {
|
||||
static const uint8_t shadow_sphere_vs_source_metal_macos[1254] = {
|
||||
0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
|
||||
0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
|
||||
0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
|
||||
|
|
@ -398,42 +639,59 @@ static const uint8_t shadow_sphere_vs_source_metal_macos[982] = {
|
|||
0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,
|
||||
0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,
|
||||
0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,
|
||||
0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,
|
||||
0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,
|
||||
0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,
|
||||
0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,
|
||||
0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,
|
||||
0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,
|
||||
0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,
|
||||
0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,
|
||||
0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x38,0x33,0x20,0x5b,0x5b,0x62,0x75,0x66,
|
||||
0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,
|
||||
0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20,
|
||||
0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,
|
||||
0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,
|
||||
0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,
|
||||
0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,
|
||||
0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,
|
||||
0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,
|
||||
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,
|
||||
0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,
|
||||
0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,
|
||||
0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,
|
||||
0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,
|
||||
0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x38,0x33,0x2e,0x6c,0x69,0x67,0x68,
|
||||
0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,
|
||||
0x6f,0x61,0x74,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e,
|
||||
0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,
|
||||
0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,
|
||||
0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,
|
||||
0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,
|
||||
0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,
|
||||
0x77,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,
|
||||
0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,
|
||||
0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,
|
||||
0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,
|
||||
0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,
|
||||
0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,
|
||||
0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,
|
||||
0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,
|
||||
0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,
|
||||
0x6e,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,
|
||||
0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,
|
||||
0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,
|
||||
0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,
|
||||
0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,
|
||||
0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,
|
||||
0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,
|
||||
0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,
|
||||
0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,
|
||||
0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x39,
|
||||
0x33,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,
|
||||
0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,
|
||||
0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,
|
||||
0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,
|
||||
0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,
|
||||
0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,
|
||||
0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,
|
||||
0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,
|
||||
0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,
|
||||
0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,
|
||||
0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,
|
||||
0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,
|
||||
0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,
|
||||
0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,
|
||||
0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,
|
||||
0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,
|
||||
0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,
|
||||
0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,
|
||||
0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20,
|
||||
0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e,
|
||||
0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,
|
||||
0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,
|
||||
0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x37,0x36,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,
|
||||
0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,
|
||||
0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,
|
||||
0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,
|
||||
0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,
|
||||
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x39,0x33,0x2e,0x6c,0x69,
|
||||
0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31,0x2e,0x30,0x29,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,
|
||||
0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
|
|
@ -443,19 +701,94 @@ static const uint8_t shadow_sphere_vs_source_metal_macos[982] = {
|
|||
|
||||
using namespace metal;
|
||||
|
||||
fragment void main0()
|
||||
struct ub_pass
|
||||
{
|
||||
float4 light_dir;
|
||||
float4 depth_row;
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float gl_FragDepth [[depth(greater)]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float3 v_world_pos_proxy [[user(locn0)]];
|
||||
float3 v_center [[user(locn1), flat]];
|
||||
float v_radius [[user(locn2), flat]];
|
||||
};
|
||||
|
||||
fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _17 [[buffer(1)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
float3 _28 = in.v_world_pos_proxy - in.v_center;
|
||||
float _33 = dot(_28, _17.light_dir.xyz);
|
||||
float _49 = (_33 * _33) - (dot(_28, _28) - (in.v_radius * in.v_radius));
|
||||
if (_49 < 0.0)
|
||||
{
|
||||
discard_fragment();
|
||||
}
|
||||
out.gl_FragDepth = dot(_17.depth_row, float4(in.v_world_pos_proxy + (_17.light_dir.xyz * fast::max((-_33) - sqrt(_49), 0.0)), 1.0));
|
||||
return out;
|
||||
}
|
||||
|
||||
*/
|
||||
static const uint8_t shadow_sphere_fs_source_metal_macos[100] = {
|
||||
static const uint8_t shadow_sphere_fs_source_metal_macos[861] = {
|
||||
0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f,
|
||||
0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,
|
||||
0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a,
|
||||
0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20,
|
||||
0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,
|
||||
0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x29,0x0a,0x7b,0x0a,
|
||||
0x7d,0x0a,0x0a,0x00,
|
||||
0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,
|
||||
0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x64,0x65,0x70,0x74,0x68,0x5f,
|
||||
0x72,0x6f,0x77,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,
|
||||
0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,
|
||||
0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28,0x67,0x72,0x65,0x61,0x74,
|
||||
0x65,0x72,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,
|
||||
0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,
|
||||
0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,
|
||||
0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b,
|
||||
0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x2c,0x20,0x66,0x6c,
|
||||
0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,
|
||||
0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,
|
||||
0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,
|
||||
0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,
|
||||
0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,
|
||||
0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,
|
||||
0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,
|
||||
0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x37,0x20,0x5b,0x5b,0x62,
|
||||
0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,
|
||||
0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,
|
||||
0x20,0x5f,0x32,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,
|
||||
0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x69,0x6e,
|
||||
0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x33,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,
|
||||
0x32,0x38,0x2c,0x20,0x5f,0x31,0x37,0x2e,0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,
|
||||
0x72,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,
|
||||
0x74,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,0x28,0x5f,0x33,0x33,0x20,0x2a,0x20,0x5f,
|
||||
0x33,0x33,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,
|
||||
0x5f,0x32,0x38,0x29,0x20,0x2d,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,
|
||||
0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,
|
||||
0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x34,0x39,
|
||||
0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,
|
||||
0x61,0x67,0x6d,0x65,0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,
|
||||
0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37,0x2e,0x64,
|
||||
0x65,0x70,0x74,0x68,0x5f,0x72,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,
|
||||
0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,
|
||||
0x70,0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x31,0x37,0x2e,0x6c,0x69,0x67,
|
||||
0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x66,0x61,0x73,
|
||||
0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x28,0x2d,0x5f,0x33,0x33,0x29,0x20,0x2d,0x20,
|
||||
0x73,0x71,0x72,0x74,0x28,0x5f,0x34,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,
|
||||
0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,
|
||||
0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
|
||||
};
|
||||
static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend backend) {
|
||||
if (backend == SG_BACKEND_GLCORE) {
|
||||
|
|
@ -475,6 +808,12 @@ static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend
|
|||
desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
|
||||
desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4;
|
||||
desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame";
|
||||
desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT;
|
||||
desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[1].size = 32;
|
||||
desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4;
|
||||
desc.uniform_blocks[1].glsl_uniforms[0].array_count = 2;
|
||||
desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_pass";
|
||||
desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX;
|
||||
desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[2].size = 16;
|
||||
|
|
@ -506,6 +845,10 @@ static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend
|
|||
desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[0].size = 64;
|
||||
desc.uniform_blocks[0].hlsl_register_b_n = 0;
|
||||
desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT;
|
||||
desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[1].size = 32;
|
||||
desc.uniform_blocks[1].hlsl_register_b_n = 1;
|
||||
desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX;
|
||||
desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[2].size = 16;
|
||||
|
|
@ -531,6 +874,10 @@ static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend
|
|||
desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[0].size = 64;
|
||||
desc.uniform_blocks[0].msl_buffer_n = 0;
|
||||
desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT;
|
||||
desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[1].size = 32;
|
||||
desc.uniform_blocks[1].msl_buffer_n = 1;
|
||||
desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX;
|
||||
desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140;
|
||||
desc.uniform_blocks[2].size = 16;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -131,6 +131,7 @@ void main()
|
|||
#pragma sokol @fs fs
|
||||
|
||||
#pragma sokol @include ../common/pbr.glsl
|
||||
#pragma sokol @include ../common/shadow_cascade.glsl
|
||||
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
|
|
@ -140,9 +141,11 @@ layout( binding = 1 ) uniform ub_pass
|
|||
vec4 camera_pos; // .xyz = camera world pos, .w unused
|
||||
mat4 view_proj; // for reverse-Z gl_FragDepth
|
||||
mat4 view; // for view-space depth debug mode + cascade selection
|
||||
vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade
|
||||
mat4 cascade_matrices[3]; // light-space view-proj per cascade
|
||||
vec4 cascade_pcf_scale; // .xyz = PCF tap-offset scale per cascade (constant world penumbra)
|
||||
vec4 cascade_far_view_z; // far view-space Z per cascade
|
||||
vec4 cascade_texel_world; // one shadow texel in world units per cascade
|
||||
vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade
|
||||
vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV
|
||||
mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
};
|
||||
|
|
@ -171,54 +174,57 @@ layout( binding = 3 ) uniform sampler smp_ao;
|
|||
|
||||
#pragma sokol @include ../common/shadow_pcf.glsl
|
||||
|
||||
// Normal-offset shadows, see cube.glsl for the longer note.
|
||||
float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal )
|
||||
{
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 );
|
||||
float texel_world = cascade_texel_world[cascade];
|
||||
float depth_bias = cascade_depth_bias[cascade];
|
||||
|
||||
// Shrink the kernel in the coarser cascades so the penumbra keeps a
|
||||
// constant world width. See cube.glsl for the longer note.
|
||||
float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 );
|
||||
|
||||
// Slide the lookup along the surface far enough to clear the whole
|
||||
// scaled 7x7 footprint, growing toward grazing light.
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) );
|
||||
float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world;
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
// Backend-dependent Y orientation, see cube.glsl for the longer note.
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
|
||||
if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) )
|
||||
if ( light_uv.z < 0.0 || light_uv.z > 1.0 )
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float bias = mix( 0.0040, 0.0008, n_dot_l );
|
||||
|
||||
float pcf = sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, bias, cascade_pcf_scale[cascade] );
|
||||
|
||||
// See cube.glsl for the longer note. Cascade 2 has no fallback at its
|
||||
// UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the
|
||||
// polygonal seam where cascade 2's spatial extent ends on the ground.
|
||||
if ( cascade == 2 )
|
||||
// The white border dissolves the XY boundary, only reject past the
|
||||
// kernel's reach. See cube.glsl for the longer note.
|
||||
float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y;
|
||||
if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) )
|
||||
{
|
||||
vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy );
|
||||
float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 );
|
||||
pcf = mix( 1.0, pcf, fade );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return pcf;
|
||||
return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y );
|
||||
}
|
||||
|
||||
float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
float shadow = sampleCascade( cascade, world_pos, world_normal );
|
||||
|
||||
// Blend the last 10% of each cascade's range with the next cascade
|
||||
// to hide the polygonal step where they meet. See cube.glsl for the
|
||||
// longer note.
|
||||
if ( cascade < 2 )
|
||||
if ( cascade < SHADOW_CASCADE_COUNT - 1 )
|
||||
{
|
||||
float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y;
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x;
|
||||
float far_z = cascade_far_view_z[cascade];
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1];
|
||||
float blend_start = mix( far_z, near_z, 0.1 );
|
||||
if ( view_z > blend_start )
|
||||
{
|
||||
|
|
@ -408,25 +414,16 @@ void main()
|
|||
if ( flags.x == 2 )
|
||||
{
|
||||
float view_z_dbg = -( view * vec4( hit_world, 1.0 ) ).z;
|
||||
int cascade = 2;
|
||||
if ( view_z_dbg < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z_dbg < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z_dbg );
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( hit_world, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) );
|
||||
vec3 tint = vec3( 1.0 );
|
||||
if ( !oob )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
tint = vec3( 1.0, 0.4, 0.4 );
|
||||
else if ( cascade == 1 )
|
||||
tint = vec3( 0.4, 1.0, 0.4 );
|
||||
else
|
||||
tint = vec3( 0.4, 0.4, 1.0 );
|
||||
tint = shadowCascadeTint( cascade );
|
||||
}
|
||||
out_color = vec4( tint, 1.0 );
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
// debug_view_mode (ub_pass.flags.x) selects the output:
|
||||
// 0 = Lambert + ambient * shadow factor.
|
||||
// 1 = view-space distance from camera as grayscale.
|
||||
// 2 = cascade-index tint (red/green/blue = cascade 0/1/2, white = UV
|
||||
// 2 = cascade-index tint (one color per cascade, white = UV
|
||||
// out of bounds on the chosen cascade, i.e. unsampled).
|
||||
//
|
||||
// UBO bindings are stage-specific in sokol-shdc.
|
||||
|
|
@ -101,19 +101,22 @@ void main()
|
|||
#pragma sokol @fs fs
|
||||
|
||||
#pragma sokol @include ../common/pbr.glsl
|
||||
#pragma sokol @include ../common/shadow_cascade.glsl
|
||||
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
vec4 sun_dir_view; // .xyz = view-space dir TO sun (normalized), for direct lighting
|
||||
vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback)
|
||||
ivec4 flags; // .x = debug_view_mode
|
||||
vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade
|
||||
mat4 cascade_matrices[3]; // light-space view-proj per cascade
|
||||
vec4 cascade_pcf_scale; // .xyz = PCF tap-offset scale per cascade (constant world penumbra)
|
||||
mat4 view; // IBL: world->view rotation for view->world n_view transform
|
||||
vec4 camera_pos_world; // IBL: world camera pos for V_world derivation
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
vec4 sun_dir_view; // .xyz = view-space dir TO sun (normalized), for direct lighting
|
||||
vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback)
|
||||
ivec4 flags; // .x = debug_view_mode
|
||||
vec4 cascade_far_view_z; // far view-space Z per cascade
|
||||
vec4 cascade_texel_world; // one shadow texel in world units per cascade
|
||||
vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade
|
||||
vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV
|
||||
mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade
|
||||
mat4 view; // IBL: world->view rotation for view->world n_view transform
|
||||
vec4 camera_pos_world; // IBL: world camera pos for V_world derivation
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
};
|
||||
|
||||
// binding=1 (not 0): sokol-shdc enforces disjoint binding numbers between
|
||||
|
|
@ -155,87 +158,92 @@ out vec4 out_color;
|
|||
// Kernel details and the X3570 unrolling note live in the include.
|
||||
#pragma sokol @include ../common/shadow_pcf.glsl
|
||||
|
||||
float sampleCascade( int cascade, vec3 world_pos, float n_dot_l )
|
||||
// Normal-offset shadows. A depth bias pushes the comparison back along
|
||||
// the light, which detaches contact shadows and can never win at a
|
||||
// silhouette where the stored depth gradient is effectively infinite.
|
||||
// Moving the lookup sideways along the surface normal instead reads a
|
||||
// well-behaved part of the map and leaves the compared depth alone, so
|
||||
// contacts stay welded to the ground.
|
||||
float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal, float n_dot_l )
|
||||
{
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 );
|
||||
float texel_world = cascade_texel_world[cascade];
|
||||
float depth_bias = cascade_depth_bias[cascade];
|
||||
|
||||
// Shrink the kernel in the coarser cascades so the penumbra keeps a
|
||||
// constant world width instead of going crisp to blurry at every
|
||||
// boundary. The floor leaves the taps about two texels apart, close
|
||||
// enough that the hardware 2x2 compare still overlaps them.
|
||||
float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 );
|
||||
|
||||
// Sine of the angle between surface and light. Zero facing the light
|
||||
// where no offset is wanted, growing toward grazing. The offset has to
|
||||
// clear the whole filter, not one texel, or the outer ring of the
|
||||
// kernel self-shadows into a texel-quantized comb along the
|
||||
// terminator. 3 texels is the scaled 7x7 half-width, plus the sampling
|
||||
// snap, and the root two reaches the kernel's corner tap.
|
||||
float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) );
|
||||
float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world;
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
|
||||
// UV.y orientation is BACKEND-DEPENDENT. D3D11/Metal/WebGPU sample
|
||||
// render targets with V = 0 at the top (NDC.y = +1 -> texture row 0),
|
||||
// they need UV.y = 0.5 - NDC.y * 0.5. OpenGL samples with V = 0 at
|
||||
// the bottom (NDC.y = +1 -> top row N-1), it needs the textbook
|
||||
// UV.y = NDC.y * 0.5 + 0.5. Renderer side sets cascade_far_view_z.w
|
||||
// to -1 on D3D11/Metal/WGPU and +1 on glcore so a single multiply
|
||||
// UV.y = NDC.y * 0.5 + 0.5. Renderer side sets the sign to -1 on
|
||||
// D3D11/Metal/WGPU and +1 on glcore so a single multiply
|
||||
// here picks the right convention.
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
|
||||
if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) )
|
||||
if ( light_uv.z < 0.0 || light_uv.z > 1.0 )
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
// Slope-scaled bias: tan(angle to light) = sqrt(1 - n.l^2) / n.l.
|
||||
// Constant texel-step factor keeps the bias roughly the same world
|
||||
// size across cascades (each cascade's depth range scales with its
|
||||
// bounding sphere, bias scales with it via the texel step).
|
||||
float ndl = clamp( n_dot_l, 0.001, 1.0 );
|
||||
float tanAngle = sqrt( 1.0 - ndl * ndl ) / ndl;
|
||||
float texelDepthStep = 0.001;
|
||||
float bias = clamp( texelDepthStep * tanAngle, 0.0005, 0.05 );
|
||||
|
||||
float pcf = sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, bias, cascade_pcf_scale[cascade] );
|
||||
|
||||
// Cascade 2 is the last cascade, sampleShadowCascaded's view-z blend
|
||||
// has nothing to blend into beyond it. On flat ground at glancing sun
|
||||
// angles PCF inside the cascade reads slightly below 1.0 (bias slop
|
||||
// across a kernel that covers ~5 cm of world per texel here), while
|
||||
// fragments outside the cascade's spatial sphere fall through to the
|
||||
// OOB return of 1.0. Without smoothing, cascade 2's UV boundary reads
|
||||
// as a hexagonal polygon on the ground. Fade PCF toward 1.0 over the
|
||||
// outer 10% of UV space to hide the seam.
|
||||
if ( cascade == 2 )
|
||||
// No hard XY bounds test. The sampler's white border makes taps past
|
||||
// the edge compare lit, so the boundary dissolves across the kernel
|
||||
// rather than flipping whole pixels between sampled and lit as the
|
||||
// texel snap steps the map. Rejecting only what lies beyond the
|
||||
// kernel's reach is exact and spares nine taps for everything well
|
||||
// outside the cascade.
|
||||
//
|
||||
// The 3 * scale here and in the normal offset above both encode the
|
||||
// 7x7 kernel's three-texel radius. Widen the kernel and both have to
|
||||
// grow, or the outer ring self-shadows along the terminator.
|
||||
float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y;
|
||||
if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) )
|
||||
{
|
||||
vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy );
|
||||
float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 );
|
||||
pcf = mix( 1.0, pcf, fade );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return pcf;
|
||||
return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y );
|
||||
}
|
||||
|
||||
// n_dot_l is the (clamped) dot of the surface normal with the sun
|
||||
// direction, passed in by the caller in whichever space is convenient
|
||||
// (rotation-invariant, same value in view and world space).
|
||||
float sampleShadowCascaded( vec3 world_pos, float n_dot_l, float view_z )
|
||||
// (rotation-invariant, same value in view and world space). The normal
|
||||
// itself must be world space, it steers the normal offset.
|
||||
float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float n_dot_l, float view_z )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
{
|
||||
cascade = 0;
|
||||
}
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
{
|
||||
cascade = 1;
|
||||
}
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
float shadow = sampleCascade( cascade, world_pos, n_dot_l );
|
||||
float shadow = sampleCascade( cascade, world_pos, world_normal, n_dot_l );
|
||||
|
||||
// Blend the last 10% of each cascade's range with the next cascade.
|
||||
// Each cascade uses the same slope-scaled bias in shadow-UV units,
|
||||
// but cascades cover very different world extents (cascade 0 ~= 1 m,
|
||||
// cascade 2 ~= 25 m+), so PCF response on flat receivers differs
|
||||
// slightly per cascade, without this blend the boundary reads as a
|
||||
// polygonal step on the ground at glancing sun angles.
|
||||
if ( cascade < 2 )
|
||||
// Texel density jumps by roughly 2.5x at every boundary, so even with
|
||||
// matched bias the penumbra width changes there. Without the blend
|
||||
// that reads as a polygonal step on the ground.
|
||||
if ( cascade < SHADOW_CASCADE_COUNT - 1 )
|
||||
{
|
||||
float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y;
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x;
|
||||
float far_z = cascade_far_view_z[cascade];
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1];
|
||||
float blend_start = mix( far_z, near_z, 0.1 );
|
||||
if ( view_z > blend_start )
|
||||
{
|
||||
float alpha = ( view_z - blend_start ) / ( far_z - blend_start );
|
||||
shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, n_dot_l ), alpha );
|
||||
shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, world_normal, n_dot_l ), alpha );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -255,14 +263,14 @@ void main()
|
|||
// GL's dFdy points in +view_y (screen origin is lower-left), while HLSL
|
||||
// ddy and Metal dfdy point in -view_y (screen origin is upper-left).
|
||||
// sokol-shdc cross-compiles dFdy->ddy/dfdy without a sign flip, so the raw
|
||||
// value's screen direction depends on the backend. cascade_far_view_z.w
|
||||
// value's screen direction depends on the backend. shadow_params.x
|
||||
// is +1 on glcore/gles3 and -1 on D3D11/Metal/WGPU (same flag used by
|
||||
// the shadow UV.y remap below), negating it gives a multiplier that
|
||||
// canonicalizes dFdy to the -view_y direction on every backend. With
|
||||
// canonical dy, cross(dy, dx) = (-view_y) x (+view_x) = +view_z, which
|
||||
// points toward the camera (out of the screen), the correct outward
|
||||
// normal for a back-culled front face.
|
||||
vec3 dy = dFdy( v_view_pos ) * ( -cascade_far_view_z.w );
|
||||
vec3 dy = dFdy( v_view_pos ) * ( -shadow_params.x );
|
||||
vec3 n_view = normalize( cross( dy, dx ) );
|
||||
|
||||
float view_z = -v_view_pos.z;
|
||||
|
|
@ -278,36 +286,17 @@ void main()
|
|||
// Debug view : shadow cascades
|
||||
if ( flags.x == 2 )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
{
|
||||
cascade = 0;
|
||||
}
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
{
|
||||
cascade = 1;
|
||||
}
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( v_world_pos, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) );
|
||||
vec3 tint = vec3( 1.0 );
|
||||
if ( !oob )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
{
|
||||
tint = vec3( 1.0, 0.4, 0.4 );
|
||||
}
|
||||
else if ( cascade == 1 )
|
||||
{
|
||||
tint = vec3( 0.4, 1.0, 0.4 );
|
||||
}
|
||||
else
|
||||
{
|
||||
tint = vec3( 0.4, 0.4, 1.0 );
|
||||
}
|
||||
tint = shadowCascadeTint( cascade );
|
||||
}
|
||||
out_color = vec4( tint, 1.0 );
|
||||
return;
|
||||
|
|
@ -335,23 +324,25 @@ void main()
|
|||
return;
|
||||
}
|
||||
|
||||
// The shadow normal offset and IBL both need a world-space N. view is
|
||||
// the world->view matrix, its 3x3 is orthonormal (camera rotation), so
|
||||
// transpose(mat3(view)) takes view-space -> world-space without
|
||||
// inverse cost. Stays clear of the D3D11 cross-product handedness trap
|
||||
// that forced n_view to be computed in view space. Only rotate here,
|
||||
// no derivatives.
|
||||
mat3 view_to_world = transpose( mat3( view ) );
|
||||
vec3 N_world = normalize( view_to_world * n_view );
|
||||
|
||||
// dot(n, L) is rotation-invariant. Same value with view-space or world-space
|
||||
// normals + sun directions. Use the view-space pair for direct light.
|
||||
vec3 L = normalize( sun_dir_view.xyz );
|
||||
float n_dot_l = max( dot( n_view, L ), 0.0 );
|
||||
float shadow = sampleShadowCascaded( v_world_pos, n_dot_l, view_z );
|
||||
float shadow = sampleShadowCascaded( v_world_pos, N_world, n_dot_l, view_z );
|
||||
|
||||
// Camera sits at origin in view space, so V_view = normalize(-v_view_pos).
|
||||
vec3 V_view = normalize( -v_view_pos );
|
||||
vec3 direct = brdf_evaluate( n_view, V_view, L, sun_color.rgb * shadow, v_base_color.rgb, v_material.x, v_material.y );
|
||||
|
||||
// IBL needs world-space N and V. view is the world->view matrix, its
|
||||
// 3x3 is orthonormal (camera rotation), so transpose(mat3(view))
|
||||
// takes view-space -> world-space without inverse cost. Stays clear
|
||||
// of the D3D11 cross-product handedness trap that forced n_view to
|
||||
// be computed in view space. Only rotate here, no derivatives.
|
||||
mat3 view_to_world = transpose( mat3( view ) );
|
||||
vec3 N_world = normalize( view_to_world * n_view );
|
||||
vec3 V_world = normalize( camera_pos_world.xyz - v_world_pos );
|
||||
vec3 ambient = pbrEvaluateAmbient( ibl_params.y > 0.5, N_world, V_world, v_base_color.rgb, v_material.x, v_material.y,
|
||||
sun_color.a, sh, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, ibl_params.x );
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ void main()
|
|||
#pragma sokol @fs fs
|
||||
|
||||
#pragma sokol @include ../common/pbr.glsl
|
||||
#pragma sokol @include ../common/shadow_cascade.glsl
|
||||
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
|
|
@ -110,9 +111,11 @@ layout( binding = 1 ) uniform ub_pass
|
|||
vec4 camera_pos; // .xyz = camera world pos, .w unused
|
||||
vec4 grid_offset; // .xy = origin wrapped to grid period (lines), .zw = full origin (axes)
|
||||
mat4 view; // for view-space depth debug mode + cascade selection
|
||||
vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade
|
||||
mat4 cascade_matrices[3]; // light-space view-proj per cascade
|
||||
vec4 cascade_pcf_scale; // .xyz = PCF tap-offset scale per cascade (constant world penumbra)
|
||||
vec4 cascade_far_view_z; // far view-space Z per cascade
|
||||
vec4 cascade_texel_world; // one shadow texel in world units per cascade
|
||||
vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade
|
||||
vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV
|
||||
mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
};
|
||||
|
|
@ -141,54 +144,57 @@ layout( binding = 3 ) uniform sampler smp_ao;
|
|||
|
||||
#pragma sokol @include ../common/shadow_pcf.glsl
|
||||
|
||||
// Normal-offset shadows, see cube.glsl for the longer note.
|
||||
float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal )
|
||||
{
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 );
|
||||
float texel_world = cascade_texel_world[cascade];
|
||||
float depth_bias = cascade_depth_bias[cascade];
|
||||
|
||||
// Shrink the kernel in the coarser cascades so the penumbra keeps a
|
||||
// constant world width. See cube.glsl for the longer note.
|
||||
float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 );
|
||||
|
||||
// Slide the lookup along the surface far enough to clear the whole
|
||||
// scaled 7x7 footprint, growing toward grazing light.
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) );
|
||||
float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world;
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
// Backend-dependent Y orientation, see cube.glsl for the longer note.
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
|
||||
if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) )
|
||||
if ( light_uv.z < 0.0 || light_uv.z > 1.0 )
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float bias = mix( 0.0040, 0.0008, n_dot_l );
|
||||
|
||||
float pcf = sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, bias, cascade_pcf_scale[cascade] );
|
||||
|
||||
// See cube.glsl for the longer note. Cascade 2 has no fallback at its
|
||||
// UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the
|
||||
// polygonal seam where cascade 2's spatial extent ends on the ground.
|
||||
if ( cascade == 2 )
|
||||
// The white border dissolves the XY boundary, only reject past the
|
||||
// kernel's reach. See cube.glsl for the longer note.
|
||||
float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y;
|
||||
if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) )
|
||||
{
|
||||
vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy );
|
||||
float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 );
|
||||
pcf = mix( 1.0, pcf, fade );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return pcf;
|
||||
return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y );
|
||||
}
|
||||
|
||||
float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
float shadow = sampleCascade( cascade, world_pos, world_normal );
|
||||
|
||||
// Blend the last 10% of each cascade's range with the next cascade
|
||||
// to hide the polygonal step where they meet. See cube.glsl for the
|
||||
// longer note.
|
||||
if ( cascade < 2 )
|
||||
if ( cascade < SHADOW_CASCADE_COUNT - 1 )
|
||||
{
|
||||
float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y;
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x;
|
||||
float far_z = cascade_far_view_z[cascade];
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1];
|
||||
float blend_start = mix( far_z, near_z, 0.1 );
|
||||
if ( view_z > blend_start )
|
||||
{
|
||||
|
|
@ -230,25 +236,16 @@ void main()
|
|||
{
|
||||
// v_view_pos is actually world_pos forwarded from the VS.
|
||||
float view_z_dbg = -( view * vec4( v_view_pos, 1.0 ) ).z;
|
||||
int cascade = 2;
|
||||
if ( view_z_dbg < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z_dbg < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z_dbg );
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( v_view_pos, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) );
|
||||
vec3 tint = vec3( 1.0 );
|
||||
if ( !oob )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
tint = vec3( 1.0, 0.4, 0.4 );
|
||||
else if ( cascade == 1 )
|
||||
tint = vec3( 0.4, 1.0, 0.4 );
|
||||
else
|
||||
tint = vec3( 0.4, 0.4, 1.0 );
|
||||
tint = shadowCascadeTint( cascade );
|
||||
}
|
||||
out_color = vec4( tint, 1.0 );
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,28 +1,18 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Shadow caster for capsules. As with the sphere caster, we substitute
|
||||
// a proxy mesh for the analytic impostor. The proxy is a lat/long cylinder
|
||||
// with two hemispherical caps (see BuildCapsuleProxy in renderer.c for
|
||||
// counts and the silhouette-straddling scale). Vertices are authored in
|
||||
// a "unit-capsule" coordinate frame where each component carries enough
|
||||
// information to scale independently by halfLength and radius.
|
||||
// Shadow caster for capsules. See shadow_caster_sphere.glsl for why the
|
||||
// analytic surface is worth the fill cost and what `depth_greater` rests
|
||||
// on.
|
||||
//
|
||||
// Each vertex is encoded as two attributes:
|
||||
// in_axis, direction along the long axis (vec3). Scaled by halfLength.
|
||||
// For body verts: (+/-1, 0, 0). For cap verts: same as the
|
||||
// attached cap (i.e., (+1,0,0) for +X cap, (-1,0,0) for -X).
|
||||
// in_radial, radial offset (vec3). Scaled by radius. For body verts:
|
||||
// (0, cos theta, sin theta). For cap verts: an extension of the
|
||||
// hemisphere parameterization that includes the cap's
|
||||
// axial bulge, e.g. for +X cap at latitude alpha: in_radial =
|
||||
// (sin alpha, cos alpha cos beta, cos alpha sin beta).
|
||||
// Rasterizes the same OBB the lit capsule impostor uses, half-extents
|
||||
// (halfLength + radius, radius, radius) about the local +X axis.
|
||||
//
|
||||
// The world position is then
|
||||
// world = center + R * (in_axis * halfLength + in_radial * radius)
|
||||
// where R is the capsule's rotation. Since rotation is orthonormal and
|
||||
// halfLength/radius are scalars, the encoding scales linearly and
|
||||
// produces a true capsule for any (halfLength, radius) pair.
|
||||
// Only the entry point matters here, not the normal, so this is a
|
||||
// cheaper intersection than the lit shader's. The capsule is the union
|
||||
// of a finite cylinder and two cap spheres, and the entry into a union
|
||||
// is the nearest entry across its parts, so the hemisphere-rejection
|
||||
// the lit shader needs for correct normals is unnecessary.
|
||||
//
|
||||
// `@module shadow_capsule` namespaces the generated symbols.
|
||||
|
||||
|
|
@ -61,8 +51,14 @@ layout( binding = 0 ) readonly buffer instances
|
|||
instance items[];
|
||||
};
|
||||
|
||||
in vec3 in_axis; // axis-direction component, scaled by halfLength
|
||||
in vec3 in_radial; // radial component, scaled by radius
|
||||
in vec3 in_pos; // unit-cube corner, half-extent 0.5
|
||||
|
||||
out vec3 v_world_pos_proxy;
|
||||
|
||||
flat out vec3 v_center;
|
||||
flat out float v_half_length;
|
||||
flat out float v_radius;
|
||||
flat out vec3 v_axis_x_world;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -71,16 +67,120 @@ void main()
|
|||
float halfLength = inst.params.x;
|
||||
float radius = inst.params.y;
|
||||
|
||||
vec3 local_pos = in_axis * halfLength + in_radial * radius;
|
||||
vec3 world_pos = center + vec3( dot( inst.xform_row0.xyz, local_pos ), dot( inst.xform_row1.xyz, local_pos ),
|
||||
dot( inst.xform_row2.xyz, local_pos ) );
|
||||
vec3 obj_pos = vec3( in_pos.x * 2.0 * ( halfLength + radius ), in_pos.y * 2.0 * radius, in_pos.z * 2.0 * radius );
|
||||
vec3 world_pos = center + vec3( dot( inst.xform_row0.xyz, obj_pos ), dot( inst.xform_row1.xyz, obj_pos ),
|
||||
dot( inst.xform_row2.xyz, obj_pos ) );
|
||||
|
||||
v_world_pos_proxy = world_pos;
|
||||
v_center = center;
|
||||
v_half_length = halfLength;
|
||||
v_radius = radius;
|
||||
// Local +X in world is the first column of R.
|
||||
v_axis_x_world = vec3( inst.xform_row0.x, inst.xform_row1.x, inst.xform_row2.x );
|
||||
|
||||
gl_Position = light_view_proj * vec4( world_pos, 1.0 );
|
||||
}
|
||||
#pragma sokol @end
|
||||
|
||||
#pragma sokol @fs fs
|
||||
|
||||
// UBOs are per-stage in sokol-shdc, so this is a second block rather
|
||||
// than a reuse of the VS ub_frame.
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
vec4 light_dir; // .xyz = world-space direction light travels (normalized)
|
||||
vec4 depth_row; // depth row of the light view-proj, world position to clip depth
|
||||
};
|
||||
|
||||
in vec3 v_world_pos_proxy;
|
||||
|
||||
flat in vec3 v_center;
|
||||
flat in float v_half_length;
|
||||
flat in float v_radius;
|
||||
flat in vec3 v_axis_x_world;
|
||||
|
||||
layout( depth_greater ) out float gl_FragDepth;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ro = v_world_pos_proxy;
|
||||
vec3 rd = light_dir.xyz;
|
||||
|
||||
vec3 pa = v_center - v_half_length * v_axis_x_world;
|
||||
vec3 pb = v_center + v_half_length * v_axis_x_world;
|
||||
|
||||
// Ray-cylinder, Quilez closed form.
|
||||
// Reference: https://iquilezles.org/articles/intersectors/
|
||||
vec3 ba = pb - pa;
|
||||
vec3 oa = ro - pa;
|
||||
float baba = dot( ba, ba );
|
||||
float bard = dot( ba, rd );
|
||||
float baoa = dot( ba, oa );
|
||||
float rdoa = dot( rd, oa );
|
||||
float oaoa = dot( oa, oa );
|
||||
|
||||
float a_c = baba - bard * bard;
|
||||
float b_c = baba * rdoa - baoa * bard;
|
||||
float c_c = baba * oaoa - baoa * baoa - v_radius * v_radius * baba;
|
||||
float h_c = b_c * b_c - a_c * c_c;
|
||||
|
||||
float t = -1.0;
|
||||
|
||||
// Entry into each part, clamped forward rather than rejected. The
|
||||
// proxy faces are tangent to the surface along a line, and rounding
|
||||
// there puts the origin a hair inside, which drives the near root
|
||||
// negative. Treating that as a miss punches a dashed hole straight
|
||||
// down the middle of the shadow. A part whose far root is behind us
|
||||
// too is a genuine miss, which is what the end faces need: they sit
|
||||
// beyond one cap and the other cap is legitimately behind.
|
||||
//
|
||||
// a_c collapses when the ray runs along the axis, the caps cover
|
||||
// that case. baba collapses when halfLength is zero, and the axial
|
||||
// range test rejects the body for free.
|
||||
if ( h_c >= 0.0 && a_c > 1e-8 )
|
||||
{
|
||||
float q = sqrt( h_c );
|
||||
if ( -b_c + q >= 0.0 )
|
||||
{
|
||||
float t_body = max( ( -b_c - q ) / a_c, 0.0 );
|
||||
float y = baoa + t_body * bard;
|
||||
if ( y > 0.0 && y < baba )
|
||||
{
|
||||
t = t_body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cap spheres at both ends.
|
||||
for ( int i = 0; i < 2; ++i )
|
||||
{
|
||||
vec3 p = ( i == 0 ) ? pa : pb;
|
||||
vec3 oc = ro - p;
|
||||
float b = dot( oc, rd );
|
||||
float c = dot( oc, oc ) - v_radius * v_radius;
|
||||
float h = b * b - c;
|
||||
if ( h >= 0.0 )
|
||||
{
|
||||
float q = sqrt( h );
|
||||
if ( -b + q >= 0.0 )
|
||||
{
|
||||
float tc = max( -b - q, 0.0 );
|
||||
if ( t < 0.0 || tc < t )
|
||||
{
|
||||
t = tc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( t < 0.0 )
|
||||
{
|
||||
// OBB corner, the ray clears the capsule.
|
||||
discard;
|
||||
}
|
||||
|
||||
// Orthographic light, so the clip w is 1 and the divide drops out.
|
||||
gl_FragDepth = dot( depth_row, vec4( ro + t * rd, 1.0 ) );
|
||||
}
|
||||
#pragma sokol @end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,36 @@
|
|||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Shadow caster for spheres. The lit sphere pipeline ray-casts an
|
||||
// analytic sphere from a bounding-cube proxy, but we can't afford to
|
||||
// write gl_FragDepth in a depth-only shadow pass (early-Z killed, high
|
||||
// shadow-map resolution makes the cost prohibitive). Instead the shadow
|
||||
// pipeline rasterizes a low-poly icosphere proxy (subdiv-1, 42 verts, 80
|
||||
// tris) generated at InitRenderer and stored in dedicated icosphere vbuf/ibuf.
|
||||
// Shadow caster for spheres. Rasterizes the same bounding cube the lit
|
||||
// impostor uses and ray-casts the exact sphere, so caster and receiver
|
||||
// agree on where the surface is and bias only has to cover projection
|
||||
// and PCF slope. An inscribed proxy mesh falls short of the true surface
|
||||
// by a couple percent of the radius, and that gap has to be paid for
|
||||
// with extra depth bias.
|
||||
//
|
||||
// Per-vertex: in_pos is a unit-sphere position (length == 1). Per-instance
|
||||
// reads from the same sphere instance buffer the lit pipeline uses, the
|
||||
// rotation rows are ignored (a sphere is rotation-invariant) and only
|
||||
// the center (xform_row*.w) and radius (params.x) participate.
|
||||
// The light is directional, so every ray is parallel: the origin is the
|
||||
// proxy fragment's world position and the direction is the direction
|
||||
// light travels. Under an orthographic projection depth is linear in
|
||||
// distance along that direction, so marching forward from the proxy
|
||||
// face can only push depth away from the light. Hence
|
||||
// `layout(depth_greater)`, which lets the hardware keep early-Z
|
||||
// rejection despite the gl_FragDepth write. The promise rests on the
|
||||
// pipeline culling back faces, so the rasterized surface is always the
|
||||
// light-facing one.
|
||||
//
|
||||
// Depth is rebuilt from the projection's depth row rather than advanced
|
||||
// from gl_FragCoord.z, which would be one madd instead of a dot4. D3D11
|
||||
// rejects a pixel shader that both reads SV_Position and writes
|
||||
// conservative depth unless the position input is declared
|
||||
// noperspective centroid or sample, and neither GLSL nor SPIRV-Cross
|
||||
// gives us a way to qualify it. The two agree to within rounding: the
|
||||
// only place they can disagree is the single point where the proxy face
|
||||
// is tangent to the surface.
|
||||
//
|
||||
// Per-instance reads from the same sphere instance buffer the lit
|
||||
// pipeline uses. The rotation rows are ignored (a sphere is
|
||||
// rotation-invariant) and only the center (xform_row*.w) and radius
|
||||
// (params.x) participate.
|
||||
//
|
||||
// `@module shadow_sphere` namespaces the generated symbols.
|
||||
|
||||
|
|
@ -50,21 +69,70 @@ layout( binding = 0 ) readonly buffer instances
|
|||
instance items[];
|
||||
};
|
||||
|
||||
in vec3 in_pos; // unit-icosphere vertex (length == 1)
|
||||
in vec3 in_pos; // unit-cube corner, half-extent 0.5
|
||||
|
||||
out vec3 v_world_pos_proxy;
|
||||
|
||||
flat out vec3 v_center;
|
||||
flat out float v_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
instance inst = items[inst_base.x + gl_InstanceIndex];
|
||||
vec3 center = vec3( inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w );
|
||||
float radius = inst.params.x;
|
||||
vec3 world_pos = center + radius * in_pos;
|
||||
|
||||
// Half-extent 0.5 scaled by 2*radius gives a cube exactly enclosing
|
||||
// the sphere. Rotation is skipped, a sphere is rotation-invariant.
|
||||
vec3 world_pos = center + ( 2.0 * radius ) * in_pos;
|
||||
|
||||
v_world_pos_proxy = world_pos;
|
||||
v_center = center;
|
||||
v_radius = radius;
|
||||
|
||||
gl_Position = light_view_proj * vec4( world_pos, 1.0 );
|
||||
}
|
||||
#pragma sokol @end
|
||||
|
||||
#pragma sokol @fs fs
|
||||
|
||||
// UBOs are per-stage in sokol-shdc, so this is a second block rather
|
||||
// than a reuse of the VS ub_frame.
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
vec4 light_dir; // .xyz = world-space direction light travels (normalized)
|
||||
vec4 depth_row; // depth row of the light view-proj, world position to clip depth
|
||||
};
|
||||
|
||||
in vec3 v_world_pos_proxy;
|
||||
|
||||
flat in vec3 v_center;
|
||||
flat in float v_radius;
|
||||
|
||||
layout( depth_greater ) out float gl_FragDepth;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ro = v_world_pos_proxy;
|
||||
vec3 rd = light_dir.xyz;
|
||||
|
||||
// Ray-sphere, near root. Reference: https://iquilezles.org/articles/intersectors/
|
||||
vec3 oc = ro - v_center;
|
||||
float b = dot( oc, rd );
|
||||
float c = dot( oc, oc ) - v_radius * v_radius;
|
||||
float h = b * b - c;
|
||||
if ( h < 0.0 )
|
||||
{
|
||||
// Cube corner, the ray clears the sphere.
|
||||
discard;
|
||||
}
|
||||
|
||||
// Non-negative because the proxy face is tangent to the sphere at
|
||||
// worst, never inside it.
|
||||
float t = max( -b - sqrt( h ), 0.0 );
|
||||
|
||||
// Orthographic light, so the clip w is 1 and the divide drops out.
|
||||
gl_FragDepth = dot( depth_row, vec4( ro + t * rd, 1.0 ) );
|
||||
}
|
||||
#pragma sokol @end
|
||||
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ void main()
|
|||
#pragma sokol @fs fs
|
||||
|
||||
#pragma sokol @include ../common/pbr.glsl
|
||||
#pragma sokol @include ../common/shadow_cascade.glsl
|
||||
|
||||
layout( binding = 1 ) uniform ub_pass
|
||||
{
|
||||
|
|
@ -137,9 +138,11 @@ layout( binding = 1 ) uniform ub_pass
|
|||
vec4 camera_pos; // .xyz = camera world pos, .w unused
|
||||
mat4 view_proj; // for reverse-Z gl_FragDepth
|
||||
mat4 view; // for view-space depth debug mode + cascade selection
|
||||
vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade
|
||||
mat4 cascade_matrices[3]; // light-space view-proj per cascade
|
||||
vec4 cascade_pcf_scale; // .xyz = PCF tap-offset scale per cascade (constant world penumbra)
|
||||
vec4 cascade_far_view_z; // far view-space Z per cascade
|
||||
vec4 cascade_texel_world; // one shadow texel in world units per cascade
|
||||
vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade
|
||||
vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV
|
||||
mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade
|
||||
vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz)
|
||||
vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved
|
||||
};
|
||||
|
|
@ -168,54 +171,57 @@ layout( binding = 3 ) uniform sampler smp_ao;
|
|||
|
||||
#pragma sokol @include ../common/shadow_pcf.glsl
|
||||
|
||||
// Normal-offset shadows, see cube.glsl for the longer note.
|
||||
float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal )
|
||||
{
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 );
|
||||
float texel_world = cascade_texel_world[cascade];
|
||||
float depth_bias = cascade_depth_bias[cascade];
|
||||
|
||||
// Shrink the kernel in the coarser cascades so the penumbra keeps a
|
||||
// constant world width. See cube.glsl for the longer note.
|
||||
float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 );
|
||||
|
||||
// Slide the lookup along the surface far enough to clear the whole
|
||||
// scaled 7x7 footprint, growing toward grazing light.
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) );
|
||||
float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world;
|
||||
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
// Backend-dependent Y orientation, see cube.glsl for the longer note.
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
|
||||
if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) )
|
||||
if ( light_uv.z < 0.0 || light_uv.z > 1.0 )
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 );
|
||||
float bias = mix( 0.0040, 0.0008, n_dot_l );
|
||||
|
||||
float pcf = sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, bias, cascade_pcf_scale[cascade] );
|
||||
|
||||
// See cube.glsl for the longer note. Cascade 2 has no fallback at its
|
||||
// UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the
|
||||
// polygonal seam where cascade 2's spatial extent ends on the ground.
|
||||
if ( cascade == 2 )
|
||||
// The white border dissolves the XY boundary, only reject past the
|
||||
// kernel's reach. See cube.glsl for the longer note.
|
||||
float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y;
|
||||
if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) )
|
||||
{
|
||||
vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy );
|
||||
float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 );
|
||||
pcf = mix( 1.0, pcf, fade );
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
return pcf;
|
||||
return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y );
|
||||
}
|
||||
|
||||
float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z )
|
||||
{
|
||||
int cascade = 2;
|
||||
if ( view_z < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z );
|
||||
|
||||
float shadow = sampleCascade( cascade, world_pos, world_normal );
|
||||
|
||||
// Blend the last 10% of each cascade's range with the next cascade
|
||||
// to hide the polygonal step where they meet. See cube.glsl for the
|
||||
// longer note.
|
||||
if ( cascade < 2 )
|
||||
if ( cascade < SHADOW_CASCADE_COUNT - 1 )
|
||||
{
|
||||
float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y;
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x;
|
||||
float far_z = cascade_far_view_z[cascade];
|
||||
float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1];
|
||||
float blend_start = mix( far_z, near_z, 0.1 );
|
||||
if ( view_z > blend_start )
|
||||
{
|
||||
|
|
@ -337,25 +343,16 @@ void main()
|
|||
if ( flags.x == 2 )
|
||||
{
|
||||
float view_z_dbg = -( view * vec4( hit_world, 1.0 ) ).z;
|
||||
int cascade = 2;
|
||||
if ( view_z_dbg < cascade_far_view_z.x )
|
||||
cascade = 0;
|
||||
else if ( view_z_dbg < cascade_far_view_z.y )
|
||||
cascade = 1;
|
||||
int cascade = selectShadowCascade( cascade_far_view_z, view_z_dbg );
|
||||
vec4 light_clip = cascade_matrices[cascade] * vec4( hit_world, 1.0 );
|
||||
vec3 light_ndc = light_clip.xyz / light_clip.w;
|
||||
float ny = light_ndc.y * cascade_far_view_z.w;
|
||||
float ny = light_ndc.y * shadow_params.x;
|
||||
vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z );
|
||||
bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) );
|
||||
vec3 tint = vec3( 1.0 );
|
||||
if ( !oob )
|
||||
{
|
||||
if ( cascade == 0 )
|
||||
tint = vec3( 1.0, 0.4, 0.4 );
|
||||
else if ( cascade == 1 )
|
||||
tint = vec3( 0.4, 1.0, 0.4 );
|
||||
else
|
||||
tint = vec3( 0.4, 0.4, 1.0 );
|
||||
tint = shadowCascadeTint( cascade );
|
||||
}
|
||||
out_color = vec4( tint, 1.0 );
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: 2022 Erin Catto
|
||||
// SPDX-FileCopyrightText: 2026 Erin Catto
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "benchmarks.h"
|
||||
|
|
|
|||
38
src/core.c
38
src/core.c
|
|
@ -115,7 +115,7 @@ void b3Log( const char* format, ... )
|
|||
|
||||
b3Version b3GetVersion( void )
|
||||
{
|
||||
return (b3Version){ 0, 1, 0 };
|
||||
return (b3Version){ 0, 2, 0 };
|
||||
}
|
||||
|
||||
bool b3IsDoublePrecision( void )
|
||||
|
|
@ -253,3 +253,39 @@ void b3StrCpy( char* dst, int size, const char* src )
|
|||
memset( dst, 0, size );
|
||||
}
|
||||
}
|
||||
|
||||
// Fowler/Noll/Vo FNV-1a salted by length, then the splitmix64 finalizer so tiny inputs
|
||||
// still spread across all bits.
|
||||
uint64_t b3Hash64NonZero( const uint8_t* bytes, int n )
|
||||
{
|
||||
uint64_t h = 0xcbf29ce484222325ull ^ (uint64_t)(uint32_t)n;
|
||||
const uint64_t prime = 0x100000001b3ull;
|
||||
int i = 0;
|
||||
|
||||
while ( i + 8 <= n )
|
||||
{
|
||||
uint64_t word;
|
||||
memcpy( &word, bytes + i, sizeof( word ) );
|
||||
#if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
word = ( ( word & 0x00000000000000FFULL ) << 56 ) | ( ( word & 0x000000000000FF00ULL ) << 40 ) |
|
||||
( ( word & 0x0000000000FF0000ULL ) << 24 ) | ( ( word & 0x00000000FF000000ULL ) << 8 ) |
|
||||
( ( word & 0x000000FF00000000ULL ) >> 8 ) | ( ( word & 0x0000FF0000000000ULL ) >> 24 ) |
|
||||
( ( word & 0x00FF000000000000ULL ) >> 40 ) | ( ( word & 0xFF00000000000000ULL ) >> 56 );
|
||||
#endif
|
||||
h = ( h ^ word ) * prime;
|
||||
i += 8;
|
||||
}
|
||||
|
||||
while ( i < n )
|
||||
{
|
||||
h = ( h ^ (uint64_t)bytes[i] ) * prime;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
h ^= h >> 30;
|
||||
h *= 0xbf58476d1ce4e5b9ull;
|
||||
h ^= h >> 27;
|
||||
h *= 0x94d049bb133111ebull;
|
||||
h ^= h >> 31;
|
||||
return h == 0 ? 1 : h;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,12 +140,6 @@ void* b3GrowAlloc( void* oldMem, int oldSize, int newSize );
|
|||
B3_PRINTF_FORMAT( 1, 2 )
|
||||
void b3Log( const char* format, ... );
|
||||
|
||||
// Geometry content hashes reserve zero to mean unhashed
|
||||
static inline uint32_t b3NonZeroHash( uint32_t hash )
|
||||
{
|
||||
return hash != 0 ? hash : 1;
|
||||
}
|
||||
|
||||
typedef struct b3Mutex b3Mutex;
|
||||
b3Mutex* b3CreateMutex( void );
|
||||
void b3DestroyMutex( b3Mutex* m );
|
||||
|
|
@ -165,3 +159,6 @@ b3Thread* b3CreateThread( b3ThreadFunction* function, void* context, const char*
|
|||
void b3JoinThread( b3Thread* t );
|
||||
|
||||
void b3StrCpy( char* dst, int size, const char* src );
|
||||
|
||||
// Good quality 64-bit hash that never returns 0.
|
||||
uint64_t b3Hash64NonZero( const uint8_t* bytes, int n );
|
||||
|
|
|
|||
|
|
@ -468,9 +468,8 @@ b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data )
|
|||
|
||||
b3Free( decompressedHeights, heightCount * sizeof( float ) );
|
||||
|
||||
// Content hash over the whole blob with the hash field zeroed, like b3HullData/b3MeshData.
|
||||
hf->hash = 0;
|
||||
hf->hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (const uint8_t*)hf, hf->byteCount ) );
|
||||
hf->hash = b3Hash64NonZero( (const uint8_t*)hf, hf->byteCount );
|
||||
|
||||
return hf;
|
||||
}
|
||||
|
|
|
|||
19
src/hull.c
19
src/hull.c
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
// Dirk Gregorius contributed portions of this code
|
||||
|
||||
#include "algorithm.h"
|
||||
#include "hull.h"
|
||||
|
||||
#include "algorithm.h"
|
||||
#include "math_internal.h"
|
||||
#include "shape.h"
|
||||
|
||||
|
|
@ -2258,7 +2259,7 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou
|
|||
}
|
||||
|
||||
hull->hash = 0;
|
||||
hull->hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (uint8_t*)hull, hull->byteCount ) );
|
||||
hull->hash = b3Hash64NonZero( (uint8_t*)hull, hull->byteCount );
|
||||
|
||||
return hull;
|
||||
}
|
||||
|
|
@ -2270,7 +2271,7 @@ b3HullData* b3CloneHull( const b3HullData* hull )
|
|||
return NULL;
|
||||
}
|
||||
|
||||
b3HullData* clone = (b3HullData*)b3Alloc( hull->byteCount );
|
||||
b3HullData* clone = b3Alloc( hull->byteCount );
|
||||
memcpy( clone, hull, hull->byteCount );
|
||||
|
||||
return clone;
|
||||
|
|
@ -2278,9 +2279,7 @@ b3HullData* b3CloneHull( const b3HullData* hull )
|
|||
|
||||
uint64_t b3HashHullData( const b3HullData* hull )
|
||||
{
|
||||
// The baked content hash already covers byteCount. Spread the 32 bits across 64 so the table
|
||||
// can use the high bits for its fast reject fragment.
|
||||
return (uint64_t)hull->hash * 0x9E3779B97F4A7C15ull;
|
||||
return hull->hash;
|
||||
}
|
||||
|
||||
bool b3CompareHullData( const b3HullData* hull1, const b3HullData* hull2 )
|
||||
|
|
@ -2301,7 +2300,7 @@ bool b3CompareHullData( const b3HullData* hull1, const b3HullData* hull2 )
|
|||
// Hull identity covers every byte, so the structs carry explicit padding. These lock
|
||||
// the layout, re-audit padding if a size changes.
|
||||
_Static_assert( sizeof( b3HullData ) == 144, "unexpected hull data size" );
|
||||
_Static_assert( sizeof( b3BoxHull ) == 648, "unexpected box hull size" );
|
||||
_Static_assert( sizeof( b3BoxHull ) == 640, "unexpected box hull size" );
|
||||
|
||||
// Implement b3HullMap.
|
||||
#define NAME b3HullMap
|
||||
|
|
@ -2494,8 +2493,9 @@ b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform tra
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Must ensure the hash is 0 so it doesn't contribute to itself.
|
||||
hull->hash = 0;
|
||||
hull->hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (uint8_t*)hull, hull->byteCount ) );
|
||||
hull->hash = b3Hash64NonZero( (uint8_t*)hull, hull->byteCount );
|
||||
|
||||
B3_VALIDATE( b3IsValidHull( hull ) );
|
||||
|
||||
|
|
@ -2863,8 +2863,9 @@ b3BoxHull b3MakeTransformedBoxHull( float hx, float hy, float hz, b3Transform tr
|
|||
boxHull.nz[6] = 0.0f;
|
||||
boxHull.nz[7] = 0.0f;
|
||||
|
||||
// Must ensure the hash is 0 so it doesn't contribute to itself.
|
||||
boxHull.base.hash = 0;
|
||||
boxHull.base.hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (uint8_t*)&boxHull, sizeof( b3BoxHull ) ) );
|
||||
boxHull.base.hash = b3Hash64NonZero( (uint8_t*)&boxHull.base, boxHull.base.byteCount );
|
||||
|
||||
return boxHull;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
// Content hash and equality over the whole baked hull. Shared by every hull
|
||||
// de-duplication map so they agree on identity.
|
||||
uint64_t b3HashHullData( const b3HullData* hull );
|
||||
bool b3CompareHullData( const b3HullData* hull1, const b3HullData* hull2 );
|
||||
|
||||
|
|
|
|||
|
|
@ -1762,7 +1762,7 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices,
|
|||
b3Array_Destroy( vertices );
|
||||
|
||||
mesh->hash = 0;
|
||||
mesh->hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (uint8_t*)mesh, mesh->byteCount ) );
|
||||
mesh->hash = b3Hash64NonZero((uint8_t*)mesh, mesh->byteCount );
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -658,6 +658,10 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void*
|
|||
if ( ( isFast == false || isMeshContact == false ) && recycleDistance > 0.0f &&
|
||||
( contact->flags & b3_relativeTransformValid ) && ( contact->flags & b3_contactRecycleFlag ) )
|
||||
{
|
||||
// The scalar part of b3InvMulQuat is just the quaternion dot product.
|
||||
// cos(relative_angle/2) = scalar(conj(q1) * q2) = dot(q1, q2)
|
||||
// A small relative angle means this value is close to 1. Need to use abs or square
|
||||
// due to double cover.
|
||||
float angleA = b3DotQuat( transformA.q, contact->cachedRotationA );
|
||||
float angleB = b3DotQuat( transformB.q, contact->cachedRotationB );
|
||||
float angularDistance = b3MinFloat( angleA * angleA, angleB * angleB );
|
||||
|
|
@ -1433,17 +1437,19 @@ void b3World_Draw( b3WorldId worldId, b3DebugDraw* draw, uint64_t maskBits )
|
|||
}
|
||||
}
|
||||
|
||||
if ( draw->drawMass && body->type == b3_dynamicBody )
|
||||
if ( draw->drawMass )
|
||||
{
|
||||
b3Vec3 offset = { 0.05f, 0.05f, 0.05f };
|
||||
|
||||
b3WorldTransform transform = { bodySim->center, bodySim->transform.q };
|
||||
draw->DrawTransformFcn( transform, draw->context );
|
||||
b3Pos p = b3TransformWorldPoint( transform, offset );
|
||||
|
||||
char buffer[32];
|
||||
snprintf( buffer, 32, "%.2f", body->mass );
|
||||
draw->DrawStringFcn( p, buffer, b3_colorWhite, draw->context );
|
||||
if (body->type == b3_dynamicBody)
|
||||
{
|
||||
b3Vec3 offset = { 0.05f, 0.05f, 0.05f };
|
||||
b3Pos p = b3TransformWorldPoint( transform, offset );
|
||||
char buffer[32];
|
||||
snprintf( buffer, 32, "%.2f", body->mass );
|
||||
draw->DrawStringFcn( p, buffer, b3_colorWhite, draw->context );
|
||||
}
|
||||
}
|
||||
|
||||
if ( draw->drawSleep )
|
||||
|
|
|
|||
|
|
@ -735,45 +735,6 @@ void b3RecEndRecord( b3Recording* rec )
|
|||
|
||||
// Geometry registry
|
||||
|
||||
// Full 64-bit content hash, so distinct blobs of the same length get independent bits. A reseeded
|
||||
// 32-bit djb2 cannot: djb2 is affine in its seed, so a same-length collision survives every seed and
|
||||
// the high word would just track the low one. Word folded for speed, byte order normalized on
|
||||
// big-endian to match b3Hash, then a splitmix64 finalizer so tiny inputs still spread across all bits.
|
||||
// From Fowler/Noll/Vo FNV-1a salted by length, then the splitmix64 mix.
|
||||
uint64_t b3Hash64Blob( const uint8_t* bytes, int n )
|
||||
{
|
||||
uint64_t h = 0xcbf29ce484222325ull ^ (uint64_t)(uint32_t)n;
|
||||
const uint64_t prime = 0x100000001b3ull;
|
||||
int i = 0;
|
||||
|
||||
while ( i + 8 <= n )
|
||||
{
|
||||
uint64_t word;
|
||||
memcpy( &word, bytes + i, sizeof( word ) );
|
||||
#if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
word = ( ( word & 0x00000000000000FFULL ) << 56 ) | ( ( word & 0x000000000000FF00ULL ) << 40 ) |
|
||||
( ( word & 0x0000000000FF0000ULL ) << 24 ) | ( ( word & 0x00000000FF000000ULL ) << 8 ) |
|
||||
( ( word & 0x000000FF00000000ULL ) >> 8 ) | ( ( word & 0x0000FF0000000000ULL ) >> 24 ) |
|
||||
( ( word & 0x00FF000000000000ULL ) >> 40 ) | ( ( word & 0xFF00000000000000ULL ) >> 56 );
|
||||
#endif
|
||||
h = ( h ^ word ) * prime;
|
||||
i += 8;
|
||||
}
|
||||
|
||||
while ( i < n )
|
||||
{
|
||||
h = ( h ^ (uint64_t)bytes[i] ) * prime;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
h ^= h >> 30;
|
||||
h *= 0xbf58476d1ce4e5b9ull;
|
||||
h ^= h >> 27;
|
||||
h *= 0x94d049bb133111ebull;
|
||||
h ^= h >> 31;
|
||||
return h;
|
||||
}
|
||||
|
||||
// Content hash to chain head, so dedup is near O(1). Colliding hashes share a head and are walked
|
||||
// through b3GeometryEntry::hashNext, so the byteCount + memcmp check always finds an existing blob.
|
||||
#define NAME b3GeometryHashMap
|
||||
|
|
@ -1186,7 +1147,7 @@ uint32_t b3RecInternHull( b3Recording* rec, const b3HullData* hull )
|
|||
int byteCount = hull->byteCount;
|
||||
uint8_t* bytes = b3Alloc( (size_t)byteCount );
|
||||
memcpy( bytes, hull, (size_t)byteCount );
|
||||
uint64_t h = b3Hash64Blob( bytes, byteCount );
|
||||
uint64_t h = b3Hash64NonZero( bytes, byteCount );
|
||||
return b3InternGeometry( &rec->registry, b3_geometryHull, h, bytes, byteCount );
|
||||
}
|
||||
|
||||
|
|
@ -1195,7 +1156,7 @@ uint32_t b3RecInternMesh( b3Recording* rec, const b3MeshData* mesh )
|
|||
int byteCount = mesh->byteCount;
|
||||
uint8_t* bytes = b3Alloc( (size_t)byteCount );
|
||||
memcpy( bytes, mesh, (size_t)byteCount );
|
||||
uint64_t h = b3Hash64Blob( bytes, byteCount );
|
||||
uint64_t h = b3Hash64NonZero( bytes, byteCount );
|
||||
return b3InternGeometry( &rec->registry, b3_geometryMesh, h, bytes, byteCount );
|
||||
}
|
||||
|
||||
|
|
@ -1204,7 +1165,7 @@ uint32_t b3RecInternHeightField( b3Recording* rec, const b3HeightFieldData* hf )
|
|||
int byteCount = hf->byteCount;
|
||||
uint8_t* bytes = b3Alloc( (size_t)byteCount );
|
||||
memcpy( bytes, hf, (size_t)byteCount );
|
||||
uint64_t h = b3Hash64Blob( bytes, byteCount );
|
||||
uint64_t h = b3Hash64NonZero( bytes, byteCount );
|
||||
return b3InternGeometry( &rec->registry, b3_geometryHeightField, h, bytes, byteCount );
|
||||
}
|
||||
|
||||
|
|
@ -1216,7 +1177,7 @@ uint32_t b3RecInternCompound( b3Recording* rec, const b3CompoundData* compound )
|
|||
// Null the tree node pointer in the copy so the canonical bytes are pointer-free.
|
||||
// b3ConvertBytesToCompound fixes it back on load via nodeOffset.
|
||||
( (b3CompoundData*)bytes )->tree.nodes = NULL;
|
||||
uint64_t h = b3Hash64Blob( bytes, byteCount );
|
||||
uint64_t h = b3Hash64NonZero( bytes, byteCount );
|
||||
return b3InternGeometry( &rec->registry, b3_geometryCompound, h, bytes, byteCount );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -373,8 +373,6 @@ uint32_t b3RecInternMesh( b3Recording* rec, const b3MeshData* mesh );
|
|||
uint32_t b3RecInternHeightField( b3Recording* rec, const b3HeightFieldData* hf );
|
||||
uint32_t b3RecInternCompound( b3Recording* rec, const b3CompoundData* compound );
|
||||
|
||||
uint64_t b3Hash64Blob( const uint8_t* bytes, int n );
|
||||
|
||||
// Lifecycle engine-side hooks
|
||||
void b3StartRecordingIntoBuffer( b3World* world, b3Recording* recording );
|
||||
void b3StopRecordingInternal( b3World* world );
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include "recording_replay.h"
|
||||
|
||||
#include "body.h"
|
||||
#include "compound.h"
|
||||
#include "physics_world.h"
|
||||
#include "world_snapshot.h"
|
||||
|
||||
|
|
@ -2176,7 +2175,7 @@ static int b3RecDispatchOne( b3RecReader* rdr )
|
|||
|
||||
bool b3ValidateReplay( const void* data, int size, int workerCount )
|
||||
{
|
||||
b3RecPlayer* player = b3RecPlayer_Create( data, size, workerCount );
|
||||
b3RecPlayer* player = b3CreatePlayer( data, size, workerCount );
|
||||
if ( player == NULL )
|
||||
{
|
||||
return false;
|
||||
|
|
@ -2191,7 +2190,7 @@ bool b3ValidateReplay( const void* data, int size, int workerCount )
|
|||
}
|
||||
|
||||
bool ok = player->rdr.ok && player->rdr.diverged == false;
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
|
@ -2600,7 +2599,7 @@ static void b3RecSeedKeyframeRegistry( b3RecPlayer* player )
|
|||
{
|
||||
memcpy( copy, slot->bytes, (size_t)slot->byteCount );
|
||||
}
|
||||
uint64_t h = b3Hash64Blob( slot->bytes, slot->byteCount );
|
||||
uint64_t h = b3Hash64NonZero( slot->bytes, slot->byteCount );
|
||||
uint32_t id = b3AppendGeometry( reg, slot->kind, h, copy, slot->byteCount );
|
||||
// Seeding in order without dedup keeps id == slot index.
|
||||
B3_ASSERT( id == (uint32_t)i );
|
||||
|
|
@ -2724,7 +2723,7 @@ static b3WorldId b3RecPlayerCreateWorld( const b3RecPlayer* player )
|
|||
return b3CreateWorld( &worldDef );
|
||||
}
|
||||
|
||||
b3RecPlayer* b3RecPlayer_Create( const void* data, int size, int workerCount )
|
||||
b3RecPlayer* b3CreatePlayer( const void* data, int size, int workerCount )
|
||||
{
|
||||
if ( data == NULL || size < (int)sizeof( b3RecHeader ) )
|
||||
{
|
||||
|
|
@ -2878,7 +2877,7 @@ b3RecPlayer* b3RecPlayer_Create( const void* data, int size, int workerCount )
|
|||
return player;
|
||||
}
|
||||
|
||||
void b3RecPlayer_Destroy( b3RecPlayer* player )
|
||||
void b3DestroyPlayer( b3RecPlayer* player )
|
||||
{
|
||||
if ( player == NULL )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ static bool b3ClipSegmentToTriangleFace( b3ClipVertex segment[2], const b3Vec3*
|
|||
}
|
||||
|
||||
// If the points are on different sides of the plane
|
||||
if ( distance1 * distance2 < 0.0f )
|
||||
if ( ( distance1 > 0.0f ) != ( distance2 > 0.0f ) )
|
||||
{
|
||||
// Find intersection point of edge and plane
|
||||
float t = distance1 / ( distance1 - distance2 );
|
||||
|
|
@ -199,6 +199,7 @@ static b3SeparatingAxis b3QueryTriangleAndCapsuleEdges( const b3Vec3* vertices,
|
|||
float squaredTolerance = 0.005f * 0.005f;
|
||||
|
||||
int edgeIndex = 2;
|
||||
float a = b3Dot( capsuleEdge, plane.normal );
|
||||
b3Vec3 v1 = vertices[2];
|
||||
for ( int index = 0; index < 3; ++index )
|
||||
{
|
||||
|
|
@ -209,12 +210,13 @@ static b3SeparatingAxis b3QueryTriangleAndCapsuleEdges( const b3Vec3* vertices,
|
|||
// Pretend the triangle edge embeds a zero area face with a side normal. This
|
||||
// provides a way to find an edge-edge normal that points outward from
|
||||
// the triangle.
|
||||
float a = b3Dot( capsuleEdge, plane.normal );
|
||||
float b = b3Dot( capsuleEdge, sideNormal );
|
||||
|
||||
// Is the capsule edge parallel to the triangle edge? If so, face contact can handle it.
|
||||
if ( a * a + b * b < squaredTolerance * b3LengthSquared( capsuleEdge ) )
|
||||
{
|
||||
v1 = v2;
|
||||
edgeIndex = index;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -346,9 +348,8 @@ static void b3BuildTriangleAndCapsuleEdgeContact( b3LocalManifold* manifold, con
|
|||
return;
|
||||
}
|
||||
|
||||
b3Vec3 point = b3Lerp( b3MulSub( result.point1, capsule->radius, normal ), result.point2, 0.5f );
|
||||
b3Vec3 point = b3Lerp( result.point1, b3MulSub( result.point2, capsule->radius, normal ), 0.5f );
|
||||
float separation = b3Dot( normal, b3Sub( p1, v1 ) );
|
||||
B3_VALIDATE( b3AbsFloat( separation - query.separation ) < B3_LINEAR_SLOP );
|
||||
|
||||
manifold->normal = normal;
|
||||
manifold->pointCount = 1;
|
||||
|
|
@ -448,7 +449,7 @@ void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const
|
|||
}
|
||||
|
||||
// Create contact from closest points.
|
||||
b3Vec3 point = b3MulSV( 0.5f, b3Add( b3Sub( distanceOutput.pointA, b3MulSV( radius, delta ) ), distanceOutput.pointB ) );
|
||||
b3Vec3 point = b3Lerp( distanceOutput.pointA, b3MulSub( distanceOutput.pointB, radius, delta ), 0.5f );
|
||||
|
||||
// Normal points from triangle to capsule.
|
||||
manifold->normal = delta;
|
||||
|
|
@ -489,6 +490,12 @@ void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const
|
|||
faceSeparation = b3MinFloat( manifold->points[0].separation, manifold->points[1].separation );
|
||||
}
|
||||
|
||||
if ( edgeQuery.indexA == B3_NULL_INDEX )
|
||||
{
|
||||
// No valid edge contact.
|
||||
return;
|
||||
}
|
||||
|
||||
// Face contact can be empty if it does not realize the axis of minimum penetration.
|
||||
// Create edge contact if face contact fails or edge contact is significantly better!
|
||||
float linearSlop = B3_LINEAR_SLOP;
|
||||
|
|
@ -926,10 +933,7 @@ static void b3CollideTriangleAndHullEdges( b3LocalManifold* manifold, int capaci
|
|||
return;
|
||||
}
|
||||
|
||||
// This can slide off the end from caching
|
||||
float separation = b3Dot( query.normal, b3Sub( pB, pA ) );
|
||||
B3_VALIDATE( b3AbsFloat( separation - query.separation ) < B3_LINEAR_SLOP );
|
||||
|
||||
b3Vec3 point = b3MulSV( 0.5f, b3Add( result.point1, result.point2 ) );
|
||||
|
||||
b3LocalManifoldPoint* pt = manifold->points + 0;
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
// state hash differ from the float build. Both modes are internally deterministic.
|
||||
#if defined( BOX3D_DOUBLE_PRECISION )
|
||||
#define RAGDOLL_SLEEP_STEP 297
|
||||
#define RAGDOLL_HASH 0x27FF38C1
|
||||
#define RAGDOLL_HASH 0xF4036C3A
|
||||
#define WAVE_PILE_SLEEP_STEP 297
|
||||
#define WAVE_PILE_HASH 0x420CA784
|
||||
#define WAVE_PILE_HASH 0x658C00CF
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0x1737F5BC
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
|
|
@ -30,9 +30,9 @@
|
|||
#define MESH_DROP_HASH 0x465381C5
|
||||
#else
|
||||
#define RAGDOLL_SLEEP_STEP 308
|
||||
#define RAGDOLL_HASH 0x1E5EDD79
|
||||
#define RAGDOLL_HASH 0x4D94E049
|
||||
#define WAVE_PILE_SLEEP_STEP 273
|
||||
#define WAVE_PILE_HASH 0x47233541
|
||||
#define WAVE_PILE_HASH 0x0BA28F3A
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0xB9F993A5
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
|
|
|
|||
|
|
@ -138,14 +138,14 @@ static int NameRoundTrip( void )
|
|||
|
||||
ENSURE( b3ValidateReplay( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ) );
|
||||
|
||||
b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
b3RecPlayer_SeekFrame( player, 20 );
|
||||
ENSURE( !b3RecPlayer_HasDiverged( player ) );
|
||||
ENSURE( CheckReplayNames( player ) == 0 );
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( rec );
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ static int RollbackNames( void )
|
|||
b3World_StopRecording( worldId );
|
||||
b3DestroyWorld( worldId );
|
||||
|
||||
b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
// Play to the end so the keyframe ring is populated.
|
||||
|
|
@ -195,7 +195,7 @@ static int RollbackNames( void )
|
|||
ENSURE( CheckReplayNames( player ) == 0 );
|
||||
}
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( rec );
|
||||
|
||||
// Every restore reloaded the name table; dropped duplicate copies must be freed, not leaked.
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ static int ScrubBackward( void )
|
|||
int sz = b3Recording_GetSize( rec );
|
||||
|
||||
// Create the player
|
||||
b3RecPlayer* player = b3RecPlayer_Create( data, sz, 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( data, sz, 1 );
|
||||
ENSURE( player != NULL );
|
||||
ENSURE( b3RecPlayer_GetFrameCount( player ) == totalFrames );
|
||||
|
||||
|
|
@ -340,7 +340,7 @@ static int ScrubBackward( void )
|
|||
}
|
||||
|
||||
b3Free( hashes, (size_t)( totalFrames + 1 ) * sizeof( uint64_t ) );
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( rec );
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -402,7 +402,7 @@ static int SeekWithHull( void )
|
|||
const uint8_t* data = b3Recording_GetData( rec );
|
||||
int sz = b3Recording_GetSize( rec );
|
||||
|
||||
b3RecPlayer* player = b3RecPlayer_Create( data, sz, 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( data, sz, 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
// Step to end
|
||||
|
|
@ -420,7 +420,7 @@ static int SeekWithHull( void )
|
|||
b3RecPlayer_SeekFrame( player, 0 );
|
||||
ENSURE( b3RecPlayer_GetFrame( player ) == 0 );
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( rec );
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -517,7 +517,7 @@ static int DebugShapeCallbacks( void )
|
|||
b3Recording* loaded = b3LoadRecordingFromFile( path );
|
||||
ENSURE( loaded != NULL );
|
||||
|
||||
b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( loaded ), b3Recording_GetSize( loaded ), 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( b3Recording_GetData( loaded ), b3Recording_GetSize( loaded ), 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
// Wiring the callbacks rebuilds the world and rewinds to frame 0.
|
||||
|
|
@ -543,7 +543,7 @@ static int DebugShapeCallbacks( void )
|
|||
ENSURE( counters.created > createdBefore );
|
||||
|
||||
// Teardown destroys the final world; every live shape is released, so the counts balance.
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
ENSURE( counters.created == counters.destroyed );
|
||||
|
||||
b3DestroyRecording( loaded );
|
||||
|
|
@ -604,7 +604,7 @@ static int PlayerAccessors( void )
|
|||
b3World_StopRecording( worldId );
|
||||
b3DestroyWorld( worldId );
|
||||
|
||||
b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
// Info reflects the recorded tuning and a non-degenerate bounds.
|
||||
|
|
@ -648,7 +648,7 @@ static int PlayerAccessors( void )
|
|||
ENSURE( b3RecPlayer_GetKeyframeBudget( player ) == (size_t)256 * 1024 * 1024 );
|
||||
ENSURE( b3RecPlayer_GetKeyframeBytes( player ) == 0 );
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( rec );
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -702,7 +702,7 @@ static int KeyframeHandleReuse( void )
|
|||
b3World_StopRecording( worldId );
|
||||
b3DestroyWorld( worldId );
|
||||
|
||||
b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
DebugShapeCounters counters = { 0, 0 };
|
||||
|
|
@ -726,7 +726,7 @@ static int KeyframeHandleReuse( void )
|
|||
ENSURE( counters.created == createdAfterFirstDraw );
|
||||
|
||||
// Teardown releases exactly the live handles, so the leak-free invariant holds.
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
ENSURE( counters.created == counters.destroyed );
|
||||
|
||||
b3DestroyRecording( rec );
|
||||
|
|
@ -835,7 +835,7 @@ static int QueryReplay( void )
|
|||
ENSURE( b3ValidateReplay( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ) );
|
||||
|
||||
// Player path: seek to a mid frame and confirm the per-frame store holds all seven queries.
|
||||
b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
b3RecPlayer_SeekFrame( player, 15 );
|
||||
|
|
@ -858,7 +858,7 @@ static int QueryReplay( void )
|
|||
}
|
||||
ENSURE( sawCastRay );
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( rec );
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -925,7 +925,7 @@ static int TaggedQuery( void )
|
|||
b3Recording* loaded = b3LoadRecordingFromFile( path );
|
||||
ENSURE( loaded != NULL );
|
||||
|
||||
b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( loaded ), b3Recording_GetSize( loaded ), 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( b3Recording_GetData( loaded ), b3Recording_GetSize( loaded ), 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
b3RecPlayer_SeekFrame( player, 5 );
|
||||
|
|
@ -954,7 +954,7 @@ static int TaggedQuery( void )
|
|||
}
|
||||
ENSURE( saw53 && saw54 && sawUntagged );
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( loaded );
|
||||
b3DestroyRecording( rec );
|
||||
return 0;
|
||||
|
|
@ -993,7 +993,7 @@ static int EmptyWorldRoundTrip( void )
|
|||
ENSURE( b3ValidateReplay( data, size, 1 ) );
|
||||
|
||||
// Restart restores in place, so the replay world id survives a rewind.
|
||||
b3RecPlayer* player = b3RecPlayer_Create( data, size, 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( data, size, 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
uint32_t worldKey = b3StoreWorldId( b3RecPlayer_GetWorldId( player ) );
|
||||
|
|
@ -1006,7 +1006,7 @@ static int EmptyWorldRoundTrip( void )
|
|||
ENSURE( b3RecPlayer_GetFrame( player ) == 0 );
|
||||
ENSURE( !b3RecPlayer_HasDiverged( player ) );
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( rec );
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1486,7 +1486,7 @@ static int AllOps( void )
|
|||
// Drive the incremental player. Exercises per-frame stepping, restart, getters, and the
|
||||
// draw path beyond what b3ValidateReplay covers.
|
||||
{
|
||||
b3RecPlayer* player = b3RecPlayer_Create( recData, recSize, 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( recData, recSize, 1 );
|
||||
ENSURE( player != NULL );
|
||||
|
||||
b3RecPlayerInfo info = b3RecPlayer_GetInfo( player );
|
||||
|
|
@ -1529,7 +1529,7 @@ static int AllOps( void )
|
|||
ENSURE( frames2 == 12 );
|
||||
ENSURE( b3RecPlayer_HasDiverged( player ) == false );
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
}
|
||||
|
||||
b3DestroyRecording( rec );
|
||||
|
|
@ -1674,8 +1674,8 @@ static int GeometryHashCollision( void )
|
|||
memset( p, 0x11, sizeof( p ) );
|
||||
memset( q, 0x11, sizeof( q ) );
|
||||
q[7] = 0x12;
|
||||
uint64_t hp = b3Hash64Blob( p, (int)sizeof( p ) );
|
||||
uint64_t hq = b3Hash64Blob( q, (int)sizeof( q ) );
|
||||
uint64_t hp = b3Hash64NonZero( p, (int)sizeof( p ) );
|
||||
uint64_t hq = b3Hash64NonZero( q, (int)sizeof( q ) );
|
||||
ENSURE( hp != hq );
|
||||
ENSURE( (uint32_t)( hp >> 32 ) != (uint32_t)( hq >> 32 ) );
|
||||
}
|
||||
|
|
@ -1792,7 +1792,7 @@ static int StagedStepCreationPose( void )
|
|||
|
||||
// Atomic replay fuses the create and its step, so at the creation frame the body is already
|
||||
// integrated and displaced along +x. Capture that pose and the final state hash.
|
||||
b3RecPlayer* atomic = b3RecPlayer_Create( data, sz, 1 );
|
||||
b3RecPlayer* atomic = b3CreatePlayer( data, sz, 1 );
|
||||
ENSURE( atomic != NULL );
|
||||
b3Pos atomicPose = { 0.0, 0.0, 0.0 };
|
||||
while ( !b3RecPlayer_IsAtEnd( atomic ) )
|
||||
|
|
@ -1809,11 +1809,11 @@ static int StagedStepCreationPose( void )
|
|||
ENSURE( !b3RecPlayer_HasDiverged( atomic ) );
|
||||
ENSURE( atomicPose.x - spawn.x > 0.01 ); // the impulse moved it before it was ever seen
|
||||
uint64_t atomicHash = b3HashWorldState( b3GetWorldFromId( b3RecPlayer_GetWorldId( atomic ) ) );
|
||||
b3RecPlayer_Destroy( atomic );
|
||||
b3DestroyPlayer( atomic );
|
||||
|
||||
// Staged replay: step forward until the first pre-step park. It must sit at the creation frame's
|
||||
// pre-integration state with the new body at exactly its spawn transform.
|
||||
b3RecPlayer* staged = b3RecPlayer_Create( data, sz, 1 );
|
||||
b3RecPlayer* staged = b3CreatePlayer( data, sz, 1 );
|
||||
ENSURE( staged != NULL );
|
||||
while ( !b3RecPlayer_IsAtEnd( staged ) )
|
||||
{
|
||||
|
|
@ -1847,7 +1847,7 @@ static int StagedStepCreationPose( void )
|
|||
ENSURE( !b3RecPlayer_HasDiverged( staged ) );
|
||||
uint64_t stagedHash = b3HashWorldState( b3GetWorldFromId( b3RecPlayer_GetWorldId( staged ) ) );
|
||||
ENSURE( stagedHash == atomicHash );
|
||||
b3RecPlayer_Destroy( staged );
|
||||
b3DestroyPlayer( staged );
|
||||
|
||||
b3DestroyRecording( rec );
|
||||
return 0;
|
||||
|
|
@ -1905,7 +1905,7 @@ static int ShapeNameReplay( void )
|
|||
const uint8_t* data = b3Recording_GetData( rec );
|
||||
int sz = b3Recording_GetSize( rec );
|
||||
|
||||
b3RecPlayer* player = b3RecPlayer_Create( data, sz, 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( data, sz, 1 );
|
||||
ENSURE( player != NULL );
|
||||
while ( b3RecPlayer_StepFrame( player ) )
|
||||
{
|
||||
|
|
@ -1931,7 +1931,7 @@ static int ShapeNameReplay( void )
|
|||
}
|
||||
}
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( rec );
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -2041,7 +2041,7 @@ static int GeometryMutatorReplay( void )
|
|||
ENSURE( b3ValidateReplay( data, size, 1 ) );
|
||||
ENSURE( b3ValidateReplay( data, size, 4 ) );
|
||||
|
||||
b3RecPlayer* player = b3RecPlayer_Create( data, size, 1 );
|
||||
b3RecPlayer* player = b3CreatePlayer( data, size, 1 );
|
||||
ENSURE( player != NULL );
|
||||
while ( b3RecPlayer_StepFrame( player ) )
|
||||
{
|
||||
|
|
@ -2070,7 +2070,7 @@ static int GeometryMutatorReplay( void )
|
|||
b3SurfaceMaterial replayMaterial = b3Shape_GetMeshSurfaceMaterial( replayMeshShape, 1 );
|
||||
ENSURE( replayMaterial.friction == swapFriction );
|
||||
|
||||
b3RecPlayer_Destroy( player );
|
||||
b3DestroyPlayer( player );
|
||||
b3DestroyRecording( rec );
|
||||
b3DestroyMesh( meshA );
|
||||
b3DestroyMesh( meshB );
|
||||
|
|
|
|||
Loading…
Reference in a new issue