pak: CrashReportClient

This commit is contained in:
merith-tk 2024-11-19 13:27:19 -08:00
parent 52ec89eb9a
commit e7e5b9b157
2099 changed files with 2166 additions and 0 deletions

View file

@ -0,0 +1,59 @@
// Copyright Epic Games, Inc. All Rights Reserved.
half3 LinearTo709Branchless(half3 lin)
{
lin = max(6.10352e-5, lin); // minimum positive non-denormal (fixes black problem on DX11 AMD and NV)
return min(lin * 4.5, pow(max(lin, 0.018), 0.45) * 1.099 - 0.099);
}
half3 LinearToSrgbBranchless(half3 lin)
{
lin = max(6.10352e-5, lin); // minimum positive non-denormal (fixes black problem on DX11 AMD and NV)
return min(lin * 12.92, pow(max(lin, 0.00313067), 1.0/2.4) * 1.055 - 0.055);
// Possible that mobile GPUs might have native pow() function?
//return min(lin * 12.92, exp2(log2(max(lin, 0.00313067)) * (1.0/2.4) + log2(1.055)) - 0.055);
}
half LinearToSrgbBranchingChannel(half lin)
{
if(lin < 0.00313067) return lin * 12.92;
return pow(lin, (1.0/2.4)) * 1.055 - 0.055;
}
half3 LinearToSrgbBranching(half3 lin)
{
return half3(
LinearToSrgbBranchingChannel(lin.r),
LinearToSrgbBranchingChannel(lin.g),
LinearToSrgbBranchingChannel(lin.b));
}
half3 sRGBToLinear( half3 Color )
{
Color = max(6.10352e-5, Color); // minimum positive non-denormal (fixes black problem on DX11 AMD and NV)
return Color > 0.04045 ? pow( Color * (1.0 / 1.055) + 0.0521327, 2.4 ) : Color * (1.0 / 12.92);
}
/**
* @param GammaCurveRatio The curve ratio compared to a 2.2 standard gamma, e.g. 2.2 / DisplayGamma. So normally the value is 1.
*/
half3 ApplyGammaCorrection(float3 LinearColor, float GammaCurveRatio)
{
// Apply "gamma" curve adjustment.
float3 CorrectedColor = pow(LinearColor, GammaCurveRatio);
#if MAC
// Note, MacOSX native output is raw gamma 2.2 not sRGB!
CorrectedColor = pow(CorrectedColor, 1.0/2.2);
#else
#if USE_709
// Didn't profile yet if the branching version would be faster (different linear segment).
CorrectedColor = LinearTo709Branchless(CorrectedColor);
#else
CorrectedColor = LinearToSrgbBranching(CorrectedColor);
#endif
#endif
return CorrectedColor;
}

View file

@ -0,0 +1,39 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "GammaCorrectionCommon.hlsl"
cbuffer PerElementVSConstants
{
matrix WorldViewProjection;
}
struct VertexOut
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float4 SecondaryColor : COLOR1;
float4 TextureCoordinates : TEXCOORD0;
};
VertexOut Main(
in float2 InPosition : POSITION,
in float4 InTextureCoordinates : TEXCOORD0,
in float2 MaterialTexCoords : TEXCOORD1,
in float4 InColor : COLOR0,
in float4 InSecondaryColor : COLOR1
)
{
VertexOut Out;
Out.Position = mul( WorldViewProjection, float4( InPosition.xy, 0, 1 ) );
Out.TextureCoordinates = InTextureCoordinates;
InColor.rgb = sRGBToLinear(InColor.rgb);
InSecondaryColor.rgb = sRGBToLinear(InSecondaryColor.rgb);
Out.Color = InColor;
Out.SecondaryColor = InSecondaryColor;
return Out;
}

View file

@ -0,0 +1,251 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "GammaCorrectionCommon.hlsl"
// Shader types
#define ESlateShader::Default 0
#define ESlateShader::Border 1
#define ESlateShader::GrayscaleFont 2
#define ESlateShader::ColorFont 3
#define ESlateShader::LineSegment 4
#define ESlateShader::RoundedBox 7
#define USE_LEGACY_DISABLED_EFFECT 0
Texture2D ElementTexture;
SamplerState ElementTextureSampler;
cbuffer PerFramePSConstants
{
/** Display gamma x:gamma curve adjustment, y:inverse gamma (1/GEngine->DisplayGamma) */
float2 GammaValues;
};
cbuffer PerElementPSConstants
{
float4 ShaderParams; // 16 bytes
float4 ShaderParams2; // 16 bytes
uint ShaderType; // 4 bytes
uint IgnoreTextureAlpha; // 4 bytes
uint DisableEffect; // 4 bytes
uint UNUSED[1]; // 4 bytes
};
struct VertexOut
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float4 SecondaryColor : COLOR1;
float4 TextureCoordinates : TEXCOORD0;
};
float3 Hue( float H )
{
float R = abs(H * 6 - 3) - 1;
float G = 2 - abs(H * 6 - 2);
float B = 2 - abs(H * 6 - 4);
return saturate( float3(R,G,B) );
}
float3 GammaCorrect(float3 InColor)
{
float3 CorrectedColor = InColor;
if ( GammaValues.y != 1.0f )
{
CorrectedColor = ApplyGammaCorrection(CorrectedColor, GammaValues.x);
}
return CorrectedColor;
}
float4 GetGrayscaleFontElementColor( VertexOut InVertex )
{
float4 OutColor = InVertex.Color;
OutColor.a *= ElementTexture.Sample(ElementTextureSampler, InVertex.TextureCoordinates.xy).a;
return OutColor;
}
float4 GetColorFontElementColor(VertexOut InVertex)
{
float4 OutColor = InVertex.Color;
OutColor *= ElementTexture.Sample(ElementTextureSampler, InVertex.TextureCoordinates.xy);
return OutColor;
}
float4 GetColor( VertexOut InVertex, float2 UV )
{
float4 FinalColor;
float4 BaseColor = ElementTexture.Sample(ElementTextureSampler, UV );
if( IgnoreTextureAlpha != 0 )
{
BaseColor.a = 1.0f;
}
FinalColor = BaseColor*InVertex.Color;
return FinalColor;
}
float4 GetDefaultElementColor( VertexOut InVertex )
{
return GetColor( InVertex, InVertex.TextureCoordinates.xy*InVertex.TextureCoordinates.zw );
}
float4 GetBorderElementColor( VertexOut InVertex )
{
float2 NewUV;
if( InVertex.TextureCoordinates.z == 0.0f && InVertex.TextureCoordinates.w == 0.0f )
{
NewUV = InVertex.TextureCoordinates.xy;
}
else
{
float2 MinUV;
float2 MaxUV;
if( InVertex.TextureCoordinates.z > 0 )
{
MinUV = float2(ShaderParams.x,0);
MaxUV = float2(ShaderParams.y,1);
InVertex.TextureCoordinates.w = 1.0f;
}
else
{
MinUV = float2(0,ShaderParams.z);
MaxUV = float2(1,ShaderParams.w);
InVertex.TextureCoordinates.z = 1.0f;
}
NewUV = InVertex.TextureCoordinates.xy*InVertex.TextureCoordinates.zw;
NewUV = frac(NewUV);
NewUV = lerp(MinUV,MaxUV,NewUV);
}
return GetColor( InVertex, NewUV );
}
float GetRoundedBoxDistance(float2 pos, float2 center, float radius, float inset)
{
// distance from center
pos = abs(pos - center);
// distance from the inner corner
pos = pos - (center - float2(radius + inset, radius + inset));
// use distance to nearest edge when not in quadrant with radius
// this handles an edge case when radius is very close to thickness
// otherwise we're in the quadrant with the radius,
// just use the analytic signed distance function
return lerp( length(pos) - radius, max(pos.x - radius, pos.y - radius), float(pos.x <= 0 || pos.y <=0) );
}
float4 GetRoundedBoxElementColor( VertexOut InVertex )
{
const float2 size = ShaderParams.zw;
float2 pos = size * InVertex.TextureCoordinates.xy;
float2 center = size / 2.0;
//X = Top Left, Y = Top Right, Z = Bottom Right, W = Bottom Left */
float4 cornerRadii = ShaderParams2;
// figure out which radius to use based on which quadrant we're in
float2 quadrant = step(InVertex.TextureCoordinates.xy, float2(.5,.5));
float left = lerp(cornerRadii.y, cornerRadii.x, quadrant.x);
float right = lerp(cornerRadii.z, cornerRadii.w, quadrant.x);
float radius = lerp(right, left, quadrant.y);
float thickness = ShaderParams.y;
// Compute the distances internal and external to the border outline
float dext = GetRoundedBoxDistance(pos, center, radius, 0.0);
float din = GetRoundedBoxDistance(pos, center, max(radius - thickness, 0), thickness);
// Compute the border intensity and fill intensity with a smooth transition
float spread = 0.5;
float bi = smoothstep(spread, -spread, dext);
float fi = smoothstep(spread, -spread, din);
// alpha blend the external color
float4 fill = GetColor(InVertex, InVertex.TextureCoordinates.xy * InVertex.TextureCoordinates.zw);
float4 border = InVertex.SecondaryColor;
float4 OutColor = lerp(border, fill, float(thickness > radius));
OutColor.a = 0.0;
// blend in the border and fill colors
OutColor = lerp(OutColor, border, bi);
OutColor = lerp(OutColor, fill, fi);
return OutColor;
}
float4 GetLineSegmentElementColor( VertexOut InVertex )
{
const float2 Gradient = InVertex.TextureCoordinates;
const float2 OutsideFilterUV = float2(1.0f, 1.0f);
const float2 InsideFilterUV = float2(ShaderParams.x, 0.0f);
const float2 LineCoverage = smoothstep(OutsideFilterUV, InsideFilterUV, abs(Gradient));
float4 Color = InVertex.Color;
Color.a *= LineCoverage.x * LineCoverage.y;
return Color;
}
float4 Main( VertexOut InVertex ) : SV_Target
{
float4 OutColor;
if( ShaderType == ESlateShader::Default )
{
OutColor = GetDefaultElementColor( InVertex );
}
else if( ShaderType == ESlateShader::RoundedBox)
{
OutColor = GetRoundedBoxElementColor( InVertex );
}
else if( ShaderType == ESlateShader::Border )
{
OutColor = GetBorderElementColor( InVertex );
}
else if( ShaderType == ESlateShader::GrayscaleFont )
{
OutColor = GetGrayscaleFontElementColor( InVertex );
}
else if (ShaderType == ESlateShader::ColorFont)
{
OutColor = GetColorFontElementColor(InVertex);
}
else
{
OutColor = GetLineSegmentElementColor( InVertex );
}
// gamma correct
OutColor.rgb = GammaCorrect(OutColor.rgb);
if (DisableEffect)
{
#if USE_LEGACY_DISABLED_EFFECT
//desaturate
float3 LumCoeffs = float3( 0.3, 0.59, .11 );
float Lum = dot( LumCoeffs, OutColor.rgb );
OutColor.rgb = lerp( OutColor.rgb, float3(Lum,Lum,Lum), .8 );
float3 Grayish = {.4, .4, .4};
// lerp between desaturated color and gray color based on distance from the desaturated color to the gray
OutColor.rgb = lerp( OutColor.rgb, Grayish, clamp( distance( OutColor.rgb, Grayish ), 0, .8) );
#else
OutColor.a *= .45f;
#endif
}
return OutColor;
}

View file

@ -0,0 +1,351 @@
// Copyright Epic Games, Inc. All Rights Reserved.
// handle differences between ES and full GL shaders
#if PLATFORM_USES_GLES
precision highp float;
#else
// #version 120 at the beginning is added in FSlateOpenGLShader::CompileShader()
#extension GL_EXT_gpu_shader4 : enable
#endif
#ifndef USE_709
#define USE_709 0
#endif // USE_709
// Shader types
#define ST_Default 0
#define ST_Border 1
#define ST_GrayscaleFont 2
#define ST_ColorFont 3
#define ST_Line 4
#define ST_RoundedBox 7
#define USE_LEGACY_DISABLED_EFFECT 0
/** Display gamma x:gamma curve adjustment, y:inverse gamma (1/GEngine->DisplayGamma) */
uniform vec2 GammaValues = vec2(1, 1/2.2);
// Draw effects
uniform bool EffectsDisabled;
uniform bool IgnoreTextureAlpha;
uniform vec4 ShaderParams;
uniform vec4 ShaderParams2;
uniform int ShaderType;
uniform sampler2D ElementTexture;
#if PLATFORM_MAC
// GL_TEXTURE_RECTANGLE_ARB support, used by the web surface on macOS
uniform bool UseTextureRectangle;
uniform sampler2DRect ElementRectTexture;
uniform vec2 Size;
#endif
varying vec4 Position;
varying vec4 TexCoords;
varying vec4 Color;
varying vec4 SecondaryColor;
vec3 maxWithScalar(float test, vec3 values)
{
return vec3(max(test, values.x), max(test, values.y), max(test, values.z));
}
vec3 powScalar(vec3 values, float power)
{
return vec3(pow(values.x, power), pow(values.y, power), pow(values.z, power));
}
vec3 LinearTo709Branchless(vec3 lin)
{
lin = maxWithScalar(6.10352e-5, lin); // minimum positive non-denormal (fixes black problem on DX11 AMD and NV)
return min(lin * 4.5, powScalar(maxWithScalar(0.018, lin), 0.45) * 1.099 - 0.099);
}
vec3 LinearToSrgbBranchless(vec3 lin)
{
lin = maxWithScalar(6.10352e-5, lin); // minimum positive non-denormal (fixes black problem on DX11 AMD and NV)
return min(lin * 12.92, powScalar(maxWithScalar(0.00313067, lin), 1.0/2.4) * 1.055 - 0.055);
// Possible that mobile GPUs might have native pow() function?
//return min(lin * 12.92, exp2(log2(max(lin, 0.00313067)) * (1.0/2.4) + log2(1.055)) - 0.055);
}
float LinearToSrgbBranchingChannel(float lin)
{
if(lin < 0.00313067) return lin * 12.92;
return pow(lin, (1.0/2.4)) * 1.055 - 0.055;
}
vec3 LinearToSrgbBranching(vec3 lin)
{
return vec3(
LinearToSrgbBranchingChannel(lin.r),
LinearToSrgbBranchingChannel(lin.g),
LinearToSrgbBranchingChannel(lin.b));
}
float sRGBToLinearChannel( float ColorChannel )
{
return ColorChannel > 0.04045 ? pow( ColorChannel * (1.0 / 1.055) + 0.0521327, 2.4 ) : ColorChannel * (1.0 / 12.92);
}
vec3 sRGBToLinear( vec3 Color )
{
return vec3(sRGBToLinearChannel(Color.r),
sRGBToLinearChannel(Color.g),
sRGBToLinearChannel(Color.b));
}
/**
* @param GammaCurveRatio The curve ratio compared to a 2.2 standard gamma, e.g. 2.2 / DisplayGamma. So normally the value is 1.
*/
vec3 ApplyGammaCorrection(vec3 LinearColor, float GammaCurveRatio)
{
// Apply "gamma" curve adjustment.
vec3 CorrectedColor = powScalar(LinearColor, GammaCurveRatio);
#if PLATFORM_MAC
// Note, MacOSX native output is raw gamma 2.2 not sRGB!
//CorrectedColor = pow(CorrectedColor, 1.0/2.2);
CorrectedColor = LinearToSrgbBranching(CorrectedColor);
#else
#if USE_709
// Didn't profile yet if the branching version would be faster (different linear segment).
CorrectedColor = LinearTo709Branchless(CorrectedColor);
#else
CorrectedColor = LinearToSrgbBranching(CorrectedColor);
#endif
#endif
return CorrectedColor;
}
vec3 GammaCorrect(vec3 InColor)
{
vec3 CorrectedColor = InColor;
// gamma correct
//#if PLATFORM_USES_GLES
// OutColor.rgb = sqrt( OutColor.rgb );
//#else
// OutColor.rgb = pow(OutColor.rgb, vec3(1.0/2.2));
//#endif
#if !PLATFORM_USES_GLES
if( GammaValues.y != 1.0f )
{
CorrectedColor = ApplyGammaCorrection(CorrectedColor, GammaValues.x);
}
#endif
return CorrectedColor;
}
vec4 GetGrayscaleFontElementColor()
{
vec4 OutColor = Color;
#if PLATFORM_LINUX
OutColor.a *= texture2D(ElementTexture, TexCoords.xy).r; // OpenGL 3.2+ uses Red for single channel textures
#else
OutColor.a *= texture2D(ElementTexture, TexCoords.xy).a;
#endif
return OutColor;
}
vec4 GetColorFontElementColor()
{
vec4 OutColor = Color;
OutColor *= texture2D(ElementTexture, TexCoords.xy);
return OutColor;
}
vec4 GetDefaultElementColor()
{
vec4 OutColor = Color;
vec4 TextureColor;
#if PLATFORM_MAC
if ( UseTextureRectangle )
{
TextureColor = texture2DRect(ElementRectTexture, TexCoords.xy*TexCoords.zw*Size).bgra;
}
else
#endif
{
TextureColor = texture2D(ElementTexture, TexCoords.xy*TexCoords.zw);
}
if( IgnoreTextureAlpha )
{
TextureColor.a = 1.0;
}
OutColor *= TextureColor;
return OutColor;
}
vec4 GetBorderElementColor()
{
vec4 OutColor = Color;
vec4 InTexCoords = TexCoords;
vec2 NewUV;
if( InTexCoords.z == 0.0 && InTexCoords.w == 0.0 )
{
NewUV = InTexCoords.xy;
}
else
{
vec2 MinUV;
vec2 MaxUV;
if( InTexCoords.z > 0.0 )
{
MinUV = vec2(ShaderParams.x,0.0);
MaxUV = vec2(ShaderParams.y,1.0);
InTexCoords.w = 1.0;
}
else
{
MinUV = vec2(0.0,ShaderParams.z);
MaxUV = vec2(1.0,ShaderParams.w);
InTexCoords.z = 1.0;
}
NewUV = InTexCoords.xy*InTexCoords.zw;
NewUV = fract(NewUV);
NewUV = mix(MinUV,MaxUV,NewUV);
}
vec4 TextureColor = texture2D(ElementTexture, NewUV);
if( IgnoreTextureAlpha )
{
TextureColor.a = 1.0;
}
OutColor *= TextureColor;
return OutColor;
}
float GetRoundedBoxDistance(vec2 pos, vec2 center, float radius, float inset)
{
// distance from center
pos = abs(pos - center);
// distance from the inner corner
pos = pos - (center - vec2(radius + inset, radius + inset));
// use distance to nearest edge when not in quadrant with radius
// this handles an edge case when radius is very close to thickness
// otherwise we're in the quadrant with the radius,
// just use the analytic signed distance function
return mix( length(pos) - radius,
max(pos.x - radius, pos.y - radius),
float(pos.x <= 0 || pos.y <=0) );
}
vec4 GetRoundedBoxElementColor()
{
vec2 size = ShaderParams.zw;
vec2 pos = size * TexCoords.xy;
vec2 center = size / 2.0;
//X = Top Left, Y = Top Right, Z = Bottom Right, W = Bottom Left */
vec4 cornerRadii = ShaderParams2;
// figure out which radius to use based on which quadrant we're in
vec2 quadrant = step(TexCoords.xy, vec2(.5,.5));
float left = mix(cornerRadii.y, cornerRadii.x, quadrant.x);
float right = mix(cornerRadii.z, cornerRadii.w, quadrant.x);
float radius = mix(right, left, quadrant.y);
float thickness = ShaderParams.y;
// Compute the distances internal and external to the border outline
float dext = GetRoundedBoxDistance(pos, center, radius, 0.0);
float din = GetRoundedBoxDistance(pos, center, max(radius - thickness, 0), thickness);
// Compute the border intensity and fill intensity with a smooth transition
float spread = 0.5;
float bi = smoothstep(spread, -spread, dext);
float fi = smoothstep(spread, -spread, din);
// alpha blend the external color
vec4 fill = GetDefaultElementColor();
vec4 border = SecondaryColor;
vec4 OutColor = mix(border, fill, float(thickness > radius));
OutColor.a = 0.0;
// blend in the border and fill colors
OutColor = mix(OutColor, border, bi);
OutColor = mix(OutColor, fill, fi);
return OutColor;
}
vec4 GetLineSegmentElementColor()
{
vec2 Gradient = TexCoords.xy;
vec2 OutsideFilterUV = vec2(1.0, 1.0);
vec2 InsideFilterUV = vec2(ShaderParams.x, 0.0);
vec2 LineCoverage = smoothstep(OutsideFilterUV, InsideFilterUV, abs(Gradient));
vec4 OutColor = Color;
OutColor.a *= LineCoverage.x * LineCoverage.y;
return OutColor;
}
void main()
{
vec4 OutColor;
if( ShaderType == ST_Default )
{
OutColor = GetDefaultElementColor();
}
else if( ShaderType == ST_RoundedBox )
{
OutColor = GetRoundedBoxElementColor();
}
else if( ShaderType == ST_Border )
{
OutColor = GetBorderElementColor();
}
else if( ShaderType == ST_GrayscaleFont )
{
OutColor = GetGrayscaleFontElementColor();
}
else if( ShaderType == ST_ColorFont )
{
OutColor = GetColorFontElementColor();
}
else
{
OutColor = GetLineSegmentElementColor();
}
// gamma correct
OutColor.rgb = GammaCorrect(OutColor.rgb);
if( EffectsDisabled )
{
#if USE_LEGACY_DISABLED_EFFECT
//desaturate
vec3 LumCoeffs = vec3( 0.3, 0.59, .11 );
float Lum = dot( LumCoeffs, OutColor.rgb );
OutColor.rgb = mix( OutColor.rgb, vec3(Lum,Lum,Lum), .8 );
vec3 Grayish = vec3(0.4, 0.4, 0.4);
OutColor.rgb = mix( OutColor.rgb, Grayish, clamp( distance( OutColor.rgb, Grayish ), 0.0, 0.8) );
#else
OutColor.a *= .45f;
#endif
}
gl_FragColor = OutColor.bgra;
}

View file

@ -0,0 +1,50 @@
// Copyright Epic Games, Inc. All Rights Reserved.
// #version 120 at the beginning is added in FSlateOpenGLShader::CompileShader()
uniform mat4 ViewProjectionMatrix;
// Per vertex
attribute vec4 InTexCoords;
attribute vec2 InPosition;
attribute vec4 InColor;
attribute vec4 InSecondaryColor;
// Between vertex and pixel shader
varying vec4 Position;
varying vec4 TexCoords;
varying vec4 Color;
varying vec4 SecondaryColor;
vec3 powScalar(vec3 values, float power)
{
return vec3(pow(values.x, power), pow(values.y, power), pow(values.z, power));
}
float sRGBToLinearChannel( float ColorChannel )
{
return ColorChannel > 0.04045 ? pow( ColorChannel * (1.0 / 1.055) + 0.0521327, 2.4 ) : ColorChannel * (1.0 / 12.92);
}
vec3 sRGBToLinear( vec3 Color )
{
return vec3(
sRGBToLinearChannel(Color.r),
sRGBToLinearChannel(Color.g),
sRGBToLinearChannel(Color.b));
}
void main()
{
TexCoords = InTexCoords;
Color.rgb = sRGBToLinear(InColor.rgb);
Color.a = InColor.a;
SecondaryColor.rgb = sRGBToLinear(InSecondaryColor.rgb);
SecondaryColor.a = InSecondaryColor.a;
Position = vec4( InPosition, 0, 1 );
gl_Position = ViewProjectionMatrix * vec4( InPosition, 0, 1 );
}

View file

@ -0,0 +1,20 @@
#if PLATFORM_USES_GLES
precision highp float;
#else
// #version 120 at the beginning is added in FSlateOpenGLShader::CompileShader()
#extension GL_EXT_gpu_shader4 : enable
#endif
varying vec2 textureCoordinate;
uniform sampler2D SplashTexture;
void main()
{
// OpenGL has 0,0 the "math" way
vec2 tc = vec2(textureCoordinate.s, 1.0-textureCoordinate.t);
gl_FragColor = texture2D(SplashTexture, tc);
}

View file

@ -0,0 +1,12 @@
attribute vec2 InPosition;
varying vec2 textureCoordinate;
void main()
{
// We do not need texture coordinates. We calculate using position.
textureCoordinate = InPosition * 0.5 + 0.5;
gl_Position = vec4(InPosition, 0.0, 1.0);
}