Skip to content

Commit

Permalink
hlsl shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 16, 2024
1 parent 46cb0ff commit 58832ee
Show file tree
Hide file tree
Showing 70 changed files with 1,502 additions and 2,216 deletions.
2 changes: 1 addition & 1 deletion data/models/demolevel/demolevel.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/world_grid.shd"
shader "/pipelines/world_grid.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/pistol/darkermetal.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/pistol/magazine.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/pistol/material_003.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/pistol/metal.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/pistol/muzzle.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/pistol/wood.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/cone.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/cube.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/cylinder.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/material.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/monkey.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/plane.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/world_grid.shd"
shader "/pipelines/world_grid.hlsl"
backface_culling false
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/sphere.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/sphere_metal.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/torus.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/x.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/y.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/shapes/z.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/snake/darkgreen.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/snake/darkred.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/snake/lightgreen.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/snake/purple.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/snake/red.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/snake/teeth.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/snake/yellow.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/ybot/alpha_body_mat.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/ybot/alpha_joints_mat.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
backface_culling true
layer "default"

Expand Down
2 changes: 1 addition & 1 deletion data/models/ybot/material.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/models/ybot/material_001.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/standard.shd"
shader "/pipelines/standard.hlsl"
texture ""
texture ""
texture ""
Expand Down
2 changes: 1 addition & 1 deletion data/particles/demo/demo.mat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
shader "/pipelines/particles.shd"
shader "/pipelines/particles.hlsl"
backface_culling true
layer "transparent"

Expand Down
28 changes: 15 additions & 13 deletions data/pipelines/atmo.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cbuffer Data : register (b4) {
float4 u_fog_scattering;
float u_fog_top;
float u_fog_enabled;
float u_godarys_enabled;
float u_godrays_enabled;
uint u_output;
uint u_optical_depth;
uint u_depth_buffer;
Expand Down Expand Up @@ -52,10 +52,11 @@ void main(uint3 thread_id : SV_DispatchThreadID) {
float3 sunlight = u_sunlight.rgb * u_sunlight.a;
float ndc_depth = bindless_textures[u_depth_buffer][thread_id.xy].r;
float2 uv = thread_id.xy / (float2)Global_framebuffer_size.xy;
float3 eyedir = getWorldNormal(uv);
float3 eyedir = getViewDirection(uv);
const float cos_theta = dot(eyedir, Global_light_dir.xyz);

if (ndc_depth > 0) {
// sky is hidden some object
float linear_depth = toLinearDepth(Global_inv_projection, ndc_depth);
float2 v = float2(
saturate(linear_depth / 50e3),
Expand All @@ -71,7 +72,8 @@ void main(uint3 thread_id : SV_DispatchThreadID) {
;
}
else {
float spot = smoothstep(0.0, 1000.0, phase(cos_theta, 0.9995)) * 200;
// sky is visible
float sun_spot = smoothstep(0.0, 1000.0, phase(cos_theta, 0.9995)) * 200;

float2 v = 1;
v.y = max(0, eyedir.y);
Expand All @@ -87,43 +89,43 @@ void main(uint3 thread_id : SV_DispatchThreadID) {
atmo.rgb =
insc.aaa * miePhase(0.75, -cos_theta) * sunlight * u_scatter_mie.rgb
+ insc.rgb * rayleighPhase(-cos_theta) * sunlight * u_scatter_rayleigh.rgb
+ spot * exp(-opt_depth.x * extinction_rayleigh - opt_depth.y * extinction_mie)
+ sun_spot * exp(-opt_depth.x * extinction_rayleigh - opt_depth.y * extinction_mie)
;
}

if (u_fog_enabled > 0) {
const float3 fog_extinction = u_fog_scattering.rgb;
float linear_depth = ndc_depth > 0 ? toLinearDepth(Global_inv_projection, ndc_depth) : 1e5;
float dist = (linear_depth / dot(eyedir, Global_view_dir.xyz));
float3 p0 = Global_camera_world_pos.xyz;
float3 p1 = Global_camera_world_pos.xyz + eyedir * dist;
makeAscending(p0, p1);

if (p0.y < u_fog_top) {
if (p1.y > u_fog_top) {
const bool is_in_fog = p0.y < u_fog_top;
if (is_in_fog) {
const bool is_partially_in_fog = p1.y > u_fog_top;
if (is_partially_in_fog) {
// clip to top of fog
float3 dir = p1 - p0;
float3 diry1 = dir / (abs(dir.y) < 1e-5 ? 1e-5 : dir.y);
p1 -= diry1 * (p1.y - u_fog_top);
}

float3 fog_transmittance = exp(-distanceInFog(p0, p1) * fog_extinction);
float3 fog_transmittance = exp(-distanceInFog(p0, p1) * u_fog_scattering.rgb);

float3 inscatter = 0;
{
const int STEP_COUNT = u_godarys_enabled > 0 ? 32 : 8;
const int STEP_COUNT = u_godrays_enabled > 0 ? 32 : 8;
float step_len = length(p1 - p0) / (STEP_COUNT + 1);
float offset = hash((float2)thread_id.xy * 0.05);
for (float f = (offset ) / STEP_COUNT; f < 1; f += 1.0 / (STEP_COUNT + 1)) {
float3 p = lerp(p0, p1, f);
float od = distanceInFog(p, p + Global_light_dir.xyz * 1e5); // TODO 1e5
od += distanceInFog(p, Global_camera_world_pos.xyz);
float shadow = u_godarys_enabled > 0 ? getShadowSimple(Global_shadowmap, p - Global_camera_world_pos.xyz) : 1;
inscatter += getFogDensity(p) * step_len * exp(-od * fog_extinction) * shadow;
float shadow = u_godrays_enabled > 0 ? getShadowSimple(Global_shadowmap, p - Global_camera_world_pos.xyz) : 1;
inscatter += getFogDensity(p) * step_len * exp(-od * u_fog_scattering.rgb) * shadow;
}
}

const float cos_theta = dot(eyedir, Global_light_dir.xyz);

scene.rgb = fog_transmittance;
atmo.rgb += inscatter * u_fog_scattering.rgb * sunlight * miePhase(0.25, -cos_theta);
}
Expand Down
25 changes: 25 additions & 0 deletions data/pipelines/blit.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//@include "pipelines/common.hlsli"

cbuffer Drawcall : register(b4) {
float4 u_r_mask;
float4 u_g_mask;
float4 u_b_mask;
float4 u_a_mask;
float4 u_offsets;
uint2 u_position;
int2 u_scale;
uint u_input;
uint u_output;
};

[numthreads(16, 16, 1)]
void main(uint3 thread_id : SV_DispatchThreadID) {
float4 value = bindless_textures[u_input][thread_id.xy];

bindless_rw_textures[u_output][thread_id.xy * u_scale + u_position] = float4(
dot(value, u_r_mask) + u_offsets.r,
dot(value, u_g_mask) + u_offsets.g,
dot(value, u_b_mask) + u_offsets.b,
dot(value, u_a_mask) + u_offsets.a
);
}
14 changes: 4 additions & 10 deletions data/pipelines/bloom_blur.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ cbuffer Drawcall : register(b4) {
uint u_small;
};

struct Output {
struct VSOutput {
float2 tc0 : TEXCOORD0;
float4 tc1 : TEXCOORD1;
float4 tc2 : TEXCOORD2;
float4 position : SV_POSITION;
};

Output mainVS(uint vertex_id : SV_VertexID) {
Output output;
VSOutput mainVS(uint vertex_id : SV_VertexID) {
VSOutput output;
float2 uv;
output.position = fullscreenQuad(vertex_id, uv);
output.tc0 = uv;
Expand All @@ -41,14 +41,8 @@ Output mainVS(uint vertex_id : SV_VertexID) {
return output;
}

struct Input {
float2 tc0 : TEXCOORD0;
float4 tc1 : TEXCOORD1;
float4 tc2 : TEXCOORD2;
};

// blur bigger in one axis and merge with smaller (already blurred from previous step)
float4 mainPS(Input input) : SV_Target {
float4 mainPS(VSOutput input) : SV_Target {
return sampleBindless(LinearSamplerClamp, u_small, input.tc0.xy) * 0.5
+ ((sampleBindless(LinearSamplerClamp, u_big, input.tc0.xy)) * 0.2270270270
+ (sampleBindless(LinearSamplerClamp, u_big, input.tc1.xy)) * 0.3162162162
Expand Down
14 changes: 4 additions & 10 deletions data/pipelines/blur.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ cbuffer Drawcall : register(b4) {
uint u_input;
};

struct Output {
struct VSOutput {
float2 tc0 : TEXCOORD0;
float4 tc1 : TEXCOORD1;
float4 tc2 : TEXCOORD2;
float4 position : SV_POSITION;
};

Output mainVS(uint vertex_id : SV_VertexID) {
Output output;
VSOutput mainVS(uint vertex_id : SV_VertexID) {
VSOutput output;
float2 uv;
output.position = fullscreenQuad(vertex_id, uv);
output.tc0 = uv;
Expand All @@ -40,13 +40,7 @@ Output mainVS(uint vertex_id : SV_VertexID) {
return output;
}

struct Input {
float2 tc0 : TEXCOORD0;
float4 tc1 : TEXCOORD1;
float4 tc2 : TEXCOORD2;
};

float4 mainPS(Input input) : SV_Target {
float4 mainPS(VSOutput input) : SV_Target {
float2 uv0 = saturate(input.tc0.xy);
float2 uv1 = saturate(input.tc1.xy);
float2 uv2 = saturate(input.tc1.zw);
Expand Down
Loading

0 comments on commit 58832ee

Please sign in to comment.