Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #78

Merged
merged 20 commits into from
Sep 28, 2024
Merged

Dev #78

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ jobs:
- name: Create zip file
run: |
cd build/windows
zip -r gknextrenderer_win64_${{ github.ref_name }}.zip ./bin ./assets/locale ./assets/fonts ./assets/models ./assets/shaders ./assets/textures
copy /Y ..\..\package\*.bat .\
zip -r gknextrenderer_win64_${{ github.ref_name }}.zip ./bin ./assets/locale ./assets/fonts ./assets/models ./assets/shaders ./assets/textures ./*.bat
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
Expand Down
Binary file added assets/fonts/DroidSansFallback.ttf
Binary file not shown.
Binary file removed assets/fonts/MicrosoftYaHeiMono.ttf
Binary file not shown.
22 changes: 16 additions & 6 deletions assets/shaders/Accumulate.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#extension GL_GOOGLE_include_directive : require
#include "Platform.glsl"
#include "common/UniformBufferObject.glsl"
#include "common/Const_Func.glsl"
#include "common/Random.glsl"

layout(binding = 0, rgba16f) uniform image2D NewSourceImage;
layout(binding = 1, rgba16f) uniform image2D AccumulateImage;
Expand All @@ -13,7 +13,6 @@ layout(binding = 4) readonly uniform UniformBufferObjectStruct { UniformBufferOb
layout(binding = 5, r32ui) uniform uimage2D VisibilityBuffer;
layout(binding = 6, r32ui) uniform uimage2D Visibility1Buffer;
layout(binding = 7, rgba8) uniform image2D OutImage;
layout(binding = 8, r8ui) uniform uimage2D AdaptiveSampleBuffer;

layout(local_size_x = 8, local_size_y = 4, local_size_z = 1) in;

Expand Down Expand Up @@ -89,20 +88,31 @@ void main() {
subpixel.y
);

history = max(vec4(0.0), history);
// judge current gbuffer / object id with prev frame, to deghosting
float currKeep = src.w / max(1, Camera.TemporalFrames);
final = mix(history, src, currKeep);


// 这里我们希望评估的是噪点密集的区域,就是肉眼看上去十分闪烁的区域
// 应该类似SVGF一样,评估时间,空间域内的方差
// 然后,这个评估,也可以用于降噪,这种区域,应该提升降噪强度。
// 最终的结果,类似于,采样数严重不足的区域,自适应的提升采样数,并拉高后续的降噪强度
// 而比如光线充足的大平面,采样数足够,后续也可以适当降低降噪强度
// 我们先输出一个区域的图给到visualdebug
if(Camera.AdaptiveSample)
{
// 之前的算法是不稳定,抖动的。使用 delta ^ 2 = prev - cur ^ 2 来预估

// 将方差直接写入buffer,显示一下,他应该是稳定的

// if history variance is too large, we should not use it.
const float historyVariance = Camera.AdaptiveVariance;

float diff = abs(luminance(final.rgb) - luminance(history.rgb));
float diff = abs(luminance(src.rgb) - luminance(history.rgb));
if (diff > historyVariance)
{
// need sample
imageStore(AdaptiveSampleBuffer, ipos, uvec4(Camera.AdaptiveSteps));
//imageStore(AdaptiveSampleBuffer, ipos, uvec4(Camera.AdaptiveSteps));
}
}
}
Expand All @@ -122,7 +132,7 @@ void main() {
{
if( EdgeDetect(current_primitive_index, isEvenFrame, ipos ) )
{
final.rgb = vec3(1,0.05,0) * Camera.PaperWhiteNit;
//final.rgb = vec3(1,0.05,0) * Camera.PaperWhiteNit;
}
}

Expand Down
167 changes: 0 additions & 167 deletions assets/shaders/Denoise.comp

This file was deleted.

73 changes: 68 additions & 5 deletions assets/shaders/FinalCompose.comp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,82 @@ layout(binding = 0, rgba16f) uniform image2D InImage;
layout(binding = 1, rgba8) uniform image2D OutImage;
layout(binding = 2) readonly uniform UniformBufferObjectStruct { UniformBufferObject Camera; };

// use for jbf
layout(binding = 3, rgba16f) uniform image2D InAlbedo;
layout(binding = 4, rgba16f) uniform image2D InNormal;
layout(binding = 5, r32ui) uniform uimage2D InVisibility0;
layout(binding = 6, r32ui) uniform uimage2D InVisibility1;

layout(local_size_x = 8, local_size_y = 4, local_size_z = 1) in;

void main() {
ivec2 ipos = ivec2(gl_GlobalInvocationID.xy) + ivec2(Camera.ViewportRect.x, Camera.ViewportRect.y);

const ivec2 ipos = ivec2(gl_GlobalInvocationID.xy) + ivec2(Camera.ViewportRect.x, Camera.ViewportRect.y);
bool isEvenFrame = Camera.TotalFrames % 2 == 0;

vec3 Total = vec3(0);

if(Camera.BFSize > 0)
{
// simple joint bilateral filter
const int N = int(Camera.BFSize); // filter size
const float sigma = Camera.BFSigma; // spatial sigma
const float sigmaL = Camera.BFSigmaLum * 100.0; //
const float sigmaN = Camera.BFSigmaNormal;
const int SX = 1; // spatial step
const int SY = 1; // spatial step

const vec3 CenterColor = imageLoad(InImage, ipos).rgb;
const vec3 CenterAlbedo = imageLoad(InAlbedo, ipos).rgb + vec3(0.001,0.001,0.001);
const vec3 DemodulateColor = CenterColor / CenterAlbedo;

const vec3 Normal = imageLoad(InNormal, ipos).rgb;
uint current_primitive_index = isEvenFrame ? imageLoad(InVisibility0, ipos).r : imageLoad(InVisibility1, ipos).r;

const float CenterLum = dot(DemodulateColor, vec3(0.212671F, 0.715160F, 0.072169F));

float Weight = 0;

int c,d;
for(c=-N;c<N+1;c++)
{
for(d=-N;d<N+1;d++)
{
const vec3 Ci = imageLoad(InImage, ipos + ivec2(c*SX,d*SY)).rgb / (imageLoad(InAlbedo, ipos + ivec2(c*SX,d*SY)).rgb + vec3(0.001,0.001,0.001));

const vec3 Ni = imageLoad(InNormal, ipos + ivec2(c*SX,d*SY)).rgb;
const uint Pi = isEvenFrame ? imageLoad(InVisibility0, ipos + ivec2(c*SX,d*SY)).r : imageLoad(InVisibility1, ipos + ivec2(c*SX,d*SY)).r;
const float lumi = dot((Ci), vec3(0.212671F, 0.715160F, 0.072169F));


const float dist = clamp( float(c*c+d*d)/float(N*N) , 0., 1. );
const float normaldist = 1.0 - dot(Ni, Normal);
const float dlum = (CenterLum - lumi)*(CenterLum - lumi);

const float Fi = exp(-dist*dist/(2.* sigma*sigma));
const float Ai = exp(-normaldist*normaldist/(2.* sigmaN*sigmaN));
const float Li = exp(-dlum*dlum/(2.* sigmaL*sigmaL));
const float Oi = float(current_primitive_index == Pi);

Total += Ci * Fi * Li * Ai * Oi;
Weight += Fi * Li * Ai * Oi;
}
}
Total /= Weight;

Total = Total * CenterAlbedo;
}
else
{
Total = imageLoad(InImage, ipos).rgb;
}

if(Camera.HDR)
{
imageStore(OutImage, ipos, vec4( LinearToST2084UE( imageLoad(InImage, ipos).rgb * Camera.PaperWhiteNit / 230.0), 1.0));
imageStore(OutImage, ipos, vec4( LinearToST2084UE( Total * Camera.PaperWhiteNit / 230.0), 1.0));
}
else
{
// manmal exposure
imageStore(OutImage, ipos, vec4( ACES_Tonemapping( imageLoad(InImage, ipos).rgb * Camera.PaperWhiteNit / 20000.0), 1.0));
imageStore(OutImage, ipos, vec4( ACES_Tonemapping( Total * Camera.PaperWhiteNit / 20000.0), 1.0));
}
//imageStore(OutImage, ipos, vec4( imageLoad(InImage, ipos).rgb, 1.0));
}
Loading
Loading