diff options
| author | git perforce import user <a@b> | 2016-10-25 12:29:14 -0600 |
|---|---|---|
| committer | Sheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees> | 2016-10-25 18:56:37 -0500 |
| commit | 3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch) | |
| tree | fa6485c169e50d7415a651bf838f5bcd0fd3bfbd /APEX_1.4/samples_v2/SampleBase/shaders | |
| download | physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip | |
Initial commit:
PhysX 3.4.0 Update @ 21294896
APEX 1.4.0 Update @ 21275617
[CL 21300167]
Diffstat (limited to 'APEX_1.4/samples_v2/SampleBase/shaders')
9 files changed, 483 insertions, 0 deletions
diff --git a/APEX_1.4/samples_v2/SampleBase/shaders/clothing_asset_skinned.hlsl b/APEX_1.4/samples_v2/SampleBase/shaders/clothing_asset_skinned.hlsl new file mode 100644 index 00000000..0c5afca1 --- /dev/null +++ b/APEX_1.4/samples_v2/SampleBase/shaders/clothing_asset_skinned.hlsl @@ -0,0 +1,73 @@ +#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; + int3 boneIndices : TEXCOORD5; + float3 boneWeights : TEXCOORD6; +}; + +struct VS_OUTPUT +{ + float4 position : SV_POSITION; + float4 worldPos : POSITION0; + float2 uv : TEXCOORD0; + float3 normal : NORMAL0; +}; + +float4x4 getBoneMatrix(int boneIndex) +{ + float4x4 boneMatrix; + boneMatrix[0] = bonesTexture.Load(int3(0, boneIndex, 0)); + boneMatrix[1] = bonesTexture.Load(int3(1, boneIndex, 0)); + boneMatrix[2] = bonesTexture.Load(int3(2, boneIndex, 0)); + boneMatrix[3] = bonesTexture.Load(int3(3, boneIndex, 0)); + return boneMatrix; +} + +float4x4 accumulate_skin(float4 boneIndices0, float4 boneWeights0) +{ + float4x4 result = boneWeights0.x * getBoneMatrix(boneIndices0.x); + result = result + boneWeights0.y * getBoneMatrix(boneIndices0.y); + result = result + boneWeights0.z * getBoneMatrix(boneIndices0.z); + result = result + boneWeights0.w * getBoneMatrix(boneIndices0.w); + return result; +} + + +VS_OUTPUT VS(VS_INPUT iV) +{ + VS_OUTPUT oV; + + //float4x4 boneMatrix = accumulate_skin(iV.boneIndices, iV.boneWeights); + float4x4 boneMatrix = accumulate_skin(float4(iV.boneIndices, 0), float4(iV.boneWeights, 0)); + + float3 skinnedPos = mul(float4(iV.position, 1.0f), boneMatrix); + float4 worldSpacePos = mul(float4(skinnedPos, 1.0f), model); + float4 eyeSpacePos = mul(worldSpacePos, view); + oV.position = mul(eyeSpacePos, projection); + + oV.worldPos = worldSpacePos; + + // normals + float3 localNormal = mul(float4(skinnedPos, 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 CalcPixelLight(textureColor, iV.worldPos, iV.normal); +}
\ No newline at end of file diff --git a/APEX_1.4/samples_v2/SampleBase/shaders/clothing_asset_static.hlsl b/APEX_1.4/samples_v2/SampleBase/shaders/clothing_asset_static.hlsl new file mode 100644 index 00000000..5a592d67 --- /dev/null +++ b/APEX_1.4/samples_v2/SampleBase/shaders/clothing_asset_static.hlsl @@ -0,0 +1,47 @@ +#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; +}; + +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; + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), model); + float4 eyeSpacePos = mul(worldSpacePos, view); + oV.position = mul(eyeSpacePos, projection); + + oV.worldPos = worldSpacePos; + + // normals + float3 worldNormal = mul(float4(iV.normal, 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 CalcPixelLight(textureColor, iV.worldPos, iV.normal); +}
\ No newline at end of file diff --git a/APEX_1.4/samples_v2/SampleBase/shaders/common_buffers.hlsl b/APEX_1.4/samples_v2/SampleBase/shaders/common_buffers.hlsl new file mode 100644 index 00000000..62bf0776 --- /dev/null +++ b/APEX_1.4/samples_v2/SampleBase/shaders/common_buffers.hlsl @@ -0,0 +1,29 @@ +#ifndef COMMON_BUFFERS_HLSL +#define COMMON_BUFFERS_HLSL + +cbuffer Camera : register(b0) +{ + row_major matrix projection; + row_major matrix projectionInv; + row_major matrix view; + 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; + float3 defaultColor; +}; + +#endif
\ No newline at end of file diff --git a/APEX_1.4/samples_v2/SampleBase/shaders/debug_primitive.hlsl b/APEX_1.4/samples_v2/SampleBase/shaders/debug_primitive.hlsl new file mode 100644 index 00000000..b96c53e3 --- /dev/null +++ b/APEX_1.4/samples_v2/SampleBase/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, view); + oV.position = mul(eyeSpacePos, projection); + + 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/APEX_1.4/samples_v2/SampleBase/shaders/destruction_asset.hlsl b/APEX_1.4/samples_v2/SampleBase/shaders/destruction_asset.hlsl new file mode 100644 index 00000000..bb2ed1c1 --- /dev/null +++ b/APEX_1.4/samples_v2/SampleBase/shaders/destruction_asset.hlsl @@ -0,0 +1,56 @@ +#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; + int boneIndex : TEXCOORD5; +}; + +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); + float4 eyeSpacePos = mul(worldSpacePos, view); + oV.position = mul(eyeSpacePos, projection); + + 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 CalcPixelLight(textureColor, iV.worldPos, iV.normal); +}
\ No newline at end of file diff --git a/APEX_1.4/samples_v2/SampleBase/shaders/lighting.hlsl b/APEX_1.4/samples_v2/SampleBase/shaders/lighting.hlsl new file mode 100644 index 00000000..6609dffa --- /dev/null +++ b/APEX_1.4/samples_v2/SampleBase/shaders/lighting.hlsl @@ -0,0 +1,48 @@ +#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); +}; + + +float4 CalcLight(float4 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); + float4 diffuse = float4(lightColor, 1) * textureColor * diffuseFactor * attenuation; + + // specular (Blinn-Phong) + float3 halfwayDir = normalize(dirToLight + viewDir); + float specFactor = pow(max(dot(viewDir, halfwayDir), 0.0), specPower); + float4 spec = float4(lightColor, 1) * specFactor * attenuation * specIntensity; + + return diffuse + spec; +}; + +float4 CalcPixelLight(float4 diffuseColor, float4 worldPos, float3 normal) +{ + float3 viewDir = normalize(viewPos - worldPos); + + // ambient + float4 ambient = float4(ambientColor, 1) * diffuseColor; + + // dir light + float4 dirLight = CalcLight(diffuseColor, dirLightDir, viewDir, normal, dirLightColor, specularPower, specularIntensity, 1); + + // point light + float3 pointLightDir = worldPos - pointLightPos; + float distance = length(pointLightDir); + float attenuation = CalcAttenuation(distance); + float4 pointLight = CalcLight(diffuseColor, pointLightDir, viewDir, normal, pointLightColor, specularPower, specularIntensity, attenuation); + + return ambient + dirLight + pointLight; +};
\ No newline at end of file diff --git a/APEX_1.4/samples_v2/SampleBase/shaders/mesh_particle.hlsl b/APEX_1.4/samples_v2/SampleBase/shaders/mesh_particle.hlsl new file mode 100644 index 00000000..615a1246 --- /dev/null +++ b/APEX_1.4/samples_v2/SampleBase/shaders/mesh_particle.hlsl @@ -0,0 +1,53 @@ +#include "common_buffers.hlsl" +#include "lighting.hlsl" + +SamplerState defaultSampler : register(s0); +Texture2D diffuseTexture : register(t0); + +static const float POINT_SIZE = 1.00f; + +struct VS_INPUT +{ + float3 position : POSITION0; + float3 normal : NORMAL; + float2 scale : TANGENT; + float2 uv : TEXCOORD0; + float3 instanceOffset : TEXCOORD9; + float3 instanceRotX : TEXCOORD10; + float3 instanceRotY : TEXCOORD11; + float3 instanceRotZ : TEXCOORD12; +}; + +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 modelMatrix = mul(model, float4x4(float4(iV.instanceRotX, 0), float4(iV.instanceRotY, 0), float4(iV.instanceRotZ, 0), float4(iV.instanceOffset, 1))); + + float4 worldSpacePos = mul(float4(iV.position, 1.0f), modelMatrix); + float4 eyeSpacePos = mul(worldSpacePos, view); + oV.position = mul(eyeSpacePos, projection); + + oV.worldPos = worldSpacePos; + + oV.uv = iV.uv; + + float3 worldNormal = mul(float4(iV.normal, 0.0f), modelMatrix); + oV.normal = worldNormal; + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + float4 textureColor = diffuseTexture.Sample(defaultSampler, iV.uv); + return CalcPixelLight(textureColor, iV.worldPos, iV.normal); +}
\ No newline at end of file diff --git a/APEX_1.4/samples_v2/SampleBase/shaders/physx_primitive.hlsl b/APEX_1.4/samples_v2/SampleBase/shaders/physx_primitive.hlsl new file mode 100644 index 00000000..80df4bf9 --- /dev/null +++ b/APEX_1.4/samples_v2/SampleBase/shaders/physx_primitive.hlsl @@ -0,0 +1,39 @@ +#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); + float4 eyeSpacePos = mul(worldSpacePos, view); + oV.position = mul(eyeSpacePos, projection); + + oV.worldPos = worldSpacePos; + + // normals + float3 worldNormal = mul(float4(iV.normal, 0.0f), model); + oV.normal = worldNormal; + + return oV; +} + +float4 PS(VS_OUTPUT iV) : SV_Target0 +{ + float4 textureColor = float4(defaultColor, 1); + + return CalcPixelLight(textureColor, iV.worldPos, iV.normal); +}
\ No newline at end of file diff --git a/APEX_1.4/samples_v2/SampleBase/shaders/pointsprite.hlsl b/APEX_1.4/samples_v2/SampleBase/shaders/pointsprite.hlsl new file mode 100644 index 00000000..f36d1187 --- /dev/null +++ b/APEX_1.4/samples_v2/SampleBase/shaders/pointsprite.hlsl @@ -0,0 +1,107 @@ +#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); + float4 eyeSpacePos = mul(worldSpacePos, view); + oV.position = mul(eyeSpacePos, projection); + + 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 |