kong test
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform vec2 screen_size_inv;
|
||||
uniform int current_mip_level;
|
||||
|
||||
in vec2 tex_coord;
|
||||
out vec4 frag_color;
|
||||
|
||||
const float bloom_knee = 0.5;
|
||||
const float bloom_threshold = 0.8;
|
||||
const float epsilon = 6.2e-5;
|
||||
|
||||
vec3 downsample_dual_filter(const sampler2D tex, const vec2 tex_coord, const vec2 texel_size) {
|
||||
vec3 delta = texel_size.xyx * vec3(0.5, 0.5, -0.5);
|
||||
|
||||
vec3 result;
|
||||
result = textureLod(tex, tex_coord, 0.0).rgb * 4.0;
|
||||
result += textureLod(tex, tex_coord - delta.xy, 0.0).rgb;
|
||||
result += textureLod(tex, tex_coord - delta.zy, 0.0).rgb;
|
||||
result += textureLod(tex, tex_coord + delta.zy, 0.0).rgb;
|
||||
result += textureLod(tex, tex_coord + delta.xy, 0.0).rgb;
|
||||
|
||||
return result * (1.0 / 8.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
frag_color.rgb = downsample_dual_filter(tex, tex_coord, screen_size_inv);
|
||||
|
||||
if (current_mip_level == 0) {
|
||||
float brightness = max(frag_color.r, max(frag_color.g, frag_color.b));
|
||||
|
||||
float softening_curve = brightness - bloom_threshold + bloom_knee;
|
||||
softening_curve = clamp(softening_curve, 0.0, 2.0 * bloom_knee);
|
||||
softening_curve = softening_curve * softening_curve / (4 * bloom_knee + epsilon);
|
||||
|
||||
float contribution_factor = max(softening_curve, brightness - bloom_threshold);
|
||||
|
||||
contribution_factor /= max(epsilon, brightness);
|
||||
|
||||
frag_color.rgb *= contribution_factor;
|
||||
}
|
||||
|
||||
frag_color.a = 1.0;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
|
||||
#[set(everything)]
|
||||
const tex: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const tex_sampler: sampler;
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
screen_size_inv: float2;
|
||||
current_mip_level: int;
|
||||
};
|
||||
|
||||
struct vert_in {
|
||||
pos: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
const bloom_knee: float = 0.5;
|
||||
const bloom_threshold: float = 0.8;
|
||||
const epsilon: float = 0.000062;
|
||||
|
||||
fun bloom_downsample_pass_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.tex = input.pos.xy * 0.5 + 0.5;
|
||||
output.tex.y = 1.0 - output.tex.y;
|
||||
output.pos = float4(input.pos.xy, 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
fun downsample_dual_filter(tex: tex2d, tex_coord: float2, texel_size: float2): float3 {
|
||||
var delta: float3 = float3(texel_size.xy, texel_size.x) * float3(0.5, 0.5, -0.5);
|
||||
|
||||
var result: float3;
|
||||
result = sample_lod(tex, tex_sampler, tex_coord, 0.0).rgb * 4.0;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord - delta.xy, 0.0).rgb;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord - delta.zy, 0.0).rgb;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord + delta.zy, 0.0).rgb;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord + delta.xy, 0.0).rgb;
|
||||
|
||||
return result * (1.0 / 8.0);
|
||||
}
|
||||
|
||||
fun bloom_downsample_pass_frag(input: vert_out): float4 {
|
||||
var color: float4;
|
||||
color.rgb = downsample_dual_filter(tex, input.tex, constants.screen_size_inv);
|
||||
|
||||
if (constants.current_mip_level == 0) {
|
||||
var brightness: float = max(color.r, max(color.g, color.b));
|
||||
|
||||
var softening_curve: float = brightness - bloom_threshold + bloom_knee;
|
||||
softening_curve = clamp(softening_curve, 0.0, 2.0 * bloom_knee);
|
||||
softening_curve = softening_curve * softening_curve / (4 * bloom_knee + epsilon);
|
||||
|
||||
var contribution_factor: float = max(softening_curve, brightness - bloom_threshold);
|
||||
|
||||
contribution_factor /= max(epsilon, brightness);
|
||||
|
||||
color.rgb *= contribution_factor;
|
||||
}
|
||||
|
||||
color.a = 1.0;
|
||||
return color;
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = bloom_downsample_pass_vert;
|
||||
fragment = bloom_downsample_pass_frag;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform vec2 screen_size_inv;
|
||||
uniform int current_mip_level;
|
||||
uniform float sample_scale;
|
||||
|
||||
in vec2 tex_coord;
|
||||
out vec4 frag_color;
|
||||
|
||||
const float bloom_strength = 0.02;
|
||||
|
||||
vec3 upsample_dual_filter(const sampler2D tex, const vec2 tex_coord, const vec2 texel_size) {
|
||||
vec2 delta = texel_size * sample_scale;
|
||||
|
||||
vec3 result;
|
||||
result = textureLod(tex, tex_coord + vec2(-delta.x * 2.0, 0.0), 0.0).rgb;
|
||||
result += textureLod(tex, tex_coord + vec2(-delta.x, delta.y), 0.0).rgb * 2.0;
|
||||
result += textureLod(tex, tex_coord + vec2(0.0, delta.y * 2.0), 0.0).rgb;
|
||||
result += textureLod(tex, tex_coord + delta, 0.0).rgb * 2.0;
|
||||
result += textureLod(tex, tex_coord + vec2(delta.x * 2.0, 0.0), 0.0).rgb;
|
||||
result += textureLod(tex, tex_coord + vec2(delta.x, -delta.y), 0.0).rgb * 2.0;
|
||||
result += textureLod(tex, tex_coord + vec2(0.0, -delta.y * 2.0), 0.0).rgb;
|
||||
result += textureLod(tex, tex_coord - delta, 0.0).rgb * 2.0;
|
||||
|
||||
return result * (1.0 / 12.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
frag_color.rgb = upsample_dual_filter(tex, tex_coord, screen_size_inv);
|
||||
|
||||
if (current_mip_level == 0) {
|
||||
frag_color.rgb *= bloom_strength;
|
||||
}
|
||||
|
||||
frag_color.a = 1.0;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
#[set(everything)]
|
||||
const tex: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const tex_sampler: sampler;
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
screen_size_inv: float2;
|
||||
current_mip_level: int;
|
||||
sample_scale: float;
|
||||
};
|
||||
|
||||
struct vert_in {
|
||||
pos: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
const bloom_strength: float = 0.02;
|
||||
|
||||
fun bloom_upsample_pass_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.tex = input.pos.xy * 0.5 + 0.5;
|
||||
output.tex.y = 1.0 - output.tex.y;
|
||||
output.pos = float4(input.pos.xy, 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
fun upsample_dual_filter(tex: tex2d, tex_coord: float2, texel_size: float2): float3 {
|
||||
var delta: float2 = texel_size * constants.sample_scale;
|
||||
|
||||
var result: float3;
|
||||
result = sample_lod(tex, tex_sampler, tex_coord + float2(-delta.x * 2.0, 0.0), 0.0).rgb;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord + float2(-delta.x, delta.y), 0.0).rgb * 2.0;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord + float2(0.0, delta.y * 2.0), 0.0).rgb;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord + delta, 0.0).rgb * 2.0;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord + float2(delta.x * 2.0, 0.0), 0.0).rgb;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord + float2(delta.x, -delta.y), 0.0).rgb * 2.0;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord + float2(0.0, -delta.y * 2.0), 0.0).rgb;
|
||||
result += sample_lod(tex, tex_sampler, tex_coord - delta, 0.0).rgb * 2.0;
|
||||
|
||||
return result * (1.0 / 12.0);
|
||||
}
|
||||
|
||||
fun bloom_upsample_pass_frag(input: vert_out): float4 {
|
||||
var color: float4;
|
||||
color.rgb = upsample_dual_filter(tex, input.tex, constants.screen_size_inv);
|
||||
|
||||
if (constants.current_mip_level == 0) {
|
||||
color.rgb = color.rgb * bloom_strength;
|
||||
}
|
||||
|
||||
color.a = 1.0;
|
||||
return color;
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = bloom_upsample_pass_vert;
|
||||
fragment = bloom_upsample_pass_frag;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform sampler2D tex;
|
||||
// uniform sampler2D histogram;
|
||||
uniform float vignette_strength;
|
||||
uniform float grain_strength;
|
||||
|
||||
in vec2 tex_coord;
|
||||
out vec4 frag_color;
|
||||
|
||||
// Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
|
||||
vec3 tonemap_filmic(const vec3 color) {
|
||||
vec3 x = max(vec3(0.0, 0.0, 0.0), color - 0.004);
|
||||
return (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06);
|
||||
}
|
||||
|
||||
void main() {
|
||||
frag_color = textureLod(tex, tex_coord, 0.0);
|
||||
|
||||
// Static grain
|
||||
float x = (tex_coord.x + 4.0) * (tex_coord.y + 4.0) * 10.0;
|
||||
float g = mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01) - 0.005;
|
||||
frag_color.rgb += vec3(g, g, g) * grain_strength;
|
||||
|
||||
frag_color.rgb *= (1.0 - vignette_strength) + vignette_strength * pow(16.0 * tex_coord.x * tex_coord.y * (1.0 - tex_coord.x) * (1.0 - tex_coord.y), 0.2);
|
||||
|
||||
// Auto exposure
|
||||
// const float auto_exposure_strength = 1.0;
|
||||
// float expo = 2.0 - clamp(length(textureLod(histogram, vec2(0.5, 0.5), 0.0).rgb), 0.0, 1.0);
|
||||
// frag_color.rgb *= pow(expo, auto_exposure_strength * 2.0);
|
||||
|
||||
frag_color.rgb = tonemap_filmic(frag_color.rgb); // With gamma
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
|
||||
#[set(everything)]
|
||||
const tex: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const tex_sampler: sampler;
|
||||
|
||||
// #[set(everything)]
|
||||
// const histogram: tex2d;
|
||||
|
||||
// #[set(everything)]
|
||||
// const histogram_sampler: sampler;
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
vignette_strength: float;
|
||||
grain_strength: float;
|
||||
};
|
||||
|
||||
struct vert_in {
|
||||
pos: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
fun compositor_pass_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.tex = input.pos.xy * 0.5 + 0.5;
|
||||
output.tex.y = 1.0 - output.tex.y;
|
||||
output.pos = float4(input.pos.xy, 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
fun tonemap_filmic(color: float3): float3 {
|
||||
// Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
|
||||
// var x: float3 = max(float3(0.0, 0.0, 0.0), color - 0.004);
|
||||
var x: float3;
|
||||
x.x = max(float3(0.0, 0.0, 0.0), color.x - 0.004);
|
||||
x.y = max(float3(0.0, 0.0, 0.0), color.y - 0.004);
|
||||
x.z = max(float3(0.0, 0.0, 0.0), color.z - 0.004);
|
||||
return (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06);
|
||||
}
|
||||
|
||||
fun compositor_pass_frag(input: vert_out): float4 {
|
||||
var color: float4 = sample_lod(tex, tex_sampler, input.tex, 0.0);
|
||||
|
||||
// Static grain
|
||||
var x: float = (input.tex.x + 4.0) * (input.tex.y + 4.0) * 10.0;
|
||||
var g: float = (((x % 13.0) + 1.0) * ((x % 123.0) + 1.0) % 0.01) - 0.005;
|
||||
color.rgb += float3(g, g, g) * constants.grain_strength;
|
||||
|
||||
color.rgb *= (1.0 - constants.vignette_strength) + constants.vignette_strength * pow(16.0 * input.tex.x * input.tex.y * (1.0 - input.tex.x) * (1.0 - input.tex.y), 0.2);
|
||||
|
||||
// Auto exposure
|
||||
// const float auto_exposure_strength = 1.0;
|
||||
// float expo = 2.0 - clamp(length(sample_lod(histogram, histogram_sampler, float2(0.5, 0.5), 0.0).rgb), 0.0, 1.0);
|
||||
// color.rgb *= pow(expo, auto_exposure_strength * 2.0);
|
||||
|
||||
color.rgb = tonemap_filmic(color.rgb); // With gamma
|
||||
return color;
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = compositor_pass_vert;
|
||||
fragment = compositor_pass_frag;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform sampler2D tex0;
|
||||
uniform sampler2D tex1;
|
||||
uniform sampler2D tex2;
|
||||
|
||||
in vec2 tex_coord;
|
||||
out vec4 frag_color[3];
|
||||
|
||||
void main() {
|
||||
frag_color[0] = textureLod(tex0, tex_coord, 0.0);
|
||||
frag_color[1] = textureLod(tex1, tex_coord, 0.0);
|
||||
frag_color[2] = textureLod(tex2, tex_coord, 0.0);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#[set(everything)]
|
||||
const tex0: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const tex0_sampler: sampler;
|
||||
|
||||
#[set(everything)]
|
||||
const tex1: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const tex1_sampler: sampler;
|
||||
|
||||
#[set(everything)]
|
||||
const tex2: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const tex2_sampler: sampler;
|
||||
|
||||
struct vert_in {
|
||||
pos: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
fun copy_mrt3_pass_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.tex = input.pos.xy * 0.5 + 0.5;
|
||||
output.tex.y = 1.0 - output.tex.y;
|
||||
output.pos = float4(input.pos.xy, 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
fun copy_mrt3_pass_frag(input: vert_out): float4[3] {
|
||||
var color: float4[3];
|
||||
color[0].rgba = sample_lod(tex0, tex0_sampler, input.tex, 0.0);
|
||||
color[1].rgba = sample_lod(tex1, tex1_sampler, input.tex, 0.0);
|
||||
color[2].rgba = sample_lod(tex2, tex2_sampler, input.tex, 0.0);
|
||||
return color;
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = copy_mrt3_pass_vert;
|
||||
fragment = copy_mrt3_pass_frag;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#[set(everything)]
|
||||
const tex: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const tex_sampler: sampler;
|
||||
|
||||
struct vert_in {
|
||||
pos: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
fun copy_pass_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.tex = input.pos.xy * 0.5 + 0.5;
|
||||
output.tex.y = 1.0 - output.tex.y;
|
||||
output.pos = float4(input.pos.xy, 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
fun copy_pass_frag(input: vert_out): float4 {
|
||||
var color: float4 = sample_lod(tex, tex_sampler, input.tex, 0.0);
|
||||
return color;
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = copy_pass_vert;
|
||||
fragment = copy_pass_frag;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform vec3 tint;
|
||||
|
||||
in vec2 tex_coord;
|
||||
out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
float radius = 0.45;
|
||||
float thickness = 0.03;
|
||||
float dist = distance(tex_coord, vec2(0.5, 0.5));
|
||||
float ring = smoothstep(radius - thickness, radius, dist) -
|
||||
smoothstep(radius, radius + thickness, dist);
|
||||
frag_color = vec4(tint, min(ring, 0.6));
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
VP: float4x4;
|
||||
invVP: float4x4;
|
||||
mouse: float2;
|
||||
tex_step: float2;
|
||||
radius: float;
|
||||
camera_right: float3;
|
||||
tint: float3;
|
||||
};
|
||||
|
||||
#[set(everything)]
|
||||
const gbufferD: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const gbufferD_sampler: sampler;
|
||||
|
||||
struct vert_in {
|
||||
pos: float4; // hlsl
|
||||
nor: float2; // hlsl
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
fun get_pos(uv: float2): float3 {
|
||||
// var depth: float = sample_lod(gbufferD, gbufferD_sampler, uv, 0.0).r;
|
||||
var depth: float = sample_lod(gbufferD, gbufferD_sampler, float2(uv.x, 1.0 - uv.y), 0.0).r;
|
||||
var wpos: float4 = float4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
||||
wpos = constants.invVP * wpos;
|
||||
return wpos.xyz / wpos.w;
|
||||
}
|
||||
|
||||
fun get_normal(p0: float3, uv: float2): float3 {
|
||||
var p1: float3 = get_pos(uv + float2(constants.tex_step.x * 4.0, 0.0));
|
||||
var p2: float3 = get_pos(uv + float2(0.0, constants.tex_step.y * 4.0));
|
||||
return normalize(cross(p2 - p0, p1 - p0));
|
||||
}
|
||||
|
||||
// fun create_basis(normal: float3, out tangent: float3, out binormal: float3) {
|
||||
// tangent = normalize(constants.camera_right - normal * dot(constants.camera_right, normal));
|
||||
// binormal = cross(tangent, normal);
|
||||
// }
|
||||
|
||||
fun cursor_vert(input: vert_in): vert_out {
|
||||
|
||||
var keep: float = input.pos.x + input.nor.x; // hlsl
|
||||
|
||||
var output: vert_out;
|
||||
output.tex = input.tex;
|
||||
var wpos: float3 = get_pos(constants.mouse);
|
||||
var uv1: float2 = constants.mouse + constants.tex_step * float2(4.0, 4.0);
|
||||
var uv2: float2 = constants.mouse - constants.tex_step * float2(4.0, 4.0);
|
||||
var wpos1: float3 = get_pos(uv1);
|
||||
var wpos2: float3 = get_pos(uv2);
|
||||
var n: float3 = normalize(get_normal(wpos, constants.mouse) + get_normal(wpos1, uv1) + get_normal(wpos2, uv2));
|
||||
var n_tan: float3;
|
||||
var n_bin: float3;
|
||||
|
||||
// create_basis(n, n_tan, n_bin);
|
||||
n_tan = normalize(constants.camera_right - n * dot(constants.camera_right, n));
|
||||
n_bin = cross(n_tan, n);
|
||||
|
||||
var x_bit: float = (input.pos.x + 16383.0) / (2.0 * 16383.0);
|
||||
var z_bit: float = (input.pos.z + 16383.0) / (2.0 * 16383.0);
|
||||
var vertex_id: int = int(2.0 * x_bit + z_bit);
|
||||
|
||||
if (input.pos.x < 0 && input.pos.z < 0) {
|
||||
vertex_id = 0;
|
||||
}
|
||||
if (input.pos.x > 0 && input.pos.z < 0) {
|
||||
vertex_id = 1;
|
||||
}
|
||||
if (input.pos.x > 0 && input.pos.z > 0) {
|
||||
vertex_id = 2;
|
||||
}
|
||||
if (input.pos.x < 0 && input.pos.z > 0) {
|
||||
vertex_id = 3;
|
||||
}
|
||||
|
||||
if (vertex_id == 0) {
|
||||
wpos += normalize(-n_tan - n_bin) * 0.7 * constants.radius;
|
||||
}
|
||||
/*else */if (vertex_id == 1) {
|
||||
wpos += normalize( n_tan - n_bin) * 0.7 * constants.radius;
|
||||
}
|
||||
/*else */if (vertex_id == 2) {
|
||||
wpos += normalize( n_tan + n_bin) * 0.7 * constants.radius;
|
||||
}
|
||||
/*else */if (vertex_id == 3) {
|
||||
wpos += normalize(-n_tan + n_bin) * 0.7 * constants.radius;
|
||||
}
|
||||
|
||||
output.pos = constants.VP * float4(wpos, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
fun cursor_frag(input: vert_out): float4 {
|
||||
var radius: float = 0.45;
|
||||
var thickness: float = 0.03;
|
||||
var dist: float = distance(input.tex, float2(0.5, 0.5));
|
||||
var ring: float = smoothstep(radius - thickness, radius, dist) - smoothstep(radius, radius + thickness, dist);
|
||||
return float4(constants.tint, min(ring, 0.6));
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = cursor_vert;
|
||||
fragment = cursor_frag;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform mat4 VP;
|
||||
uniform mat4 invVP;
|
||||
uniform vec2 mouse;
|
||||
uniform vec2 tex_step;
|
||||
uniform float radius;
|
||||
uniform vec3 camera_right;
|
||||
uniform sampler2D gbufferD;
|
||||
|
||||
#ifdef HLSL
|
||||
in vec4 pos;
|
||||
in vec2 nor;
|
||||
#endif
|
||||
in vec2 tex;
|
||||
out vec2 tex_coord;
|
||||
|
||||
vec3 get_pos(vec2 uv) {
|
||||
#ifdef HLSL
|
||||
float keep = pos.x + nor.x;
|
||||
#endif
|
||||
|
||||
#ifdef GLSL
|
||||
float depth = textureLod(gbufferD, uv, 0.0).r;
|
||||
#else
|
||||
float depth = textureLod(gbufferD, vec2(uv.x, 1.0 - uv.y), 0.0).r;
|
||||
#endif
|
||||
|
||||
vec4 wpos = vec4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
||||
wpos = mul(wpos, invVP);
|
||||
return wpos.xyz / wpos.w;
|
||||
}
|
||||
|
||||
vec3 get_normal(vec3 p0, vec2 uv) {
|
||||
vec3 p1 = get_pos(uv + vec2(tex_step.x * 4.0, 0.0));
|
||||
vec3 p2 = get_pos(uv + vec2(0.0, tex_step.y * 4.0));
|
||||
return normalize(cross(p2 - p0, p1 - p0));
|
||||
}
|
||||
|
||||
void create_basis(vec3 normal, OUT(vec3, tangent), OUT(vec3, binormal)) {
|
||||
tangent = normalize(camera_right - normal * dot(camera_right, normal));
|
||||
binormal = cross(tangent, normal);
|
||||
}
|
||||
|
||||
void main() {
|
||||
tex_coord = tex;
|
||||
vec3 wpos = get_pos(mouse);
|
||||
vec2 uv1 = mouse + tex_step * vec2(4.0, 4.0);
|
||||
vec2 uv2 = mouse - tex_step * vec2(4.0, 4.0);
|
||||
vec3 wpos1 = get_pos(uv1);
|
||||
vec3 wpos2 = get_pos(uv2);
|
||||
vec3 n = normalize(
|
||||
get_normal(wpos, mouse) +
|
||||
get_normal(wpos1, uv1) +
|
||||
get_normal(wpos2, uv2)
|
||||
);
|
||||
vec3 n_tan;
|
||||
vec3 n_bin;
|
||||
create_basis(n, n_tan, n_bin);
|
||||
if (gl_VertexID == 0) wpos += normalize(-n_tan - n_bin) * 0.7 * radius;
|
||||
else if (gl_VertexID == 1) wpos += normalize( n_tan - n_bin) * 0.7 * radius;
|
||||
else if (gl_VertexID == 2) wpos += normalize( n_tan + n_bin) * 0.7 * radius;
|
||||
else if (gl_VertexID == 3) wpos += normalize(-n_tan + n_bin) * 0.7 * radius;
|
||||
gl_Position = mul(vec4(wpos, 1.0), VP);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
in vec2 tex_coord;
|
||||
out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
const float auto_exposure_speed = 1.0;
|
||||
frag_color.a = 0.01 * auto_exposure_speed;
|
||||
frag_color.rgb = textureLod(tex, vec2(0.5, 0.5), 0.0).rgb +
|
||||
textureLod(tex, vec2(0.2, 0.2), 0.0).rgb +
|
||||
textureLod(tex, vec2(0.8, 0.2), 0.0).rgb +
|
||||
textureLod(tex, vec2(0.2, 0.8), 0.0).rgb +
|
||||
textureLod(tex, vec2(0.8, 0.8), 0.0).rgb;
|
||||
frag_color.rgb /= 5.0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#[set(everything)]
|
||||
const tex: tex2d;
|
||||
|
||||
#[set(everything)]
|
||||
const tex_sampler: sampler;
|
||||
|
||||
struct vert_in {
|
||||
pos: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
const auto_exposure_speed: float = 1.0;
|
||||
|
||||
fun histogram_pass_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.tex = input.pos.xy * 0.5 + 0.5;
|
||||
output.tex.y = 1.0 - output.tex.y;
|
||||
output.pos = float4(input.pos.xy, 0.0, 1.0);
|
||||
return output;
|
||||
}
|
||||
|
||||
fun histogram_pass_frag(input: vert_out): float4 {
|
||||
var color: float4;
|
||||
color.a = 0.01 * auto_exposure_speed;
|
||||
color.rgb = sample_lod(tex, tex_sampler, float2(0.5, 0.5), 0.0).rgb +
|
||||
sample_lod(tex, tex_sampler, float2(0.2, 0.2), 0.0).rgb +
|
||||
sample_lod(tex, tex_sampler, float2(0.8, 0.2), 0.0).rgb +
|
||||
sample_lod(tex, tex_sampler, float2(0.2, 0.8), 0.0).rgb +
|
||||
sample_lod(tex, tex_sampler, float2(0.8, 0.8), 0.0).rgb;
|
||||
color.rgb /= 5.0;
|
||||
return color;
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = histogram_pass_vert;
|
||||
fragment = histogram_pass_frag;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#version 450
|
||||
|
||||
in vec3 vcolor;
|
||||
out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
frag_color = vec4(vcolor, 1.0);
|
||||
frag_color.rgb = pow(frag_color.rgb, vec3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2));
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
WVP: float4x4;
|
||||
};
|
||||
|
||||
struct vert_in {
|
||||
pos: float4;
|
||||
col: float4;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
vcolor: float3;
|
||||
}
|
||||
|
||||
fun mesh_poscol_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
var spos: float4 = float4(input.pos.xyz, 1.0);
|
||||
output.vcolor = input.col.rgb;
|
||||
output.pos = constants.WVP * spos;
|
||||
return output;
|
||||
}
|
||||
|
||||
fun mesh_poscol_frag(input: vert_out): float4 {
|
||||
var color: float4;
|
||||
color = float4(input.vcolor, 1.0);
|
||||
// color.rgb = pow(color.rgb, vec3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2));
|
||||
color.r = pow(color.r, 1.0 / 2.2);
|
||||
color.g = pow(color.g, 1.0 / 2.2);
|
||||
color.b = pow(color.b, 1.0 / 2.2);
|
||||
return color;
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = mesh_poscol_vert;
|
||||
fragment = mesh_poscol_frag;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform mat4 WVP;
|
||||
|
||||
in vec4 pos;
|
||||
in vec4 col;
|
||||
out vec3 vcolor;
|
||||
|
||||
void main() {
|
||||
vec4 spos = vec4(pos.xyz, 1.0);
|
||||
vcolor = col.rgb;
|
||||
gl_Position = mul(spos, WVP);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
#version 450
|
||||
|
||||
#include "../../base/shaders/std/gbuffer.glsl"
|
||||
|
||||
in vec3 wnormal;
|
||||
in vec4 wvpposition;
|
||||
in vec4 prevwvpposition;
|
||||
out vec4 frag_color[3];
|
||||
|
||||
void main() {
|
||||
vec3 n = normalize(wnormal);
|
||||
vec3 basecol = vec3(0.8, 0.8, 0.8);
|
||||
float roughness = 0.25;
|
||||
float metallic = 0.0;
|
||||
float occlusion = 1.0;
|
||||
n /= (abs(n.x) + abs(n.y) + abs(n.z));
|
||||
n.xy = n.z >= 0.0 ? n.xy : octahedron_wrap(n.xy);
|
||||
uint matid = uint(0);
|
||||
frag_color[0] = vec4(n.xy, roughness, pack_f32_i16(metallic, matid));
|
||||
frag_color[1] = vec4(basecol, occlusion);
|
||||
vec2 posa = (wvpposition.xy / wvpposition.w) * 0.5 + 0.5;
|
||||
vec2 posb = (prevwvpposition.xy / prevwvpposition.w) * 0.5 + 0.5;
|
||||
frag_color[2].rg = vec2(posa - posb);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
N: float3x3;
|
||||
WVP: float4x4;
|
||||
};
|
||||
|
||||
struct vert_in {
|
||||
pos: float4;
|
||||
nor: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
wnormal: float3;
|
||||
}
|
||||
|
||||
fun mesh_posnor_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.pos = constants.WVP * float4(input.pos.xyz, 1.0);
|
||||
output.wnormal = normalize(constants.N * float3(input.nor.xy, input.pos.w));
|
||||
return output;
|
||||
}
|
||||
|
||||
fun octahedron_wrap(v: float2): float2 {
|
||||
var a: float2;
|
||||
if (v.x >= 0.0) {
|
||||
a.x = 1.0;
|
||||
}
|
||||
else {
|
||||
a.x = -1.0;
|
||||
}
|
||||
|
||||
if (v.y >= 0.0) {
|
||||
a.y = 1.0;
|
||||
}
|
||||
else {
|
||||
a.y = -1.0;
|
||||
}
|
||||
|
||||
var r: float2;
|
||||
r.x = abs(v.y);
|
||||
r.y = abs(v.x);
|
||||
r.x = 1.0 - r.x;
|
||||
r.y = 1.0 - r.y;
|
||||
return r * a;
|
||||
|
||||
// return (1.0 - abs(v.yx)) * (float2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0));
|
||||
}
|
||||
|
||||
fun pack_f32_i16(f: float, i: uint): float {
|
||||
// GBuffer helper - Sebastien Lagarde
|
||||
// https://seblagarde.wordpress.com/2018/09/02/gbuffer-helper-packing-integer-and-float-together/
|
||||
// const num_bit_target: int = 16;
|
||||
// const num_bit_i: int = 4;
|
||||
// const prec: float = float(1 << num_bit_target);
|
||||
// const maxi: float = float(1 << num_bit_i);
|
||||
// const prec_minus_one: float = prec - 1.0;
|
||||
// const t1: float = ((prec / maxi) - 1.0) / prec_minus_one;
|
||||
// const t2: float = (prec / maxi) / prec_minus_one;
|
||||
// return t1 * f + t2 * float(i);
|
||||
return 0.062504762 * f + 0.062519999 * float(i);
|
||||
}
|
||||
|
||||
fun mesh_posnor_frag(input: vert_out): float4[2] {
|
||||
var basecol: float3 = float3(0.8, 0.8, 0.8);
|
||||
var roughness: float = 0.25;
|
||||
var metallic: float = 0.0;
|
||||
var occlusion: float = 1.0;
|
||||
var n: float3 = normalize(input.wnormal);
|
||||
n /= abs(n.x) + abs(n.y) + abs(n.z);
|
||||
if (n.z >= 0.0) {
|
||||
n.xy = n.xy;
|
||||
}
|
||||
else {
|
||||
n.xy = octahedron_wrap(n.xy);
|
||||
}
|
||||
var matid: uint = 0;
|
||||
var color: float4[2];
|
||||
color[0].rgba = float4(n.xy, roughness, pack_f32_i16(metallic, matid));
|
||||
color[1].rgba = float4(basecol, occlusion);
|
||||
return color;
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = mesh_posnor_vert;
|
||||
fragment = mesh_posnor_frag;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform mat3 N;
|
||||
uniform mat4 WVP;
|
||||
uniform mat4 prevWVP;
|
||||
|
||||
in vec4 pos;
|
||||
in vec2 nor;
|
||||
out vec3 wnormal;
|
||||
out vec4 wvpposition;
|
||||
out vec4 prevwvpposition;
|
||||
|
||||
void main() {
|
||||
vec4 spos = vec4(pos.xyz, 1.0);
|
||||
wnormal = normalize(mul(vec3(nor.xy, pos.w), N));
|
||||
gl_Position = mul(spos, WVP);
|
||||
wvpposition = gl_Position;
|
||||
prevwvpposition = mul(spos, prevWVP);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#version 450
|
||||
|
||||
#include "std/gbuffer.glsl"
|
||||
|
||||
in vec2 tex_coord;
|
||||
in vec3 wnormal;
|
||||
in vec4 wvpposition;
|
||||
in vec4 prevwvpposition;
|
||||
out vec4 frag_color[3];
|
||||
|
||||
void main() {
|
||||
vec3 n = normalize(wnormal);
|
||||
vec3 basecol = vec3(0.2, 0.2, 0.2) + tex_coord.x * 0.0000001; // keep tex_coord
|
||||
float roughness = 0.4;
|
||||
float metallic = 0.0;
|
||||
float occlusion = 1.0;
|
||||
n /= (abs(n.x) + abs(n.y) + abs(n.z));
|
||||
n.xy = n.z >= 0.0 ? n.xy : octahedron_wrap(n.xy);
|
||||
uint matid = uint(0);
|
||||
frag_color[0] = vec4(n.xy, roughness, pack_f32_i16(metallic, matid));
|
||||
frag_color[1] = vec4(basecol, occlusion);
|
||||
vec2 posa = (wvpposition.xy / wvpposition.w) * 0.5 + 0.5;
|
||||
vec2 posb = (prevwvpposition.xy / prevwvpposition.w) * 0.5 + 0.5;
|
||||
frag_color[2].rg = vec2(posa - posb);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
|
||||
#[set(everything)]
|
||||
const constants: {
|
||||
N: float3x3;
|
||||
WVP: float4x4;
|
||||
tex_unpack: float;
|
||||
};
|
||||
|
||||
struct vert_in {
|
||||
pos: float4;
|
||||
nor: float2;
|
||||
tex: float2;
|
||||
}
|
||||
|
||||
struct vert_out {
|
||||
pos: float4;
|
||||
tex: float2;
|
||||
wnormal: float3;
|
||||
}
|
||||
|
||||
fun mesh_posnortex_vert(input: vert_in): vert_out {
|
||||
var output: vert_out;
|
||||
output.pos = constants.WVP * float4(input.pos.xyz, 1.0);
|
||||
output.tex = input.tex * constants.tex_unpack;
|
||||
output.wnormal = normalize(constants.N * float3(input.nor.xy, input.pos.w));
|
||||
return output;
|
||||
}
|
||||
|
||||
fun octahedron_wrap(v: float2): float2 {
|
||||
var a: float2;
|
||||
if (v.x >= 0.0) {
|
||||
a.x = 1.0;
|
||||
}
|
||||
else {
|
||||
a.x = -1.0;
|
||||
}
|
||||
|
||||
if (v.y >= 0.0) {
|
||||
a.y = 1.0;
|
||||
}
|
||||
else {
|
||||
a.y = -1.0;
|
||||
}
|
||||
|
||||
var r: float2;
|
||||
r.x = abs(v.y);
|
||||
r.y = abs(v.x);
|
||||
r.x = 1.0 - r.x;
|
||||
r.y = 1.0 - r.y;
|
||||
return r * a;
|
||||
|
||||
// return (1.0 - abs(v.yx)) * (float2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0));
|
||||
}
|
||||
|
||||
fun pack_f32_i16(f: float, i: uint): float {
|
||||
// GBuffer helper - Sebastien Lagarde
|
||||
// https://seblagarde.wordpress.com/2018/09/02/gbuffer-helper-packing-integer-and-float-together/
|
||||
// const num_bit_target: int = 16;
|
||||
// const num_bit_i: int = 4;
|
||||
// const prec: float = float(1 << num_bit_target);
|
||||
// const maxi: float = float(1 << num_bit_i);
|
||||
// const prec_minus_one: float = prec - 1.0;
|
||||
// const t1: float = ((prec / maxi) - 1.0) / prec_minus_one;
|
||||
// const t2: float = (prec / maxi) / prec_minus_one;
|
||||
// return t1 * f + t2 * float(i);
|
||||
return 0.062504762 * f + 0.062519999 * float(i);
|
||||
}
|
||||
|
||||
fun mesh_posnortex_frag(input: vert_out): float4[2] {
|
||||
var n: float3 = normalize(input.wnormal);
|
||||
var basecol: float3 = float3(0.2, 0.2, 0.2) + input.tex.x * 0.0000001; // keep tex_coord
|
||||
var roughness: float = 0.4;
|
||||
var metallic: float = 0.0;
|
||||
var occlusion: float = 1.0;
|
||||
|
||||
n /= abs(n.x) + abs(n.y) + abs(n.z);
|
||||
if (n.z >= 0.0) {
|
||||
n.xy = n.xy;
|
||||
}
|
||||
else {
|
||||
n.xy = octahedron_wrap(n.xy);
|
||||
}
|
||||
|
||||
var matid: uint = 0;
|
||||
var color: float4[2];
|
||||
color[0].rgba = float4(n.xy, roughness, pack_f32_i16(metallic, matid));
|
||||
color[1].rgba = float4(basecol, occlusion);
|
||||
return color;
|
||||
}
|
||||
|
||||
#[pipe]
|
||||
struct pipe {
|
||||
vertex = mesh_posnortex_vert;
|
||||
fragment = mesh_posnortex_frag;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#version 450
|
||||
|
||||
uniform mat3 N;
|
||||
uniform mat4 WVP;
|
||||
uniform float tex_unpack;
|
||||
uniform mat4 prevWVP;
|
||||
|
||||
in vec4 pos;
|
||||
in vec2 nor;
|
||||
in vec2 tex;
|
||||
out vec2 tex_coord;
|
||||
out vec3 wnormal;
|
||||
out vec4 wvpposition;
|
||||
out vec4 prevwvpposition;
|
||||
|
||||
void main() {
|
||||
vec4 spos = vec4(pos.xyz, 1.0);
|
||||
tex_coord = tex * tex_unpack;
|
||||
wnormal = normalize(mul(vec3(nor.xy, pos.w), N));
|
||||
gl_Position = mul(spos, WVP);
|
||||
wvpposition = gl_Position;
|
||||
prevwvpposition = mul(spos, prevWVP);
|
||||
}
|
||||
Reference in New Issue
Block a user