diff options
Diffstat (limited to 'samples/resources')
| -rwxr-xr-x[-rw-r--r--] | samples/resources/configs/assets.xml | 216 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/configs/resources.xml | 10 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/common_buffers.hlsl | 54 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/debug_primitive.hlsl | 60 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/lighting.hlsl | 100 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/model_simple.hlsl | 82 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/model_simple_textured.hlsl | 150 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/model_skinned.hlsl | 106 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/model_skinned_textured.hlsl | 106 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/physx_primitive.hlsl | 72 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/physx_primitive_plane.hlsl | 126 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/physx_primitive_transparent.hlsl | 78 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/pointsprite.hlsl | 210 | ||||
| -rwxr-xr-x[-rw-r--r--] | samples/resources/shaders/unlit_transparent.hlsl | 52 |
14 files changed, 711 insertions, 711 deletions
diff --git a/samples/resources/configs/assets.xml b/samples/resources/configs/assets.xml index d2e2291..d8f8187 100644..100755 --- a/samples/resources/configs/assets.xml +++ b/samples/resources/configs/assets.xml @@ -1,109 +1,109 @@ -<!--<Model file="blast" name="Blast" position="0 5 0"/>--> -<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> bondFlagsMask: - X_BONDS = 1 << 0, - Y_BONDS = 1 << 1, - Z_BONDS = 1 << 2, - X_PLUS_WORLD_BONDS = 1 << 3, - X_MINUS_WORLD_BONDS = 1 << 4, - Y_PLUS_WORLD_BONDS = 1 << 5, - Y_MINUS_WORLD_BONDS = 1 << 6, - Z_PLUS_WORLD_BONDS = 1 << 7, - Z_MINUS_WORLD_BONDS = 1 << 8, - default: 000000111 (X_BONDS | Y_BONDS | Z_BONDS) ---> - -<Box name="Wall (3 depth, 625 nodes)" extents="20 20 2" bondFlagsMask="1000111"> - <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" bondFlagsMask="1000111"> - <Level slices="5 5 1" /> - <Level slices="5 5 1" isSupport="true" /> -</Box> - -<Box name="Static Frame" extents="20 20 2" bondFlagsMask="1111111"> - <Level slices="1 1 1" /> - <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, support depth = 1)" 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" bondFlagsMask="1000111"> - <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" /> +<!--<Model file="blast" name="Blast" position="0 5 0"/>-->
+<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> bondFlagsMask:
+ X_BONDS = 1 << 0,
+ Y_BONDS = 1 << 1,
+ Z_BONDS = 1 << 2,
+ X_PLUS_WORLD_BONDS = 1 << 3,
+ X_MINUS_WORLD_BONDS = 1 << 4,
+ Y_PLUS_WORLD_BONDS = 1 << 5,
+ Y_MINUS_WORLD_BONDS = 1 << 6,
+ Z_PLUS_WORLD_BONDS = 1 << 7,
+ Z_MINUS_WORLD_BONDS = 1 << 8,
+ default: 000000111 (X_BONDS | Y_BONDS | Z_BONDS)
+-->
+
+<Box name="Wall (3 depth, 625 nodes)" extents="20 20 2" bondFlagsMask="1000111">
+ <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" bondFlagsMask="1000111">
+ <Level slices="5 5 1" />
+ <Level slices="5 5 1" isSupport="true" />
+</Box>
+
+<Box name="Static Frame" extents="20 20 2" bondFlagsMask="1111111">
+ <Level slices="1 1 1" />
+ <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, support depth = 1)" 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" bondFlagsMask="1000111">
+ <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/samples/resources/configs/resources.xml b/samples/resources/configs/resources.xml index 2d9eaad..50482db 100644..100755 --- a/samples/resources/configs/resources.xml +++ b/samples/resources/configs/resources.xml @@ -1,5 +1,5 @@ -<project toolsVersion="3.5"> - <platform name="win"> - <dependency name="BlastSampleResources" version="22532953"/> - </platform> -</project> +<project toolsVersion="5.2">
+ <dependency name="BlastSampleResources" linkPath="../BlastSampleResources">
+ <package name="BlastSampleResources" version="22532953"/>
+ </dependency>
+</project>
diff --git a/samples/resources/shaders/common_buffers.hlsl b/samples/resources/shaders/common_buffers.hlsl index 1aa3386..4332370 100644..100755 --- a/samples/resources/shaders/common_buffers.hlsl +++ b/samples/resources/shaders/common_buffers.hlsl @@ -1,28 +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; -}; - +#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/samples/resources/shaders/debug_primitive.hlsl b/samples/resources/shaders/debug_primitive.hlsl index a24ebfb..be0d455 100644..100755 --- a/samples/resources/shaders/debug_primitive.hlsl +++ b/samples/resources/shaders/debug_primitive.hlsl @@ -1,31 +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); +#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/samples/resources/shaders/lighting.hlsl b/samples/resources/shaders/lighting.hlsl index 2dacc14..aaefdc3 100644..100755 --- a/samples/resources/shaders/lighting.hlsl +++ b/samples/resources/shaders/lighting.hlsl @@ -1,51 +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; +#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/samples/resources/shaders/model_simple.hlsl b/samples/resources/shaders/model_simple.hlsl index 7d55a72..9796a39 100644..100755 --- a/samples/resources/shaders/model_simple.hlsl +++ b/samples/resources/shaders/model_simple.hlsl @@ -1,42 +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); +#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/samples/resources/shaders/model_simple_textured.hlsl b/samples/resources/shaders/model_simple_textured.hlsl index 5167837..b9ecdcb 100644..100755 --- a/samples/resources/shaders/model_simple_textured.hlsl +++ b/samples/resources/shaders/model_simple_textured.hlsl @@ -1,76 +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); +#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/samples/resources/shaders/model_skinned.hlsl b/samples/resources/shaders/model_skinned.hlsl index 1e26c95..2ae7695 100644..100755 --- a/samples/resources/shaders/model_skinned.hlsl +++ b/samples/resources/shaders/model_skinned.hlsl @@ -1,54 +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); +#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/samples/resources/shaders/model_skinned_textured.hlsl b/samples/resources/shaders/model_skinned_textured.hlsl index 2b2bb0e..3c49fcd 100644..100755 --- a/samples/resources/shaders/model_skinned_textured.hlsl +++ b/samples/resources/shaders/model_skinned_textured.hlsl @@ -1,54 +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); +#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/samples/resources/shaders/physx_primitive.hlsl b/samples/resources/shaders/physx_primitive.hlsl index 03fd137..d0c2d47 100644..100755 --- a/samples/resources/shaders/physx_primitive.hlsl +++ b/samples/resources/shaders/physx_primitive.hlsl @@ -1,37 +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); +#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/samples/resources/shaders/physx_primitive_plane.hlsl b/samples/resources/shaders/physx_primitive_plane.hlsl index 3b2ec5d..a567867 100644..100755 --- a/samples/resources/shaders/physx_primitive_plane.hlsl +++ b/samples/resources/shaders/physx_primitive_plane.hlsl @@ -1,64 +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); +#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/samples/resources/shaders/physx_primitive_transparent.hlsl b/samples/resources/shaders/physx_primitive_transparent.hlsl index d52392e..a8ba074 100644..100755 --- a/samples/resources/shaders/physx_primitive_transparent.hlsl +++ b/samples/resources/shaders/physx_primitive_transparent.hlsl @@ -1,40 +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; +#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/samples/resources/shaders/pointsprite.hlsl b/samples/resources/shaders/pointsprite.hlsl index 2bff194..f80c4ba 100644..100755 --- a/samples/resources/shaders/pointsprite.hlsl +++ b/samples/resources/shaders/pointsprite.hlsl @@ -1,106 +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; +#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/samples/resources/shaders/unlit_transparent.hlsl b/samples/resources/shaders/unlit_transparent.hlsl index 0c2158a..e2bb6c8 100644..100755 --- a/samples/resources/shaders/unlit_transparent.hlsl +++ b/samples/resources/shaders/unlit_transparent.hlsl @@ -1,27 +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; +#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 |