Skip to content

Commit

Permalink
Global illumination and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMoroz committed Jan 12, 2020
1 parent ea316bd commit 0914a21
Show file tree
Hide file tree
Showing 45 changed files with 2,715 additions and 122 deletions.
18 changes: 9 additions & 9 deletions game_folder/shaders/compute/MAIN.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
####################################################
#shader name
multires_marching/MRRM1.glsl
#global size
#global work-group number
width/(8*MRRM_scale)
height/(8*MRRM_scale)
#texture resolution
Expand All @@ -16,7 +16,7 @@ height/MRRM_scale
####################################################
#shader name
multires_marching/MRRM2.glsl
#global size
#global work-group number
width/8
height/8
#texture resolution
Expand All @@ -27,18 +27,18 @@ height
####################################################
#shader name #half res shadows and AO
main/Illumination_step.glsl
#global size
#global work-group number
width/(shadow_scale*8)
height/(shadow_scale*8)
#texture resolution
width/shadow_scale
height/shadow_scale
#output texture number
1
2
####################################################
#shader name
main/Shading_step.glsl
#global size
#global work-group number
width/8
height/8
#texture resolution
Expand All @@ -49,7 +49,7 @@ height
####################################################
#shader name
post_processing/downsampling.glsl
#global size
#global work-group number
width/(8*bloom_scale)
height/(8*bloom_scale)
#texture resolution
Expand All @@ -60,7 +60,7 @@ height/bloom_scale
####################################################
#shader name
post_processing/Bloom_horiz.glsl
#global size
#global work-group number
width/(bloom_scale*128)
height/bloom_scale
#texture resolution
Expand All @@ -71,7 +71,7 @@ height/bloom_scale
####################################################
#shader name
post_processing/Bloom_vertic.glsl
#global size
#global work-group number
width/bloom_scale
height/(bloom_scale*128)
#texture resolution
Expand All @@ -82,7 +82,7 @@ height/bloom_scale
####################################################
#shader name
main/Final_step.glsl
#global size
#global work-group number
width/8
height/8
#texture resolution
Expand Down
2 changes: 1 addition & 1 deletion game_folder/shaders/compute/ORIGINAL.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ height/(shadow_scale*8)
width/shadow_scale
height/shadow_scale
#output texture number
1
2
####################################################
#shader name
original/original_shading.glsl
Expand Down
4 changes: 2 additions & 2 deletions game_folder/shaders/compute/main/Final_step.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ shared vec4 de_sph[1][1];
#include<utility/camera.glsl>
#include<utility/shading.glsl>

#define DOF_samples 60
#define DOF_samples 50
#define DOF

#define RA 5.
#define RA 3.5
const float GA = 2.399;
const mat2 rot = mat2(cos(GA),sin(GA),-sin(GA),cos(GA));

Expand Down
33 changes: 19 additions & 14 deletions game_folder/shaders/compute/main/Illumination_step.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
#define block_size 64

layout(local_size_x = group_size, local_size_y = group_size) in;
layout(rgba32f, binding = 0) uniform image2D illumination;
layout(rgba32f, binding = 1) uniform image2D DE_input;
layout(rgba32f, binding = 2) uniform image2D color_HDR; //calculate final color
layout(rgba32f, binding = 0) uniform image2D illuminationDirect;
layout(rgba32f, binding = 1) uniform image2D illuminationGI;
layout(rgba32f, binding = 2) uniform image2D DE_input;
layout(rgba32f, binding = 3) uniform image2D color_HDR; //calculate final color

//make all the local distance estimator spheres shared
shared vec4 de_sph[group_size][group_size];

#include<utility/camera.glsl>
#include<utility/shading.glsl>

///Half-resolution illumination step

///Low-resolution illumination step

void main() {

ivec2 global_pos = ivec2(gl_GlobalInvocationID.xy);
ivec2 local_indx = ivec2(gl_LocalInvocationID.xy);

vec2 img_size = vec2(imageSize(illumination));
vec2 img_size = vec2(imageSize(illuminationDirect));
vec2 pimg_size = vec2(imageSize(DE_input));
vec2 step_scale = img_size/pimg_size;

Expand All @@ -38,17 +38,22 @@ void main() {
pos = sph;
dir.w += td;

vec4 illum = vec4(0);
vec4 illumDIR = vec4(0);
vec4 illumGI = vec4(1.);

if(pos.w < max(2*fovray*td, MIN_DIST) && SHADOWS_ENABLED)
{
pos.xyz += (DE(pos.xyz) - 2.*fovray*td/step_scale.x)*dir.xyz;
pos.xyz += (DE(pos.xyz) - 2.*fovray*td/step_scale.x)*dir.xyz;
pos.xyz += (DE(pos.xyz) - 2.*fovray*td/step_scale.x)*dir.xyz;
illum.x = shadow_march(pos, normalize(vec4(LIGHT_DIRECTION,0)), MAX_DIST, LIGHT_ANGLE);
//marching towards a point at a distance = to the pixel cone radius from the object
float pix_cone_rad = 2.*fovray*td/step_scale.x;
pos.xyz += (DE(pos.xyz) - pix_cone_rad)*dir.xyz;
pos.xyz += (DE(pos.xyz) - pix_cone_rad)*dir.xyz;
pos.xyz += (DE(pos.xyz) - pix_cone_rad)*dir.xyz;

//illum.y = ambient_occlusion(pos, norm);
illumDIR.xyz = sky_color(LIGHT_DIRECTION)*shadow_march(pos, normalize(vec4(LIGHT_DIRECTION,0)), MAX_DIST, LIGHT_ANGLE);
}
illum.w = td;
imageStore(illumination, global_pos, illum);
illumDIR.w = td;
illumGI.w = td;

imageStore(illuminationDirect, global_pos, illumDIR);
imageStore(illuminationGI, global_pos, illumGI);
}
62 changes: 62 additions & 0 deletions game_folder/shaders/compute/main/Illumination_step_GI.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#version 430
#define group_size 8
#define block_size 64

layout(local_size_x = group_size, local_size_y = group_size) in;
layout(rgba32f, binding = 0) uniform image2D global_illum;
layout(rgba32f, binding = 1) uniform image2D illuminationDirect;
layout(rgba32f, binding = 2) uniform image2D illuminationGI;
layout(rgba32f, binding = 3) uniform image2D DE_input;
layout(rgba32f, binding = 4) uniform image2D color_HDR; //calculate final color

//make all the local distance estimator spheres shared
shared vec4 de_sph[group_size][group_size];

#include<utility/camera.glsl>
#include<utility/shading.glsl>

///Low-resolution illumination step

void main() {

ivec2 global_pos = ivec2(gl_GlobalInvocationID.xy);
ivec2 local_indx = ivec2(gl_LocalInvocationID.xy);

vec2 img_size = vec2(imageSize(illuminationDirect));
vec2 pimg_size = vec2(imageSize(DE_input));
float GIscale = (vec2(imageSize(global_illum)) / img_size).x;
vec2 step_scale = img_size/pimg_size;

ivec2 prev_pos = min(ivec2((vec2(global_pos)/step_scale) + 0.5),ivec2(pimg_size)-1);

ray rr = get_ray(vec2(global_pos)/img_size);
vec4 pos = vec4(rr.pos,0);
vec4 dir = vec4(rr.dir,0);
vec4 var = vec4(0);

vec4 sph = imageLoad(DE_input, prev_pos);
float td = dot(dir.xyz, sph.xyz - pos.xyz);//traveled distance

pos = sph;
dir.w += td;

vec4 illumDIR = vec4(0);
vec4 illumGI = vec4(0);

if(pos.w < max(2*fovray*td, MIN_DIST) && SHADOWS_ENABLED)
{
//marching towards a point at a distance = to the pixel cone radius from the object
float pix_cone_rad = 2.*fovray*td/step_scale.x;
pos.xyz += (DE(pos.xyz) - pix_cone_rad)*dir.xyz;
pos.xyz += (DE(pos.xyz) - pix_cone_rad)*dir.xyz;
pos.xyz += (DE(pos.xyz) - pix_cone_rad)*dir.xyz;

illumGI = bilinear_surface(global_illum, td, GIscale, vec2(global_pos)*GIscale);
illumDIR.xyz = sky_color(LIGHT_DIRECTION)*shadow_march(pos, normalize(vec4(LIGHT_DIRECTION,0)), MAX_DIST, LIGHT_ANGLE);
}
illumDIR.w = td;
illumGI.w = td;

imageStore(illuminationDirect, global_pos, illumDIR);
imageStore(illuminationGI, global_pos, illumGI);
}
16 changes: 9 additions & 7 deletions game_folder/shaders/compute/main/Shading_step.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#define block_size 64

layout(local_size_x = group_size, local_size_y = group_size) in;
layout(rgba32f, binding = 0) uniform image2D illumination; //shadows
layout(rgba32f, binding = 1) uniform image2D color_output;
layout(rgba32f, binding = 2) uniform image2D DE_input;
layout(rgba32f, binding = 3) uniform image2D color_HDR; //calculate final color
layout(rgba32f, binding = 0) uniform image2D illuminationDirect;
layout(rgba32f, binding = 1) uniform image2D illuminationGI;
layout(rgba32f, binding = 2) uniform image2D color_output;
layout(rgba32f, binding = 3) uniform image2D DE_input;
layout(rgba32f, binding = 4) uniform image2D color_HDR; //calculate final color


//make all the local distance estimator spheres shared
Expand All @@ -20,7 +21,7 @@ void main() {
ivec2 global_pos = ivec2(gl_GlobalInvocationID.xy);
ivec2 local_indx = ivec2(gl_LocalInvocationID.xy);
vec2 img_size = vec2(imageSize(color_HDR));
float res_ratio = imageSize(illumination).x/img_size.x;
float res_ratio = imageSize(illuminationDirect).x/img_size.x;
vec4 sph = imageLoad(DE_input, global_pos);


Expand All @@ -31,12 +32,13 @@ void main() {

float td = dot(dir.xyz, sph.xyz - pos.xyz);//traveled distance

vec4 illum = bilinear_surface(illumination, td, 3*td*fovray/res_ratio, vec2(global_pos)*res_ratio);
vec4 illumDIR = bilinear_surface(illuminationDirect, td, 3*td*fovray/res_ratio, vec2(global_pos)*res_ratio);
vec4 illumGI = bilinear_surface(illuminationGI, td, 3*td*fovray/res_ratio, vec2(global_pos)*res_ratio);
//vec4 illum = interp(illumination, vec2(global_pos)*res_ratio);
pos = sph;
dir.w += td;

vec3 color = shading(pos, dir, fovray, illum.x);
vec3 color = shading(pos, dir, fovray, illumDIR.xyz, illumGI.xyz);
//color = vec3(illum.x);
vec3 prev_color = imageLoad(color_HDR, global_pos).xyz;
if(!isnan(color.x) && !isnan(color.y) && !isnan(color.z))
Expand Down
26 changes: 15 additions & 11 deletions game_folder/shaders/compute/main/global_illumination_step.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#define block_size 64

layout(local_size_x = group_size, local_size_y = group_size) in;
layout(rgba32f, binding = 0) uniform image2D DE_input;
layout(rgba32f, binding = 1) uniform image2D color_HDR; //calculate final color
layout(rgba32f, binding = 2) uniform image2D illumination;
layout(rgba32f, binding = 0) uniform image2D global_illum;
layout(rgba32f, binding = 1) uniform image2D normals;
layout(rgba32f, binding = 2) uniform image2D DE_input;
layout(rgba32f, binding = 3) uniform image2D color_HDR; //calculate final color

//make all the local distance estimator spheres shared
shared vec4 de_sph[group_size][group_size];
Expand All @@ -20,7 +21,7 @@ void main() {
ivec2 global_pos = ivec2(gl_GlobalInvocationID.xy);
ivec2 local_indx = ivec2(gl_LocalInvocationID.xy);

vec2 img_size = vec2(imageSize(illumination));
vec2 img_size = vec2(imageSize(global_illum));
vec2 pimg_size = vec2(imageSize(DE_input));
vec2 step_scale = img_size/pimg_size;

Expand All @@ -38,15 +39,18 @@ void main() {
dir.w += td;

vec4 illum = vec4(0);

vec4 norm = vec4(1,0,0,0);
if(pos.w < max(2*fovray*td, MIN_DIST) && SHADOWS_ENABLED)
{
pos.xyz += (DE(pos.xyz) - 2.*fovray*td/step_scale.x)*dir.xyz;
pos.xyz += (DE(pos.xyz) - 2.*fovray*td/step_scale.x)*dir.xyz;
pos.xyz += (DE(pos.xyz) - 2.*fovray*td/step_scale.x)*dir.xyz;

illum.xyz = ambient_light(pos);
//marching towards a point at a distance = to the pixel cone radius from the object
float pix_cone_rad = 10.*fovray*td/step_scale.x;
pos.xyz += (DE(pos.xyz) - pix_cone_rad)*dir.xyz;
pos.xyz += (DE(pos.xyz) - pix_cone_rad)*dir.xyz;
pos.xyz += (DE(pos.xyz) - pix_cone_rad)*dir.xyz;
norm = calcNormal(pos.xyz, 0.1*pix_cone_rad);
illum.xyz = ambient_light(pos.xyz, pix_cone_rad);
}
illum.w = td;
imageStore(illumination, global_pos, illum);
imageStore(global_illum, global_pos, illum);
imageStore(normals, global_pos, norm);
}
Loading

0 comments on commit 0914a21

Please sign in to comment.