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

Use color correction postprocess in map viewer #704

Open
kristiker opened this issue Jan 22, 2024 · 0 comments · May be fixed by #790
Open

Use color correction postprocess in map viewer #704

kristiker opened this issue Jan 22, 2024 · 0 comments · May be fixed by #790

Comments

@kristiker
Copy link
Member

kristiker commented Jan 22, 2024

Is your feature request related to a problem? Please describe.

Maps use a global postprocess file (vpost resource) that has a Color Lookup Table in it.

Describe the solution you'd like

Here is the pixel shader

// SPIR-V source (2980), SPVC_BACKEND_GLSL reflection with SPIRV-Cross by KhronosGroup
// Source 2 Viewer 7.0.0.0 - https://valveresourceformat.github.io

#version 460

struct globals
{
    float g_flColorCorrectionDefaultWeight;
    vec4 g_vViewFadeColor;
    float g_flFadeMode;
};

layout(set = 0, binding = 90) uniform texture2D g_tColorBuffer;
layout(set = 0, binding = 93) uniform texture3D g_tColorCorrection;

layout(location = 0) in vec2 PositionPs;
layout(location = 0) out vec4 vColor;

void main()
{
    vec4 vColorBuffer = textureLod(sampler2D(g_tColorBuffer, _5465), PositionPs, 0.0);
    vec3 vColorLinear = vColorBuffer.rgb;
    vec3 _25074 = mix(vColorLinear, mix(g_vViewFadeColor.xyz, g_vViewFadeColor.xyz * vColorLinear, vec3(g_flFadeMode)), vec3(g_vViewFadeColor.w));
    
    vec3 vColorGamma = SrgbLinearToGamma(_25074);

    vec3 vSampleCoord = (saturate(vColorGamma) * (31/32)) + vec3(1/(32*2));

    vColor.rgb = mix(texture(sampler3D(g_tColorCorrection, _3600), vSampleCoord).rgb, vColorGamma, vec3(g_flColorCorrectionDefaultWeight));

    vColor.rgb = SrgbGammaToLinear(vColor.rgb);
    vColor.a = vColorBuffer.a;
}

Color buffer is now avaliable as MainFrameBuffer.Color in the GLSceneViewer class. Replace GL.BlitFramebuffer with a postprocess shader invocation (fullscreen triangle pass).

The lut data can be retrieved from this

public int GetColorCorrectionLUTDimension()
=> Data.GetProperty<int>("m_nColorCorrectionVolumeDim");
public byte[] GetColorCorrectionLUT()
=> Data.GetProperty<byte[]>("m_colorCorrectionVolumeData");

Upload as RGBA8888 Tex3D with 32 slices.

Describe alternatives you've considered

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant