Vulkan fixes
This commit is contained in:
@@ -143,16 +143,16 @@ fun sh_irradiance(nor: float3): float3 {
|
||||
var cl21: float3 = float3(constants.shirr5.y, constants.shirr5.z, constants.shirr5.w);
|
||||
var cl22: float3 = float3(constants.shirr6.x, constants.shirr6.y, constants.shirr6.z);
|
||||
return (
|
||||
c1 * cl22 * (nor.y * nor.y - (-nor.z) * (-nor.z)) +
|
||||
c3 * cl20 * nor.x * nor.x +
|
||||
c4 * cl00 -
|
||||
c5 * cl20 +
|
||||
2.0 * c1 * cl2m2 * nor.y * (-nor.z) +
|
||||
2.0 * c1 * cl21 * nor.y * nor.x +
|
||||
2.0 * c1 * cl2m1 * (-nor.z) * nor.x +
|
||||
2.0 * c2 * cl11 * nor.y +
|
||||
2.0 * c2 * cl1m1 * (-nor.z) +
|
||||
2.0 * c2 * cl10 * nor.x
|
||||
cl22 * c1 * (nor.y * nor.y - (-nor.z) * (-nor.z)) +
|
||||
cl20 * c3 * nor.x * nor.x +
|
||||
cl00 * c4 -
|
||||
cl20 * c5 +
|
||||
cl2m2 * 2.0 * c1 * nor.y * (-nor.z) +
|
||||
cl21 * 2.0 * c1 * nor.y * nor.x +
|
||||
cl2m1 * 2.0 * c1 * (-nor.z) * nor.x +
|
||||
cl11 * 2.0 * c2 * nor.y +
|
||||
cl1m1 * 2.0 * c2 * (-nor.z) +
|
||||
cl10 * 2.0 * c2 * nor.x
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,7 +208,8 @@ fun deferred_light_frag(input: vert_out): float4 {
|
||||
n.z
|
||||
)
|
||||
);
|
||||
envl /= PI;
|
||||
// envl /= PI;
|
||||
envl = envl / PI;
|
||||
|
||||
var reflection_world: float3 = reflect(-v, n);
|
||||
var lod: float = mip_from_roughness(roughness, float(constants.envmap_num_mipmaps));
|
||||
@@ -217,16 +218,20 @@ fun deferred_light_frag(input: vert_out): float4 {
|
||||
envl.rgb = envl.rgb * albedo;
|
||||
// Indirect specular
|
||||
// var env_brdf: float2 = senvmap_brdf[uint2(roughness * 256.0, (1.0 - dotnv) * 256.0)].xy;
|
||||
var env_brdf: float4 = senvmap_brdf[uint2(roughness * 256.0, (1.0 - dotnv) * 256.0)];
|
||||
envl.rgb += prefiltered_color * (f0 * env_brdf.x + env_brdf.y) * 1.5;
|
||||
var env_brdf: float4 = senvmap_brdf[uint2(uint(roughness * 256.0), uint((1.0 - dotnv) * 256.0))];
|
||||
|
||||
//envl.rgb += prefiltered_color * (f0 * env_brdf.x + env_brdf.y) * 1.5;
|
||||
envl.rgb = envl.rgb + (prefiltered_color * (f0 * env_brdf.x + env_brdf.y) * 1.5);
|
||||
envl.rgb *= constants.envmap_data.w * occ;
|
||||
|
||||
var color: float4;
|
||||
color.rgb = envl;
|
||||
color.rgb = envl.rgb;
|
||||
color.rgb = color.rgb * sample_lod(ssaotex, sampler_linear, input.tex, 0.0).r;
|
||||
|
||||
if (matid == uint(1)) { // Emission
|
||||
color.rgb += g1.rgb; // materialid
|
||||
// if (matid == uint(1)) { // Emission
|
||||
if (matid == uint(1.0)) { // Emission
|
||||
//color.rgb += g1.rgb; // materialid
|
||||
color.rgb = color.rgb + g1.rgb; // materialid
|
||||
albedo = float3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,14 +68,16 @@ fun mesh_posnor_frag(input: vert_out): float4[2] {
|
||||
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);
|
||||
// n /= abs(n.x) + abs(n.y) + abs(n.z);
|
||||
n = 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 matid: uint = 0;
|
||||
var matid: uint = uint(0.0);
|
||||
var color: float4[2];
|
||||
color[0] = float4(n.xy, roughness, pack_f32_i16(metallic, matid));
|
||||
color[1] = float4(basecol, occlusion);
|
||||
|
||||
@@ -73,7 +73,8 @@ fun mesh_posnortex_frag(input: vert_out): float4[2] {
|
||||
var metallic: float = 0.0;
|
||||
var occlusion: float = 1.0;
|
||||
|
||||
n /= abs(n.x) + abs(n.y) + abs(n.z);
|
||||
// n /= abs(n.x) + abs(n.y) + abs(n.z);
|
||||
n = (n / abs(n.x) + abs(n.y) + abs(n.z));
|
||||
if (n.z >= 0.0) {
|
||||
n.xy = n.xy;
|
||||
}
|
||||
@@ -81,7 +82,8 @@ fun mesh_posnortex_frag(input: vert_out): float4[2] {
|
||||
n.xy = octahedron_wrap(n.xy);
|
||||
}
|
||||
|
||||
var matid: uint = 0;
|
||||
// var matid: uint = 0;
|
||||
var matid: uint = uint(0.0);
|
||||
var color: float4[2];
|
||||
color[0] = float4(n.xy, roughness, pack_f32_i16(metallic, matid));
|
||||
color[1] = float4(basecol, occlusion);
|
||||
|
||||
@@ -13,7 +13,7 @@ const radiance: tex2d;
|
||||
const PI: float = 3.14159265358979;
|
||||
const PI2: float = 6.28318530718;
|
||||
// #ifdef METAL
|
||||
// const samples = 1024 * 2; // Prevent gpu hang
|
||||
// const samples: float = 1024 * 2; // Prevent gpu hang
|
||||
// #else
|
||||
// const samples: float = 1024 * 16;
|
||||
const samples: float = 16384;
|
||||
@@ -61,18 +61,25 @@ fun cos_weighted_hemisphere_direction(n: float3, co: float2, seed: float): float
|
||||
var rx: float = ra * cos(PI2 * r.x);
|
||||
var ry: float = ra * sin(PI2 * r.x);
|
||||
var rz: float = sqrt(1.0 - r.y);
|
||||
var rr: float3 = float3(rx * uu + ry * vv + rz * n);
|
||||
var rr: float3 = rx * uu + ry * vv + rz * n;
|
||||
return normalize(rr);
|
||||
}
|
||||
|
||||
fun prefilter_envmap_frag(input: vert_out): float4 {
|
||||
var color: float4 = float4(0.0, 0.0, 0.0, 1.0);
|
||||
var n: float3 = reverse_equirect(input.tex);
|
||||
for (var i: uint = 0; i < samples; i += 1) {
|
||||
var dir: float3 = normalize(lerp3(n, cos_weighted_hemisphere_direction(n, input.tex, i), constants.params.x));
|
||||
color.rgb += sample(radiance, sampler_linear, equirect(dir)).rgb;
|
||||
|
||||
//for (var i: int = 0; i < int(samples); i += 1) {
|
||||
var i: int = 0;
|
||||
while (i < int(samples)) {
|
||||
var dir: float3 = normalize(lerp3(n, cos_weighted_hemisphere_direction(n, input.tex, float(i)), constants.params.x));
|
||||
color.rgb = color.rgb + sample(radiance, sampler_linear, equirect(dir)).rgb;
|
||||
|
||||
//
|
||||
i += 1;
|
||||
//
|
||||
}
|
||||
color.rgb /= float(samples);
|
||||
color.rgb = color.rgb / samples;
|
||||
// color.rgb = pow(color.rgb, float3(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);
|
||||
|
||||
@@ -82,7 +82,9 @@ fun ssao_blur_pass_frag(input: vert_out): float {
|
||||
var weight: float = 0.132572;
|
||||
var color: float = sample_lod(tex, sampler_linear, input.tex, 0.0).r * weight;
|
||||
|
||||
for (var i: int = 1; i < 8; i += 1) {
|
||||
//for (var i: int = 1; i < 8; i += 1) {
|
||||
var i: int = 1;
|
||||
while (i < 8) {
|
||||
|
||||
var blur_weight_i: float; // = blur_weights[i];
|
||||
if (i == 1) {
|
||||
@@ -123,6 +125,10 @@ fun ssao_blur_pass_frag(input: vert_out): float {
|
||||
w = blur_weight_i * influence_factor;
|
||||
color += col * w;
|
||||
weight += w;
|
||||
|
||||
//
|
||||
i += 1;
|
||||
//
|
||||
}
|
||||
|
||||
color = color / weight;
|
||||
|
||||
@@ -68,7 +68,10 @@ fun ray_cast(view_ray: float3, dir: float3, vpos: float3): float {
|
||||
dir = dir * ray_step;
|
||||
var hit_coord: float3 = vpos;
|
||||
var dist: float = 0.15;
|
||||
for (var i: int = 0; i < max_steps; i = i + 1) {
|
||||
|
||||
// for (var i: int = 0; i < max_steps; i = i + 1) {
|
||||
var i: int = 0;
|
||||
while (i < max_steps) {
|
||||
hit_coord += dir;
|
||||
var delta: float = get_delta_depth(view_ray, hit_coord);
|
||||
if (delta > 0.0 && delta < 0.2) {
|
||||
@@ -76,6 +79,10 @@ fun ray_cast(view_ray: float3, dir: float3, vpos: float3): float {
|
||||
// break;
|
||||
return dist;
|
||||
}
|
||||
|
||||
//
|
||||
i += 1;
|
||||
//
|
||||
}
|
||||
return dist;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user