diff options
| author | Bryan Galdrikian <[email protected]> | 2017-10-24 15:25:02 -0700 |
|---|---|---|
| committer | Bryan Galdrikian <[email protected]> | 2017-10-24 15:25:02 -0700 |
| commit | b0c11962f6012430da3bcaa2727288046b33d648 (patch) | |
| tree | cf13338fa4fd7072badf64f751f94abeeb437003 /sdk/extensions/shaders/include/NvBlastExtDamageShaders.h | |
| parent | linux build fix - all configs (diff) | |
| download | blast-b0c11962f6012430da3bcaa2727288046b33d648.tar.xz blast-b0c11962f6012430da3bcaa2727288046b33d648.zip | |
Changes for 1.1.1
See README.md
Diffstat (limited to 'sdk/extensions/shaders/include/NvBlastExtDamageShaders.h')
| -rw-r--r-- | sdk/extensions/shaders/include/NvBlastExtDamageShaders.h | 158 |
1 files changed, 127 insertions, 31 deletions
diff --git a/sdk/extensions/shaders/include/NvBlastExtDamageShaders.h b/sdk/extensions/shaders/include/NvBlastExtDamageShaders.h index 8daf9cf..b7962cd 100644 --- a/sdk/extensions/shaders/include/NvBlastExtDamageShaders.h +++ b/sdk/extensions/shaders/include/NvBlastExtDamageShaders.h @@ -30,6 +30,7 @@ #define NVBLASTEXTDAMAGESHADERS_H #include "NvBlastTypes.h" +#include "NvBlastDebugRender.h" /** @@ -38,6 +39,49 @@ A few example damage shader implementations. /////////////////////////////////////////////////////////////////////////////// +// Damage Accelerator +/////////////////////////////////////////////////////////////////////////////// + +class NvBlastExtDamageAccelerator +{ +public: + virtual void release() = 0; + + virtual Nv::Blast::DebugBuffer fillDebugRender(int depth = -1, bool segments = false) = 0; +}; + +NVBLAST_API NvBlastExtDamageAccelerator* NvBlastExtDamageAcceleratorCreate(const NvBlastAsset* asset, int type); + + +/////////////////////////////////////////////////////////////////////////////// +// Damage Program +/////////////////////////////////////////////////////////////////////////////// + +/** +Damage program params. + +Custom user params to be passed in shader functions. This structure hints recommended parameters layout, but it +doesn't required to be this way. + +The idea of this 'hint' is that damage parameters are basically 2 entities: material + damage description. +1. Material is something that describes an actor properties (e.g. mass, stiffness, fragility) which are not expected to be changed often. +2. Damage description is something that describes particular damage event (e.g. position, radius and force of explosion). + +Also this damage program hints that there could be more than one damage event happening and processed per one shader call (for efficiency reasons). +So different damage descriptions can be stacked and passed in one shader call (while material is kept the same obviously). +*/ +struct NvBlastExtProgramParams +{ + NvBlastExtProgramParams(const void* desc, const void* material_ = nullptr, NvBlastExtDamageAccelerator* accelerator_ = nullptr) + : damageDesc(desc), material(material_), accelerator(accelerator_) {} + + const void* damageDesc; //!< array of damage descriptions + const void* material; //!< pointer to material + NvBlastExtDamageAccelerator* accelerator; +}; + + +/////////////////////////////////////////////////////////////////////////////// // Common Material /////////////////////////////////////////////////////////////////////////////// @@ -95,38 +139,20 @@ NOTE: The signature of shader functions are equal to NvBlastGraphShaderFunction They are not expected to be called directly. @see NvBlastGraphShaderFunction, NvBlastSubgraphShaderFunction */ -NVBLAST_API void NvBlastExtFalloffGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const NvBlastProgramParams* params); -NVBLAST_API void NvBlastExtFalloffSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const NvBlastProgramParams* params); -NVBLAST_API void NvBlastExtCutterGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const NvBlastProgramParams* params); -NVBLAST_API void NvBlastExtCutterSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const NvBlastProgramParams* params); - - -/** -Helper Radial Falloff Damage function. - -Basically it calls NvBlastActorGenerateFracture and then NvBlastActorApplyFracture with Radial Falloff shader. - -\param[in,out] actor The NvBlastActor to apply fracture to. -\param[in,out] buffers Target buffers to hold applied command events. -\param[in] damageDescBuffer Damage descriptors array. -\param[in] damageDescCount Size of damage descriptors array. -\param[in] material Material to use. -\param[in] logFn User-supplied message function (see NvBlastLog definition). May be NULL. -\param[in,out] timers If non-NULL this struct will be filled out with profiling information for the step, in profile build configurations. - -\return true iff any fracture was applied. -*/ -NVBLAST_API bool NvBlastExtDamageActorRadialFalloff(NvBlastActor* actor, NvBlastFractureBuffers* buffers, const NvBlastExtRadialDamageDesc* damageDescBuffer, uint32_t damageDescCount, const NvBlastExtMaterial* material, NvBlastLog logFn, NvBlastTimers* timers); +NVBLAST_API void NvBlastExtFalloffGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const void* params); +NVBLAST_API void NvBlastExtFalloffSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const void* params); +NVBLAST_API void NvBlastExtCutterGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const void* params); +NVBLAST_API void NvBlastExtCutterSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const void* params); /////////////////////////////////////////////////////////////////////////////// -// Segment Radial Damage +// Capsule Radial Damage /////////////////////////////////////////////////////////////////////////////// /** -Segment Radial Damage Desc +Capsule Radial Damage Desc */ -struct NvBlastExtSegmentRadialDamageDesc +struct NvBlastExtCapsuleRadialDamageDesc { float damage; //!< normalized damage amount, range: [0, 1] (maximum health value to be reduced) float position0[3]; //!< damage segment point A position @@ -136,17 +162,17 @@ struct NvBlastExtSegmentRadialDamageDesc }; /** -Segment Radial Falloff damage for both graph and subgraph shaders. +Capsule Radial Falloff damage for both graph and subgraph shaders. -For every bond/chunk damage is calculated from the distance to line segment AB described in NvBlastExtSegmentRadialDamageDesc. +For every bond/chunk damage is calculated from the distance to line segment AB described in NvBlastExtCapsuleRadialDamageDesc. If distance is smaller then minRadius, full compressive amount of damage is applied. From minRadius to maxRaidus it linearly falls off to zero. NOTE: The signature of shader functions are equal to NvBlastGraphShaderFunction and NvBlastSubgraphShaderFunction respectively. They are not expected to be called directly. @see NvBlastGraphShaderFunction, NvBlastSubgraphShaderFunction */ -NVBLAST_API void NvBlastExtSegmentFalloffGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const NvBlastProgramParams* params); -NVBLAST_API void NvBlastExtSegmentFalloffSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const NvBlastProgramParams* params); +NVBLAST_API void NvBlastExtCapsuleFalloffGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const void* params); +NVBLAST_API void NvBlastExtCapsuleFalloffSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const void* params); /////////////////////////////////////////////////////////////////////////////// @@ -174,8 +200,78 @@ NOTE: The signature of shader functions are equal to NvBlastGraphShaderFunction They are not expected to be called directly. @see NvBlastGraphShaderFunction, NvBlastSubgraphShaderFunction */ -NVBLAST_API void NvBlastExtShearGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const NvBlastProgramParams* params); -NVBLAST_API void NvBlastExtShearSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const NvBlastProgramParams* params); +NVBLAST_API void NvBlastExtShearGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const void* params); +NVBLAST_API void NvBlastExtShearSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const void* params); + + +/////////////////////////////////////////////////////////////////////////////// +// Triangle Intersection Damage +/////////////////////////////////////////////////////////////////////////////// + +/** +Triangle Intersection Damage Desc +*/ +struct NvBlastExtTriangleIntersectionDamageDesc +{ + float damage; //!< normalized damage amount, range: [0, 1] (maximum health value to be reduced) + NvcVec3 position0; //!< triangle point A position + NvcVec3 position1; //!< triangle point B position + NvcVec3 position2; //!< triangle point C position +}; + +/** +Triangle Intersection damage for both graph and subgraph shaders. + +Every bond is considered to be a segment connecting two chunk centroids. For every bond (segment) intersection with passed triangle is checked. If intersects +full damage is applied on bond. +For subgraph shader segments are formed as connections between it's subchunks centroids. Intersection is check in the same fashion. + +The idea is that if you want to cut an object say with the laser sword, you can form a triangle by taking the position of a sword on this timeframe and on previous one. +So that nothing will be missed in terms of space and time. By sweeping sword through whole object it will be cut in halves inevitably, since all bonds segments form connected graph. + +NOTE: The signature of shader functions are equal to NvBlastGraphShaderFunction and NvBlastSubgraphShaderFunction respectively. +They are not expected to be called directly. +@see NvBlastGraphShaderFunction, NvBlastSubgraphShaderFunction +*/ +NVBLAST_API void NvBlastExtTriangleIntersectionGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const void* params); +NVBLAST_API void NvBlastExtTriangleIntersectionSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const void* params); + + +/////////////////////////////////////////////////////////////////////////////// +// Impact Spread +/////////////////////////////////////////////////////////////////////////////// + +/** +Impact Spread Damage Desc +*/ +struct NvBlastExtImpactSpreadDamageDesc +{ + float damage; //!< normalized damage amount, range: [0, 1] (maximum health value to be reduced) + float position[3]; //!< origin of damage action + + float minRadius; //!< inner radius of damage action + float maxRadius; //!< outer radius of damage action +}; + +/** +Impact Spread Damage Shaders. + +It assumes that position is somewhere on the chunk and looks for nearest chunk to this position and damages it. +Then it does breadth-first support graph traversal. For radial falloff metric distance is measured along the edges of the graph. +That allows to avoid damaging parts which are near in space but disjointed topologically. For example if you hit one column of an arc +it would take much bigger radius for damage to travel to the other column than in the simple radial damage. + +Shader is designed to be used with impact damage, where it is know in advance that actual hit happened. + +This shader requires NvBlastExtDamageAccelerator passed in, it request scratch memory from it, therefore it is also designed to work +only in single threaded mode. It can easily be changed by passing scratch memory as a part of NvBlastExtProgramParams if required. + +NOTE: The signature of shader functions are equal to NvBlastGraphShaderFunction and NvBlastSubgraphShaderFunction respectively. +They are not expected to be called directly. +@see NvBlastGraphShaderFunction, NvBlastSubgraphShaderFunction +*/ +NVBLAST_API void NvBlastExtImpactSpreadGraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastGraphShaderActor* actor, const void* params); +NVBLAST_API void NvBlastExtImpactSpreadSubgraphShader(NvBlastFractureBuffers* commandBuffers, const NvBlastSubgraphShaderActor* actor, const void* params); #endif // NVBLASTEXTDAMAGESHADERS_H |