dofdemo/Assets/backbox.hlsl
2024-11-24 13:30:57 -05:00

53 lines
No EOL
1.4 KiB
HLSL

#include "stereokit.hlsli"
//--name = dofdev/backbox
//--color:color = 1, 1, 1, 1
float4 color;
struct vsIn {
float4 pos : SV_Position;
float3 norm : NORMAL0;
float2 uv : TEXCOORD0;
// float4 col : COLOR0;
};
struct psIn {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR0;
float3 normal : NORMAL0;
float3 world_pos : WORLD;
float3 cam_pos : TEXCOORD1;
float3 cam_dir : TEXCOORD2;
uint view_id : SV_RenderTargetArrayIndex;
};
psIn vs(vsIn input, uint id : SV_InstanceID) {
psIn o;
o.view_id = id % sk_view_count;
id = id / sk_view_count;
o.cam_pos = sk_camera_pos[o.view_id].xyz;
o.cam_dir = sk_camera_dir[o.view_id].xyz;
float3 world = mul(float4(input.pos.xyz, 1), sk_inst[id].world).xyz;
o.pos = mul(float4(world, 1), sk_viewproj[o.view_id]);
o.world_pos = world;
// flip input normals to treat backfaces like normal
o.normal = normalize(mul(-input.norm, (float3x3)sk_inst[id].world));
o.uv = input.uv;
o.color = color * sk_inst[id].color;
return o;
}
float4 ps(psIn input) : SV_TARGET {
float3 view_dir = normalize(input.world_pos - input.cam_pos);
// Fresnel effect calculation
float fresnel = 1.0 - saturate(dot(-view_dir, input.normal));
fresnel = pow(fresnel, 5.0); // Adjust power for different falloff rates
float value = 0.5;
return float4(fresnel * input.color.rgb * value, input.color.a);
}