dofdemo/Assets/colorcube.hlsl
2024-12-07 17:57:31 -05:00

48 lines
No EOL
1 KiB
HLSL

#include "stereokit.hlsli"
//--name = dofdev/colorcube
//--color:color = 1, 1, 1, 1
float4 color;
struct vsIn {
float4 pos : SV_Position;
float3 norm : NORMAL0;
};
struct psIn {
float4 pos : SV_POSITION;
float3 col_pos : TEXCOORD0;
float4 color : COLOR0;
uint view_id : SV_RenderTargetArrayIndex;
};
float f_inv(float x) {
if (x >= 0.04045) {
return pow((x + 0.055)/(1 + 0.055), 2.4);
}
return x / 12.92;
}
psIn vs(vsIn input, uint id : SV_InstanceID) {
psIn o;
o.view_id = id % sk_view_count;
id = id / sk_view_count;
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.col_pos = input.pos.xyz + float3(0.5, 0.5, 0.5);
float3 normal = normalize(mul(input.norm, (float3x3)sk_inst[id].world));
o.color = color * sk_inst[id].color;
return o;
}
float4 ps(psIn input) : SV_TARGET {
// pos to color
float3 col = float3(input.col_pos);
// linear to sRGB
return float4(f_inv(col.r), f_inv(col.g), f_inv(col.b), 1);
}