diff options
| author | Bryan Galdrikian <[email protected]> | 2017-02-21 12:07:59 -0800 |
|---|---|---|
| committer | Bryan Galdrikian <[email protected]> | 2017-02-21 12:07:59 -0800 |
| commit | 446ce137c6823ba9eff273bdafdaf266287c7c98 (patch) | |
| tree | d20aab3e2ed08d7b3ca71c2f40db6a93ea00c459 /NvBlast/samples/resources | |
| download | blast-1.0.0-beta.tar.xz blast-1.0.0-beta.zip | |
first commitv1.0.0-beta
Diffstat (limited to 'NvBlast/samples/resources')
14 files changed, 703 insertions, 0 deletions
diff --git a/NvBlast/samples/resources/configs/assets.xml b/NvBlast/samples/resources/configs/assets.xml new file mode 100644 index 0000000..6482345 --- /dev/null +++ b/NvBlast/samples/resources/configs/assets.xml @@ -0,0 +1,88 @@ +<Model file="wall" name="Model Wall (Simple)" position="0 11.5 0" rotation="1 0 0 -90"/> +<Model file="wall" name="Model Wall (Skinned)" position="0 11.5 0" rotation="1 0 0 -90" isSkinned = "true"/> +<Model file="hugeAsset" name="Tower - 38k chunks (Skinned)" position="0 0 0" rotation="1 0 0 0" isSkinned = "true"/> +<Model file="towerSubsupport1" name="Tower subsupport-1 level (Simple)" position="0 0 0" rotation="1 0 0 0" isSkinned = "false"/> +<Model file="towerSubsupport1" name="Tower subsupport-1 level (Skinned)" position="0 0 0" rotation="1 0 0 0" isSkinned = "true"/> +<Model file="towerSubsupport2" name="Tower subsupport-2 level (Skinned)" position="0 0 0" rotation="1 0 0 0" isSkinned = "true"/> +<Model file="towerSupport" name="Tower - only support (Skinned)" position="0 0 0" rotation="1 0 0 0" isSkinned = "true"/> +<Model file="vase" name="Vase (Skinned)" position="0 1 0" rotation="1 0 0 0" isSkinned = "true"/> +<Model file="table" name="Table" position="0 0.38 0" rotation="1 0 0 0"/> +<Model file="bunny" name="Bunny (Simple)"/> +<Model file="bunny" name="Bunny (Skinned)" isSkinned = "true"/> +<Model file="bunnySubsupport" name="Bunny Subsupport (Simple)"/> +<Model file="bunnySubsupport" name="Bunny Subsupport (Skinned)" isSkinned = "true"/> +<Model file="bunnySupportOn2Level" name="Bunny Support on 2nd depth (Simple)"/> +<Model file="bunnySupportOn2Level" name="Bunny Support on 2nd depth (Skinned)" isSkinned = "true"/> +<Model id="blockwall" file="blockwall" name="Block Wall" position="0 7 0" isSkinned = "false"/> + +<Composite name="Block Walls (composite)" position="0 0 0"> + <AssetRef id="blockwall" position="0 7 0" rotation="1 0 0 0" /> + <AssetRef id="blockwall" position="0 21 0" rotation="1 0 0 0" /> + <Joint asset0="0" asset1="1" chunk0="81" chunk1="70" position0="-11 7 0" position1="-11 -7 0" /> + <Joint asset0="0" asset1="1" chunk0="46" chunk1="13" position0="0 7 0" position1="0 -7 0" /> + <Joint asset0="0" asset1="1" chunk0="39" chunk1="4" position0="11 7 0" position1="11 -7 0" /> +</Composite> + +<Composite name="Lego (composite)" position="0 0 0"> + <AssetRef id="blockwall" position="-5 7 -5" /> + <AssetRef id="blockwall" position="5 7 5" /> + <AssetRef id="column" position="0 15 0" rotation="1 0 0 -90" /> + <AssetRef id="column" position="0 27 0" /> +</Composite> + +<Composite name="NRF Joints (composite)" position="0 0 0"> + <AssetRef id="column support 1" position="15 10 0" /> + <AssetRef id="column support 1" position="-15 10 0" /> + <Joint asset0="0" asset1="-1" chunk0="3" chunk1="0" position0="0 0 0" position1="15 30 0" /> + <Joint asset0="1" asset1="-1" chunk0="5" chunk1="0" position0="0 8 0" position1="-15 38 0" /> +</Composite> + +<Box name="Wall (3 depth, 625 nodes)" extents="20 20 2" staticHeight="0.5"> + <Level slices="1 1 1" /> + <Level slices="5 5 1" /> + <Level slices="5 5 1" isSupport="true" /> +</Box> + +<Box name="Wall (2 depth, 625 nodes, no root chunk)" extents="20 20 2" staticHeight="0.5"> + <Level slices="5 5 1" /> + <Level slices="5 5 1" isSupport="true" /> +</Box> + +<Box name="Poor Man's Cloth" extents="20 20 0.2" jointAllBonds = "true" > + <Level slices="1 1 1" /> + <Level slices="20 20 1" isSupport="true" /> + <Level slices="2 2 1" /> +</Box> + +<Box name="Cube (4 depth, 1728 nodes)" extents="20 20 20"> + <Level slices="1 1 1" /> + <Level slices="2 2 2" /> + <Level slices="2 2 2" /> + <Level slices="3 3 3" isSupport="true" /> +</Box> + +<Box id="column" name="Column (3 depth, 50 nodes)" extents="2 20 2"> + <Level slices="1 1 1" /> + <Level slices="1 5 1" /> + <Level slices="1 10 1" isSupport="true"/> +</Box> + +<Box id="column support 1" name="Column (3 depth, 50 nodes)" extents="2 20 2"> + <Level slices="1 1 1" /> + <Level slices="1 5 1" isSupport="true" /> + <Level slices="1 10 1" /> +</Box> + +<Box name="Cube of Layers (3 depth, 1250 nodes)" extents="20 20 20"> + <Level slices="1 1 1" /> + <Level slices="1 1 10" /> + <Level slices="5 5 5" isSupport="true"/> +</Box> + +<Box name="Brittle Wall" extents="40 20 1" staticHeight="0.5"> + <Level slices="1 1 1" /> + <Level slices="2 2 1" /> + <Level slices="2 2 1" isSupport="true"/> + <Level slices="2 2 2" /> + <Level slices="2 2 2" /> +</Box>
\ No newline at end of file diff --git a/NvBlast/samples/resources/configs/resources.xml b/NvBlast/samples/resources/configs/resources.xml new file mode 100644 index 0000000..57b709c --- /dev/null +++ b/NvBlast/samples/resources/configs/resources.xml @@ -0,0 +1,5 @@ +<project toolsVersion="3.5"> + <platform name="win"> + <dependency name="BlastSampleResources" version="21645816"/> + </platform> +</project> diff --git a/NvBlast/samples/resources/shaders/common_buffers.hlsl b/NvBlast/samples/resources/shaders/common_buffers.hlsl new file mode 100644 index 0000000..1aa3386 --- /dev/null +++ b/NvBlast/samples/resources/shaders/common_buffers.hlsl @@ -0,0 +1,28 @@ +#ifndef COMMON_BUFFERS_HLSL +#define COMMON_BUFFERS_HLSL + +cbuffer Camera : register(b0) +{ + row_major matrix viewProjection; + row_major matrix projectionInv; + float3 viewPos; +}; + +cbuffer World : register(b1) +{ + float3 ambientColor; + float3 pointLightPos; + float3 pointLightColor; + float3 dirLightDir; + float specularPower; + float3 dirLightColor; + float specularIntensity; +}; + +cbuffer Object : register(b2) +{ + row_major matrix model; + float4 defaultColor; +}; + +#endif
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/debug_primitive.hlsl b/NvBlast/samples/resources/shaders/debug_primitive.hlsl new file mode 100644 index 0000000..a24ebfb --- /dev/null +++ b/NvBlast/samples/resources/shaders/debug_primitive.hlsl @@ -0,0 +1,31 @@ +#include "common_buffers.hlsl" + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 color : COLOR0; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float3 color : COLOR0; +}; + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), model); + float4 eyeSpacePos = mul(worldSpacePos, viewProjection); + oV.position = mul(worldSpacePos, viewProjection); + + oV.color = iV.color; + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + return float4(iV.color, 1); +}
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/lighting.hlsl b/NvBlast/samples/resources/shaders/lighting.hlsl new file mode 100644 index 0000000..2dacc14 --- /dev/null +++ b/NvBlast/samples/resources/shaders/lighting.hlsl @@ -0,0 +1,51 @@ +#include "common_buffers.hlsl" + +static const float att_c = 1.0f; +static const float att_l = 0.014f; +static const float att_q = 0.0007f; + + +float CalcAttenuation(float distance) +{ + return 1 / (att_c + att_l * distance + att_q * distance * distance); +}; + + +float3 CalcLight(float3 textureColor, float3 lightDir, float3 viewDir, float3 normal, float3 lightColor, float specPower, float specIntensity, float attenuation) +{ + normal = normalize(normal); + + // diffuse + float3 dirToLight = normalize(-lightDir); + float diffuseFactor = max(dot(normal, dirToLight), 0.0); + float3 diffuse = lightColor * textureColor * diffuseFactor * attenuation; + + // specular (Blinn-Phong) + float3 halfwayDir = normalize(dirToLight + viewDir); + float specFactor = pow(max(dot(viewDir, halfwayDir), 0.0), specPower); + float3 spec = lightColor * specFactor * attenuation * specIntensity; + + return diffuse + spec; +}; + +float3 CalcPixelLight(float3 diffuseColor, float3 worldPos, float3 normal) +{ + float3 viewDir = normalize(viewPos - worldPos); + + // ambient + float3 ambient = ambientColor * diffuseColor; + + // dir light + float3 dirLight = CalcLight(diffuseColor, dirLightDir, viewDir, normal, dirLightColor, specularPower, specularIntensity, 1); + + // point light + float3 pointLightDir = worldPos - pointLightPos; + float distance = length(pointLightDir); + float attenuation = CalcAttenuation(distance); + float3 pointLight = CalcLight(diffuseColor, pointLightDir, viewDir, normal, pointLightColor, specularPower, specularIntensity, attenuation); + + // hacky hack: ambient attenuates within point light distance + ambient *= attenuation; + + return ambient + dirLight + pointLight; +};
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/model_simple.hlsl b/NvBlast/samples/resources/shaders/model_simple.hlsl new file mode 100644 index 0000000..7d55a72 --- /dev/null +++ b/NvBlast/samples/resources/shaders/model_simple.hlsl @@ -0,0 +1,42 @@ +#include "common_buffers.hlsl" +#include "lighting.hlsl" + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 normal : NORMAL0; + float health : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float4 worldPos : POSITION0; + float3 normal : NORMAL0; + float health : TEXCOORD1; +}; + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), model); + oV.position = mul(worldSpacePos, viewProjection); + + oV.worldPos = worldSpacePos; + + // normals + float3 worldNormal = mul(iV.normal, (float3x3)model); + oV.normal = worldNormal; + + oV.health = iV.health; + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + float3 lightColor = CalcPixelLight(defaultColor.xyz, iV.worldPos.xyz, iV.normal); + lightColor.r = 1.0f - iV.health; // hack for health + return float4(lightColor, 1); +}
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/model_simple_textured.hlsl b/NvBlast/samples/resources/shaders/model_simple_textured.hlsl new file mode 100644 index 0000000..5167837 --- /dev/null +++ b/NvBlast/samples/resources/shaders/model_simple_textured.hlsl @@ -0,0 +1,76 @@ +#include "common_buffers.hlsl" +#include "lighting.hlsl" + +SamplerState defaultSampler : register(s0); +Texture2D diffuseTexture : register(t0); + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 normal : NORMAL0; + float2 uv : TEXCOORD0; + float health : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float4 worldPos : POSITION0; + float2 uv : TEXCOORD0; + float3 normal : NORMAL0; + float health : TEXCOORD1; +}; + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), model); + oV.position = mul(worldSpacePos, viewProjection); + + oV.worldPos = worldSpacePos; + + // normals + float3 worldNormal = mul(float4(iV.normal, 0.0f), model); + oV.normal = worldNormal; + + oV.uv = iV.uv; + oV.health = iV.health; + + return oV; +} + +float noise2(float2 co) +{ + return frac(sin(dot(co.xy, float2(12.9898,78.233))) * 43758.5453); +} + +float voronoi( float2 x ) +{ + int2 p = floor( x ); + float2 f = frac( x ); + + float res = 8.0; + for( int j=-1; j<=1; j++ ) + for( int i=-1; i<=1; i++ ) + { + int2 b = int2( i, j ); + float2 r = float2( b ) - f + noise2( p + b ); + float d = dot( r, r ); + + res = min( res, d ); + } + return sqrt( res ); +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + float4 textureColor = diffuseTexture.Sample(defaultSampler, iV.uv); + + // health cracks hack + float crack = 1.0f - voronoi(iV.uv * 50.0f); + crack = smoothstep(0.0f, 0.5f, crack); + textureColor = textureColor * lerp(1.0f, crack, (1.0f - iV.health) * 0.7f); + + return float4(CalcPixelLight(textureColor, iV.worldPos, iV.normal), 1); +}
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/model_skinned.hlsl b/NvBlast/samples/resources/shaders/model_skinned.hlsl new file mode 100644 index 0000000..1e26c95 --- /dev/null +++ b/NvBlast/samples/resources/shaders/model_skinned.hlsl @@ -0,0 +1,54 @@ +#include "common_buffers.hlsl" +#include "lighting.hlsl" + +SamplerState defaultSampler : register(s0); +Texture2D diffuseTexture : register(t0); +Texture2D bonesTexture : register(t1); + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 normal : NORMAL0; + float2 uv : TEXCOORD0; + uint boneIndex : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float4 worldPos : POSITION0; + float2 uv : TEXCOORD0; + float3 normal : NORMAL0; +}; + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4x4 boneMatrix; + boneMatrix[0] = bonesTexture.Load(int3(0, iV.boneIndex, 0)); + boneMatrix[1] = bonesTexture.Load(int3(1, iV.boneIndex, 0)); + boneMatrix[2] = bonesTexture.Load(int3(2, iV.boneIndex, 0)); + boneMatrix[3] = bonesTexture.Load(int3(3, iV.boneIndex, 0)); + + float3 skinnedPos = mul(float4(iV.position, 1.0f), boneMatrix); + float4 worldSpacePos = mul(float4(skinnedPos, 1.0f), model); + oV.position = mul(worldSpacePos, viewProjection); + + oV.worldPos = worldSpacePos; + + // normals + float3 localNormal = mul(float4(iV.normal, 0.0f), boneMatrix); + float3 worldNormal = mul(float4(localNormal, 0.0f), model); + oV.normal = worldNormal; + + oV.uv = iV.uv; + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + float3 lightColor = CalcPixelLight(defaultColor.xyz, iV.worldPos.xyz, iV.normal); + return float4(lightColor, 1); +}
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/model_skinned_textured.hlsl b/NvBlast/samples/resources/shaders/model_skinned_textured.hlsl new file mode 100644 index 0000000..2b2bb0e --- /dev/null +++ b/NvBlast/samples/resources/shaders/model_skinned_textured.hlsl @@ -0,0 +1,54 @@ +#include "common_buffers.hlsl" +#include "lighting.hlsl" + +SamplerState defaultSampler : register(s0); +Texture2D diffuseTexture : register(t0); +Texture2D bonesTexture : register(t1); + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 normal : NORMAL0; + float2 uv : TEXCOORD0; + uint boneIndex : TEXCOORD1; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float4 worldPos : POSITION0; + float2 uv : TEXCOORD0; + float3 normal : NORMAL0; +}; + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4x4 boneMatrix; + boneMatrix[0] = bonesTexture.Load(int3(0, iV.boneIndex, 0)); + boneMatrix[1] = bonesTexture.Load(int3(1, iV.boneIndex, 0)); + boneMatrix[2] = bonesTexture.Load(int3(2, iV.boneIndex, 0)); + boneMatrix[3] = bonesTexture.Load(int3(3, iV.boneIndex, 0)); + + float3 skinnedPos = mul(float4(iV.position, 1.0f), boneMatrix); + float4 worldSpacePos = mul(float4(skinnedPos, 1.0f), model); + oV.position = mul(worldSpacePos, viewProjection); + + oV.worldPos = worldSpacePos; + + // normals + float3 localNormal = mul(float4(iV.normal, 0.0f), boneMatrix); + float3 worldNormal = mul(float4(localNormal, 0.0f), model); + oV.normal = worldNormal; + + oV.uv = iV.uv; + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + float4 textureColor = diffuseTexture.Sample(defaultSampler, iV.uv); + return float4(CalcPixelLight(textureColor, iV.worldPos, iV.normal), 1); +}
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/physx_primitive.hlsl b/NvBlast/samples/resources/shaders/physx_primitive.hlsl new file mode 100644 index 0000000..03fd137 --- /dev/null +++ b/NvBlast/samples/resources/shaders/physx_primitive.hlsl @@ -0,0 +1,37 @@ +#include "common_buffers.hlsl" +#include "lighting.hlsl" + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 normal : NORMAL0; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float4 worldPos : POSITION0; + float3 normal : NORMAL0; +}; + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), model); + oV.position = mul(worldSpacePos, viewProjection); + + oV.worldPos = worldSpacePos; + + // normals + float3 worldNormal = mul(iV.normal, (float3x3)model); + oV.normal = worldNormal; + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + float3 lightColor = CalcPixelLight(defaultColor.xyz, iV.worldPos.xyz, iV.normal); + return float4(lightColor, 1); +}
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/physx_primitive_plane.hlsl b/NvBlast/samples/resources/shaders/physx_primitive_plane.hlsl new file mode 100644 index 0000000..3b2ec5d --- /dev/null +++ b/NvBlast/samples/resources/shaders/physx_primitive_plane.hlsl @@ -0,0 +1,64 @@ +#include "common_buffers.hlsl" +#include "lighting.hlsl" + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 normal : NORMAL0; + float2 uv : TEXCOORD0; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float4 worldPos : POSITION0; + float2 uv : TEXCOORD0; + float3 normal : NORMAL0; +}; + +float filterwidth(float2 v) +{ + float2 fw = max(abs(ddx(v)), abs(ddy(v))); + return max(fw.x, fw.y); +} + +float2 bump(float2 x) +{ + return (floor(x/2) + 2.f * max((x/2) - floor(x/2) - .5f, 0.f)); +} + +float checker(float2 uv) +{ + float width = filterwidth(uv); + float2 p0 = uv - 0.5 * width; + float2 p1 = uv + 0.5 * width; + + float2 i = (bump(p1) - bump(p0)) / width; + return i.x * i.y + (1 - i.x) * (1 - i.y); +} + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), model); + oV.position = mul(worldSpacePos, viewProjection); + + oV.uv = iV.uv; + + oV.worldPos = worldSpacePos; + + // normals + float3 worldNormal = mul(iV.normal, (float3x3)model); + oV.normal = worldNormal; + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + float4 color = defaultColor; + color *= 1.0 - 0.25 * checker(iV.uv); + float3 lightColor = CalcPixelLight(color.xyz, iV.worldPos.xyz, iV.normal); + return float4(lightColor, 1); +}
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/physx_primitive_transparent.hlsl b/NvBlast/samples/resources/shaders/physx_primitive_transparent.hlsl new file mode 100644 index 0000000..d52392e --- /dev/null +++ b/NvBlast/samples/resources/shaders/physx_primitive_transparent.hlsl @@ -0,0 +1,40 @@ +#include "common_buffers.hlsl" +#include "lighting.hlsl" + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 normal : NORMAL0; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float4 worldPos : POSITION0; + float3 normal : NORMAL0; +}; + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), model); + oV.position = mul(worldSpacePos, viewProjection); + + oV.worldPos = worldSpacePos; + + // normals + float3 worldNormal = mul(iV.normal, (float3x3)model); + oV.normal = worldNormal; + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + float4 color = defaultColor; + float3 viewDir = normalize(viewPos - iV.worldPos.xyz); + float factor = max(0.0f, dot(normalize(iV.normal), viewDir)); + color.a *= factor; + return color; +}
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/pointsprite.hlsl b/NvBlast/samples/resources/shaders/pointsprite.hlsl new file mode 100644 index 0000000..2bff194 --- /dev/null +++ b/NvBlast/samples/resources/shaders/pointsprite.hlsl @@ -0,0 +1,106 @@ +#include "common_buffers.hlsl" +#include "lighting.hlsl" + +SamplerState linearSampler : register(s0); +SamplerState pointSampler : register(s1); +Texture2D diffuseTexture : register(t0); +Texture2D<float> depthTexture : register(t1); + +static const float POINT_SIZE = 1.00f; +static const float FADE_DISTANCE = 1.0f; + +struct VS_INPUT +{ + float3 position : POSITION0; + float4 color : COLOR0; + float2 scale : TANGENT; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float4 color : COLOR0; + float2 uv : TEXCOORD0; + float2 screenPos : TEXCOORD1; + float2 depth : TEXCOORD2; + float2 pointSize : PSIZE; +}; + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), model); + oV.position = mul(worldSpacePos, viewProjection); + + oV.color = iV.color; + oV.uv = float2(0, 0); + + // uncomment to use scale + //oV.pointSize = iV.scale * POINT_SIZE; + oV.pointSize = float2(1, 1) * POINT_SIZE; + + return oV; +} + +static const float4 SPRITE_VERTEX_POSITIONS[4] = +{ + float4( 0.5, -0.5, 0, 0), + float4( 0.5, 0.5, 0, 0), + float4( -0.5, -0.5, 0, 0), + float4( -0.5, 0.5, 0, 0), +}; + +static const float2 SPRITE_VERTEX_TEXCOORDS[4] = +{ + float2(1, 0), + float2(1, 1), + float2(0, 0), + float2(0, 1), +}; + +[maxvertexcount(4)] +void GS( point VS_OUTPUT sprite[1], inout TriangleStream<VS_OUTPUT> triStream ) +{ + VS_OUTPUT v; + + v.color = sprite[0].color; + v.pointSize = sprite[0].pointSize; + + float4 aspectFactor = float4((projection[0][0] / projection[1][1]) * v.pointSize.x, 1.0 * v.pointSize.y, 0, 0); + + [unroll] for(int i = 0; i < 4; ++i) + { + v.position = sprite[0].position + SPRITE_VERTEX_POSITIONS[i] * aspectFactor; + v.screenPos = v.position.xy / v.position.w; + v.depth = v.position.zw; + v.uv = SPRITE_VERTEX_TEXCOORDS[i]; + triStream.Append(v); + } + + triStream.RestartStrip(); +} + +float4 PS(VS_OUTPUT input) : SV_Target0 +{ + // soft particles fade: + float2 screenPos = 0.5*( (input.screenPos) + float2(1,1)); + screenPos.y = 1 - screenPos.y; + + float particleDepth = input.depth.x / input.depth.y; + + float depthSample = depthTexture.Sample(pointSampler, screenPos); + + float4 depthViewSample = mul(float4(input.screenPos, depthSample, 1), projectionInv ); + float4 depthViewParticle = mul(float4(input.screenPos, particleDepth, 1), projectionInv); + + float depthDiff = depthViewSample.z / depthViewSample.w - depthViewParticle.z / depthViewParticle.w; + if( depthDiff < 0 ) + discard; + + float depthFade = saturate( depthDiff / FADE_DISTANCE ); + + float4 textureColor = diffuseTexture.Sample(linearSampler, input.uv) * input.color; + textureColor.a *= depthFade; + return textureColor; +}
\ No newline at end of file diff --git a/NvBlast/samples/resources/shaders/unlit_transparent.hlsl b/NvBlast/samples/resources/shaders/unlit_transparent.hlsl new file mode 100644 index 0000000..0c2158a --- /dev/null +++ b/NvBlast/samples/resources/shaders/unlit_transparent.hlsl @@ -0,0 +1,27 @@ +#include "common_buffers.hlsl" + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 normal : NORMAL0; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; +}; + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), model); + oV.position = mul(worldSpacePos, viewProjection); + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + return defaultColor; +}
\ No newline at end of file |