mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-10-25 02:10:51 +00:00
S2H cleanup. (#3964)
This commit is contained in:
committed by
GitHub
parent
71aef19f1f
commit
78ee247bf5
@@ -1,8 +1,6 @@
|
||||
// Port of ShaderToHuman-bgfx/examples/Features/Scatter_example.hlsl.
|
||||
#include "bgfx_compute.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h_scatter.hlsl"
|
||||
#include "s2h/s2h_scatter.sh"
|
||||
|
||||
IMAGE2D_WO(s_scatterColor, rgba8, 0);
|
||||
uniform vec4 u_s2hScatterSize;
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
$input v_color0, v_texcoord0
|
||||
|
||||
// The S2H sources are shared with the HLSL integration; this adapter supplies
|
||||
// shaderc-compatible definitions for the bgfx backends.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
@@ -2,8 +2,7 @@ $input v_color0, v_texcoord0
|
||||
|
||||
// Fragment-renderer port of ShaderToHuman-bgfx/examples/Features/2D_example.hlsl.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
uniform vec4 u_s2hTime;
|
||||
uniform vec4 u_s2hMouse;
|
||||
@@ -36,7 +35,7 @@ void drawBlendingExample(inout ContextGather _ui)
|
||||
vec3 color = s2h_indexToColor(uint(peelId));
|
||||
vec2 center = vec2(sin(angle), cos(angle)) * 60.0f + vec2(105.0f, 450.0f);
|
||||
float alpha = saturate(2.0f - length(_ui.pxPos - center) / 25.0f);
|
||||
overColor = lerp(overColor, color, alpha);
|
||||
overColor = mix(overColor, color, alpha);
|
||||
underAccumulator.rgb += color * alpha * (1.0f - underAccumulator.a);
|
||||
underAccumulator.a = 1.0f - (1.0f - alpha) * (1.0f - underAccumulator.a);
|
||||
}
|
||||
@@ -111,5 +110,5 @@ void main()
|
||||
|
||||
drawBlendingExample(ui);
|
||||
vec4 background = vec4(0.7f, 0.4f, 0.4f, 1.0f);
|
||||
gl_FragColor = lerp(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
gl_FragColor = mix(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ $input v_color0, v_texcoord0
|
||||
|
||||
// Self-contained fragment-renderer port of Features/3D_example.hlsl.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h_3d.hlsl"
|
||||
#include "s2h/s2h_3d.sh"
|
||||
|
||||
uniform vec4 u_s2hTime;
|
||||
|
||||
@@ -28,9 +26,7 @@ mat4 lookAt(vec3 _eye, vec3 _target, vec3 _up)
|
||||
vec3 zaxis = safeNormalize(_target - _eye);
|
||||
vec3 xaxis = safeNormalize(cross(_up, zaxis));
|
||||
vec3 yaxis = cross(zaxis, xaxis);
|
||||
// HLSL mat4 constructors receive rows, while GLSL mat4 constructors
|
||||
// receive columns. s2h_drawBasis expects world-space basis vectors in the
|
||||
// matrix columns, so only the HLSL path needs the transpose.
|
||||
// HLSL mat4 constructors receive rows, GLSL receives columns.
|
||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
||||
return mat4(vec4(xaxis, 0.0f), vec4(yaxis, 0.0f), vec4(zaxis, 0.0f), vec4(_eye, 1.0f));
|
||||
#else
|
||||
@@ -73,7 +69,7 @@ void main()
|
||||
s2h_printFloat(ui, cameraPosition.y); s2h_printTxt(ui, _COMMA);
|
||||
s2h_printFloat(ui, cameraPosition.z);
|
||||
|
||||
vec3 color = lerp(vec3(0.0f, 0.0f, 0.0f), context.dstColor.rgb, context.dstColor.a);
|
||||
vec3 color = mix(vec3(0.0f, 0.0f, 0.0f), context.dstColor.rgb, context.dstColor.a);
|
||||
color = color * (1.0f - ui.dstColor.a) + ui.dstColor.rgb;
|
||||
gl_FragColor = vec4(s2h_accurateLinearToSRGB(color), 1.0f);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ $input v_color0, v_texcoord0
|
||||
|
||||
// Port of ShaderToHuman-bgfx/examples/Features/2D_Arrow.hlsl.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
uniform vec4 u_s2hMouse;
|
||||
|
||||
@@ -65,5 +64,5 @@ void main()
|
||||
s2h_drawArrow(ui, screenCenter, screenCenter + oppositeDirection * lineLength, vec4(1.0f, 0.0f, 0.0f, 1.0f), arrowHeadLength, arrowHeadWidth);
|
||||
|
||||
vec4 background = vec4(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
gl_FragColor = lerp(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
gl_FragColor = mix(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ $input v_color0, v_texcoord0
|
||||
|
||||
// Self-contained fragment-renderer port of Features/Clear_example.hlsl.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h_3d.hlsl"
|
||||
#include "s2h/s2h_3d.sh"
|
||||
|
||||
uniform vec4 u_s2hTime;
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ $input v_color0, v_texcoord0
|
||||
|
||||
// Port of ShaderToHuman-bgfx/examples/Features/2D_CoordinateSystem.hlsl.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -24,5 +23,5 @@ void main()
|
||||
s2h_printTxt(ui, _n, _a, _t, _e, _S, _y);
|
||||
s2h_printTxt(ui, _s, _t, _e, _m);
|
||||
|
||||
gl_FragColor = lerp(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
gl_FragColor = mix(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
$input v_color0, v_texcoord0
|
||||
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h/s2h_bgfx.sh"
|
||||
|
||||
SAMPLER2D(s_quadPostColor, 0);
|
||||
uniform vec4 u_s2hMouse;
|
||||
@@ -17,10 +17,10 @@ void main()
|
||||
{
|
||||
vec2 sourcePixel = floor(mouse - vec2(8.0f, 8.0f) + panelLocal / 10.0f);
|
||||
color = texture2D(s_quadPostColor, (sourcePixel + 0.5f) / resolution).rgb;
|
||||
vec2 cell = frac(panelLocal / 10.0f);
|
||||
vec2 cell = fract(panelLocal / 10.0f);
|
||||
if (cell.x < 0.08f || cell.y < 0.08f) color = vec3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
float crosshair = 1.0f - smoothstep(0.0f, 1.0f, min(abs(pixel.x - mouse.x), abs(pixel.y - mouse.y)));
|
||||
color = lerp(color, vec3(1.0f, 1.0f, 1.0f), crosshair);
|
||||
color = mix(color, vec3(1.0f, 1.0f, 1.0f), crosshair);
|
||||
gl_FragColor = vec4(color, 1.0f);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
$input v_color0, v_texcoord0
|
||||
|
||||
// Port of ShaderToHuman-bgfx/examples/Features/Gather_example.hlsl.
|
||||
// The original compute example stores its widget state in a UAV. This
|
||||
// fullscreen version receives the same state from the ImGui host controls.
|
||||
// Widget state comes from the ImGui host controls, not a UAV as in the original.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
uniform vec4 u_s2hTime;
|
||||
uniform vec4 u_s2hUiState;
|
||||
@@ -76,9 +74,7 @@ void main()
|
||||
vec3 sliderColor = u_s2hColor.rgb;
|
||||
|
||||
#if BGFX_SHADER_LANGUAGE_WGSL
|
||||
// shaderc's WGSL backend overflows its compiler stack when all of the
|
||||
// nested S2H widget calls below are emitted together. Keep a compact,
|
||||
// functional presentation for WebGPU; DX11 and GLSL use the full port.
|
||||
// shaderc's WGSL backend overflows its compiler stack on the full port.
|
||||
s2h_printLF(ui);
|
||||
s2h_printLF(ui);
|
||||
s2h_printTxt(ui, _U, _I, _SPACE, _S, _t, _a);
|
||||
@@ -97,7 +93,7 @@ void main()
|
||||
s2h_printTxt(ui, _SPACE, _c, _h, _e, _c, _k);
|
||||
s2h_printLF(ui);
|
||||
s2h_printTxt(ui, _SPACE, _SPACE);
|
||||
s2h_progress(ui, 5u, frac(u_s2hTime.x));
|
||||
s2h_progress(ui, 5u, fract(u_s2hTime.x));
|
||||
s2h_printLF(ui);
|
||||
s2h_printTxt(ui, _SPACE, _SPACE);
|
||||
s2h_sliderFloat(ui, 8u, sliderAlpha, 0.0f, 1.0f);
|
||||
@@ -147,7 +143,7 @@ void main()
|
||||
s2h_printLF(ui);
|
||||
s2h_printLF(ui);
|
||||
s2h_printTxt(ui, _SPACE, _SPACE);
|
||||
s2h_progress(ui, 5u, frac(u_s2hTime.x));
|
||||
s2h_progress(ui, 5u, fract(u_s2hTime.x));
|
||||
s2h_printTxt(ui, _SPACE, _s, _2, _h, _UNDERSCORE, _p);
|
||||
s2h_printTxt(ui, _r, _o, _g, _r, _e, _s);
|
||||
s2h_printTxt(ui, _s);
|
||||
@@ -168,5 +164,5 @@ void main()
|
||||
#endif
|
||||
|
||||
vec4 background = vec4(0.4f, 0.7f, 0.4f, 1.0f);
|
||||
gl_FragColor = lerp(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
gl_FragColor = mix(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
}
|
||||
|
||||
@@ -2,21 +2,20 @@ $input v_color0, v_texcoord0
|
||||
|
||||
// Port of ShaderToHuman-bgfx/examples/Features/GenUserFont_example.hlsl.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
uniform vec4 u_s2hTime;
|
||||
|
||||
vec3 myMod(vec3 _x, vec3 _period)
|
||||
{
|
||||
return frac(_x / _period) * _period;
|
||||
return fract(_x / _period) * _period;
|
||||
}
|
||||
|
||||
vec3 hsb2rgb(vec3 _color)
|
||||
{
|
||||
vec3 rgb = saturate(abs(myMod(_color.x * 6.0f + vec3(0.0f, 4.0f, 2.0f), vec3(6.0f, 6.0f, 6.0f)) - 3.0f) - 1.0f);
|
||||
rgb = rgb * rgb * (3.0f - 2.0f * rgb);
|
||||
return _color.z * lerp(vec3(1.0f, 1.0f, 1.0f), rgb, _color.y);
|
||||
return _color.z * mix(vec3(1.0f, 1.0f, 1.0f), rgb, _color.y);
|
||||
}
|
||||
|
||||
void main()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
$input v_color0, v_texcoord0
|
||||
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h/s2h_bgfx.sh"
|
||||
|
||||
SAMPLER2D(s_quadPostColor, 0);
|
||||
uniform vec4 u_s2hMouse;
|
||||
@@ -13,6 +13,6 @@ void main()
|
||||
vec2 mouseUv = u_s2hMouse.xy / u_viewRect.zw;
|
||||
vec2 delta = uv - mouseUv;
|
||||
float highlight = 1.0f - smoothstep(0.02f, 0.025f, length(delta));
|
||||
color = lerp(color, vec3(1.0f, 1.0f, 0.0f), highlight);
|
||||
color = mix(color, vec3(1.0f, 1.0f, 0.0f), highlight);
|
||||
gl_FragColor = vec4(color, 1.0f);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
$input v_color0, v_texcoord0
|
||||
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h/s2h_bgfx.sh"
|
||||
|
||||
uniform vec4 u_s2hTime;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 uv = v_texcoord0;
|
||||
float grid = step(0.96f, frac(uv.x * 10.0f)) + step(0.96f, frac(uv.y * 10.0f));
|
||||
float grid = step(0.96f, fract(uv.x * 10.0f)) + step(0.96f, fract(uv.y * 10.0f));
|
||||
float wave = 0.5f + 0.5f * sin(u_s2hTime.x + uv.x * 8.0f + uv.y * 5.0f);
|
||||
vec3 color = lerp(vec3(0.06f, 0.1f, 0.25f), vec3(0.9f, 0.25f, 0.1f), wave);
|
||||
gl_FragColor = vec4(lerp(color, vec3(1.0f, 1.0f, 1.0f), grid), 1.0f);
|
||||
vec3 color = mix(vec3(0.06f, 0.1f, 0.25f), vec3(0.9f, 0.25f, 0.1f), wave);
|
||||
gl_FragColor = vec4(mix(color, vec3(1.0f, 1.0f, 1.0f), grid), 1.0f);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
$input v_color0, v_texcoord0
|
||||
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
uniform vec4 u_s2hTime;
|
||||
uniform vec4 u_s2hMouse;
|
||||
@@ -11,7 +10,7 @@ void main()
|
||||
{
|
||||
vec2 edge = min(v_texcoord0, 1.0f - v_texcoord0);
|
||||
float border = 1.0f - smoothstep(0.008f, 0.018f, min(edge.x, edge.y));
|
||||
vec3 color = lerp(vec3(0.03f, 0.04f, 0.08f), vec3(1.0f, 0.0f, 1.0f), border * 0.4f);
|
||||
vec3 color = mix(vec3(0.03f, 0.04f, 0.08f), vec3(1.0f, 0.0f, 1.0f), border * 0.4f);
|
||||
|
||||
ContextGather ui;
|
||||
s2h_init(ui, s2h_getPixelCoord(gl_FragCoord.xy));
|
||||
@@ -27,6 +26,6 @@ void main()
|
||||
s2h_printLF(ui);
|
||||
s2h_printTxt(ui, _t, _i, _m, _e, _COLON, _SPACE); s2h_printFloat(ui, u_s2hTime.x);
|
||||
|
||||
color = lerp(color, ui.dstColor.rgb, ui.dstColor.a);
|
||||
color = mix(color, ui.dstColor.rgb, ui.dstColor.a);
|
||||
gl_FragColor = vec4(color, 1.0f);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ $input v_color0, v_texcoord0
|
||||
|
||||
// Port of ShaderToHuman-bgfx/examples/HelloScreenVSPS/HelloWorldPS.hlsl.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -22,5 +21,5 @@ void main()
|
||||
s2h_drawSRGBRamp(ui, vec2(10.0f, 100.0f));
|
||||
|
||||
vec4 background = vec4(uv.x, uv.y, 0.0f, 1.0f);
|
||||
gl_FragColor = lerp(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
gl_FragColor = mix(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ $input v_color0, v_texcoord0
|
||||
|
||||
// Port of ShaderToHuman-bgfx/examples/Features/Table_example.hlsl.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
uniform vec4 u_s2hTime;
|
||||
|
||||
@@ -102,5 +101,5 @@ void main()
|
||||
s2h_printTxt(ui, _y, _COLON, _SPACE); s2h_printFloat(ui, rangeY.x); s2h_printTxt(ui, _SPACE, _PERIOD, _PERIOD, _SPACE); s2h_printFloat(ui, rangeY.y);
|
||||
|
||||
vec4 background = vec4(0.4f, 0.7f, 0.4f, 1.0f);
|
||||
gl_FragColor = lerp(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
gl_FragColor = mix(background, vec4(ui.dstColor.rgb, 1.0f), ui.dstColor.a);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
$input v_color0, v_texcoord0
|
||||
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h/s2h_bgfx.sh"
|
||||
|
||||
SAMPLER2D(s_quadPostColor, 0);
|
||||
|
||||
|
||||
@@ -2,14 +2,13 @@ $input v_color0, v_texcoord0
|
||||
|
||||
// Adapted from ShaderToHuman-bgfx/examples/Zoom2D/Render.hlsl.
|
||||
#include "../common/common.sh"
|
||||
#include "s2h_bgfx.sh"
|
||||
#include "s2h.hlsl"
|
||||
#include "s2h/s2h.sh"
|
||||
|
||||
uniform vec4 u_s2hZoom;
|
||||
|
||||
float grid(vec2 _position, float _scale)
|
||||
{
|
||||
vec2 local = abs(frac(_position / 20.0f) - 0.5f);
|
||||
vec2 local = abs(fract(_position / 20.0f) - 0.5f);
|
||||
float gridLine = 1.0f - smoothstep(0.46f, 0.50f, max(local.x, local.y));
|
||||
return gridLine * saturate((_scale - 2.0f) / 6.0f);
|
||||
}
|
||||
@@ -21,7 +20,7 @@ void main()
|
||||
vec2 zoomedPixel = (pixel + u_s2hZoom.xy) * zoomScale;
|
||||
vec2 snappedPixel = floor(zoomedPixel) + 0.5f;
|
||||
vec3 color = vec3(0.01f, 0.01f, 0.10f);
|
||||
color = lerp(color, vec3(0.22f, 0.25f, 0.35f), grid(zoomedPixel, zoomScale));
|
||||
color = mix(color, vec3(0.22f, 0.25f, 0.35f), grid(zoomedPixel, zoomScale));
|
||||
|
||||
ContextGather ui;
|
||||
s2h_init(ui, snappedPixel);
|
||||
@@ -32,7 +31,7 @@ void main()
|
||||
s2h_printTxt(ui, _c, _o, _o, _r, _d, _i);
|
||||
s2h_printTxt(ui, _n, _a, _t, _e, _S, _y);
|
||||
s2h_printTxt(ui, _s, _t, _e, _m);
|
||||
color = lerp(color, ui.dstColor.rgb, ui.dstColor.a);
|
||||
color = mix(color, ui.dstColor.rgb, ui.dstColor.a);
|
||||
|
||||
ContextGather overlay;
|
||||
s2h_init(overlay, pixel);
|
||||
@@ -50,7 +49,7 @@ void main()
|
||||
s2h_printTxt(overlay, _r, _i, _g, _h, _t, _SPACE);
|
||||
s2h_printTxt(overlay, _M, _o, _u, _s, _e, _COLON);
|
||||
s2h_printTxt(overlay, _SPACE, _S, _c, _a, _l, _e);
|
||||
color = lerp(color, overlay.dstColor.rgb, overlay.dstColor.a);
|
||||
color = mix(color, overlay.dstColor.rgb, overlay.dstColor.a);
|
||||
|
||||
gl_FragColor = vec4(color, 1.0f);
|
||||
}
|
||||
|
||||
@@ -121,34 +121,36 @@ public:
|
||||
{
|
||||
program = BGFX_INVALID_HANDLE;
|
||||
}
|
||||
m_timeUniform = bgfx::createUniform("u_s2hTime", bgfx::UniformFreq::View, bgfx::UniformType::Vec4);
|
||||
m_uiStateUniform = bgfx::createUniform("u_s2hUiState", bgfx::UniformFreq::View, bgfx::UniformType::Vec4);
|
||||
m_colorUniform = bgfx::createUniform("u_s2hColor", bgfx::UniformFreq::View, bgfx::UniformType::Vec4);
|
||||
m_mouseUniform = bgfx::createUniform("u_s2hMouse", bgfx::UniformFreq::View, bgfx::UniformType::Vec4);
|
||||
m_zoomUniform = bgfx::createUniform("u_s2hZoom", bgfx::UniformFreq::View, bgfx::UniformType::Vec4);
|
||||
|
||||
m_program[0] = loadProgram("vs_s2h", "fs_s2h_3d");
|
||||
m_program[1] = loadProgram("vs_s2h", "fs_s2h_2d");
|
||||
m_program[2] = loadProgram("vs_s2h", "fs_s2h_gather");
|
||||
m_program[5] = loadProgram("vs_s2h", "fs_s2h_quadvsps");
|
||||
m_program[6] = loadProgram("vs_s2h", "fs_s2h_table");
|
||||
m_program[7] = loadProgram("vs_s2h", "fs_s2h_quadpost_scene");
|
||||
m_program[8] = loadProgram("vs_s2h", "fs_s2h_arrow");
|
||||
m_program[9] = loadProgram("vs_s2h", "fs_s2h_generate_user_font");
|
||||
m_timeUniform = bgfx::createUniform("u_s2hTime", bgfx::UniformFreq::Frame, bgfx::UniformType::Vec4);
|
||||
m_uiStateUniform = bgfx::createUniform("u_s2hUiState", bgfx::UniformFreq::Frame, bgfx::UniformType::Vec4);
|
||||
m_colorUniform = bgfx::createUniform("u_s2hColor", bgfx::UniformFreq::Frame, bgfx::UniformType::Vec4);
|
||||
m_mouseUniform = bgfx::createUniform("u_s2hMouse", bgfx::UniformFreq::Frame, bgfx::UniformType::Vec4);
|
||||
m_zoomUniform = bgfx::createUniform("u_s2hZoom", bgfx::UniformFreq::Frame, bgfx::UniformType::Vec4);
|
||||
m_scatterSizeUniform = bgfx::createUniform("u_s2hScatterSize", bgfx::UniformFreq::Frame, bgfx::UniformType::Vec4);
|
||||
m_quadPostSampler = bgfx::createUniform("s_quadPostColor", bgfx::UniformType::Sampler);
|
||||
m_scatterSampler = bgfx::createUniform("s_scatterColor", bgfx::UniformType::Sampler);
|
||||
|
||||
m_program[ 0] = loadProgram("vs_s2h", "fs_s2h_3d");
|
||||
m_program[ 1] = loadProgram("vs_s2h", "fs_s2h_2d");
|
||||
m_program[ 2] = loadProgram("vs_s2h", "fs_s2h_gather");
|
||||
m_program[ 5] = loadProgram("vs_s2h", "fs_s2h_quadvsps");
|
||||
m_program[ 6] = loadProgram("vs_s2h", "fs_s2h_table");
|
||||
m_program[ 7] = loadProgram("vs_s2h", "fs_s2h_quadpost_scene");
|
||||
m_program[ 8] = loadProgram("vs_s2h", "fs_s2h_arrow");
|
||||
m_program[ 9] = loadProgram("vs_s2h", "fs_s2h_generate_user_font");
|
||||
m_program[11] = loadProgram("vs_s2h", "fs_s2h_coordinate_system");
|
||||
m_program[12] = loadProgram("vs_s2h", "fs_s2h");
|
||||
m_program[13] = loadProgram("vs_s2h", "fs_s2h_screen");
|
||||
m_program[14] = loadProgram("vs_s2h", "fs_s2h_clear");
|
||||
m_program[15] = loadProgram("vs_s2h", "fs_s2h_zoom2d");
|
||||
m_quadPostProgram = loadProgram("vs_s2h", "fs_s2h_quadpost");
|
||||
m_userFontProgram = loadProgram("vs_s2h", "fs_s2h_use_user_font");
|
||||
m_debugZoomProgram = loadProgram("vs_s2h", "fs_s2h_debug_zoom");
|
||||
m_scatterClearProgram = loadProgram("cs_s2h_scatter_clear", NULL);
|
||||
m_scatterProgram = loadProgram("cs_s2h_scatter", NULL);
|
||||
m_quadPostProgram = loadProgram("vs_s2h", "fs_s2h_quadpost");
|
||||
m_userFontProgram = loadProgram("vs_s2h", "fs_s2h_use_user_font");
|
||||
m_debugZoomProgram = loadProgram("vs_s2h", "fs_s2h_debug_zoom");
|
||||
m_scatterClearProgram = loadProgram("cs_s2h_scatter_clear", NULL);
|
||||
m_scatterProgram = loadProgram("cs_s2h_scatter", NULL);
|
||||
m_scatterDisplayProgram = loadProgram("vs_s2h", "fs_s2h_scatter_display");
|
||||
m_quadPostSampler = bgfx::createUniform("s_quadPostColor", bgfx::UniformType::Sampler);
|
||||
m_scatterSampler = bgfx::createUniform("s_scatterColor", bgfx::UniformType::Sampler);
|
||||
m_scatterSizeUniform = bgfx::createUniform("u_s2hScatterSize", bgfx::UniformFreq::View, bgfx::UniformType::Vec4);
|
||||
|
||||
createQuadPostTarget();
|
||||
createScatterTarget();
|
||||
|
||||
@@ -159,6 +161,7 @@ public:
|
||||
int shutdown() override
|
||||
{
|
||||
imguiDestroy();
|
||||
|
||||
for (bgfx::ProgramHandle& program : m_program)
|
||||
{
|
||||
if (bgfx::isValid(program) )
|
||||
@@ -166,6 +169,7 @@ public:
|
||||
bgfx::destroy(program);
|
||||
}
|
||||
}
|
||||
|
||||
bgfx::destroy(m_quadPostProgram);
|
||||
bgfx::destroy(m_userFontProgram);
|
||||
bgfx::destroy(m_debugZoomProgram);
|
||||
@@ -183,7 +187,9 @@ public:
|
||||
bgfx::destroy(m_colorUniform);
|
||||
bgfx::destroy(m_mouseUniform);
|
||||
bgfx::destroy(m_zoomUniform);
|
||||
|
||||
bgfx::shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -201,6 +207,7 @@ public:
|
||||
showExampleDialog(this);
|
||||
|
||||
drawSettings();
|
||||
|
||||
if (2 == m_example)
|
||||
{
|
||||
updateGatherControls();
|
||||
@@ -219,6 +226,7 @@ public:
|
||||
0.0f,
|
||||
0.0f,
|
||||
};
|
||||
|
||||
const float uiState[] =
|
||||
{
|
||||
float(m_gatherRadio),
|
||||
@@ -226,6 +234,7 @@ public:
|
||||
m_gatherColor[3],
|
||||
0.0f,
|
||||
};
|
||||
|
||||
const float mouse[] =
|
||||
{
|
||||
float(m_mouseState.m_mx),
|
||||
@@ -233,6 +242,7 @@ public:
|
||||
m_gatherMouseDown ? 1.0f : 0.0f,
|
||||
0.0f,
|
||||
};
|
||||
|
||||
const float zoom[] =
|
||||
{
|
||||
m_zoomPan[0],
|
||||
@@ -240,18 +250,26 @@ public:
|
||||
m_zoomScale,
|
||||
0.0f,
|
||||
};
|
||||
|
||||
const bool originBottomLeft = bgfx::getCaps()->originBottomLeft;
|
||||
|
||||
const float scatterSize[] = { float(m_width), float(m_height), originBottomLeft ? 1.0f : 0.0f, 0.0f };
|
||||
|
||||
bgfx::setFrameUniform(m_timeUniform, time);
|
||||
bgfx::setFrameUniform(m_uiStateUniform, uiState);
|
||||
bgfx::setFrameUniform(m_colorUniform, m_gatherColor);
|
||||
bgfx::setFrameUniform(m_mouseUniform, mouse);
|
||||
bgfx::setFrameUniform(m_zoomUniform, zoom);
|
||||
bgfx::setFrameUniform(m_scatterSizeUniform, scatterSize);
|
||||
|
||||
if (4 == m_example)
|
||||
{
|
||||
const float scatterSize[] = { float(m_width), float(m_height), originBottomLeft ? 1.0f : 0.0f, 0.0f };
|
||||
const uint32_t dispatchWidth = (m_width + 7) / 8;
|
||||
const uint32_t dispatchHeight = (m_height + 7) / 8;
|
||||
|
||||
bgfx::setViewUniform(2, m_scatterSizeUniform, scatterSize);
|
||||
bgfx::setImage(0, m_scatterTexture, 0, bgfx::Access::Write, bgfx::TextureFormat::RGBA8);
|
||||
bgfx::dispatch(2, m_scatterClearProgram, uint16_t(dispatchWidth), uint16_t(dispatchHeight) );
|
||||
|
||||
bgfx::setViewUniform(3, m_scatterSizeUniform, scatterSize);
|
||||
bgfx::setImage(0, m_scatterTexture, 0, bgfx::Access::Write, bgfx::TextureFormat::RGBA8);
|
||||
bgfx::dispatch(3, m_scatterProgram, 1, 1);
|
||||
|
||||
@@ -265,12 +283,10 @@ public:
|
||||
bgfx::setViewFrameBuffer(0, m_quadPostFrameBuffer);
|
||||
bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewClear(0, BGFX_CLEAR_COLOR, 0x101018ff);
|
||||
bgfx::setViewUniform(0, m_timeUniform, time);
|
||||
renderScreenSpaceQuad(0, 10 == m_example ? m_program[9] : m_program[7]);
|
||||
|
||||
bgfx::setViewFrameBuffer(1, BGFX_INVALID_HANDLE);
|
||||
bgfx::setViewRect(1, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewUniform(1, m_mouseUniform, mouse);
|
||||
bgfx::setTexture(0, m_quadPostSampler, m_quadPostTexture);
|
||||
renderScreenSpaceQuad(1, 7 == m_example ? m_quadPostProgram : (10 == m_example ? m_userFontProgram : m_debugZoomProgram), originBottomLeft);
|
||||
}
|
||||
@@ -278,11 +294,7 @@ public:
|
||||
{
|
||||
bgfx::setViewFrameBuffer(0, BGFX_INVALID_HANDLE);
|
||||
bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) );
|
||||
bgfx::setViewUniform(0, m_timeUniform, time);
|
||||
bgfx::setViewUniform(0, m_uiStateUniform, uiState);
|
||||
bgfx::setViewUniform(0, m_colorUniform, m_gatherColor);
|
||||
bgfx::setViewUniform(0, m_mouseUniform, mouse);
|
||||
bgfx::setViewUniform(0, m_zoomUniform, zoom);
|
||||
|
||||
bgfx::touch(0);
|
||||
renderScreenSpaceQuad(0, m_program[m_example]);
|
||||
}
|
||||
@@ -417,8 +429,9 @@ public:
|
||||
{
|
||||
const int32_t mouseX = m_mouseState.m_mx;
|
||||
const int32_t mouseY = m_mouseState.m_my;
|
||||
const bool leftDown = m_mouseState.m_buttons[entry::MouseButton::Left];
|
||||
const bool leftDown = m_mouseState.m_buttons[entry::MouseButton::Left];
|
||||
const bool rightDown = m_mouseState.m_buttons[entry::MouseButton::Right];
|
||||
|
||||
if (ImGui::GetIO().WantCaptureMouse)
|
||||
{
|
||||
m_zoomLastMouseX = mouseX;
|
||||
@@ -450,6 +463,7 @@ public:
|
||||
uint32_t m_debug;
|
||||
uint32_t m_reset;
|
||||
int m_example = 0;
|
||||
|
||||
bgfx::ProgramHandle m_program[BX_COUNTOF(s_exampleNames)];
|
||||
bgfx::ProgramHandle m_quadPostProgram;
|
||||
bgfx::ProgramHandle m_userFontProgram;
|
||||
@@ -458,17 +472,21 @@ public:
|
||||
bgfx::ProgramHandle m_scatterProgram;
|
||||
bgfx::ProgramHandle m_scatterDisplayProgram;
|
||||
bgfx::TextureHandle m_quadPostTexture;
|
||||
|
||||
bgfx::FrameBufferHandle m_quadPostFrameBuffer;
|
||||
bgfx::UniformHandle m_quadPostSampler;
|
||||
bgfx::TextureHandle m_scatterTexture;
|
||||
|
||||
bgfx::UniformHandle m_quadPostSampler;
|
||||
bgfx::UniformHandle m_scatterSampler;
|
||||
bgfx::UniformHandle m_scatterSizeUniform;
|
||||
FrameTime m_frameTime;
|
||||
bgfx::UniformHandle m_timeUniform;
|
||||
bgfx::UniformHandle m_uiStateUniform;
|
||||
bgfx::UniformHandle m_colorUniform;
|
||||
bgfx::UniformHandle m_mouseUniform;
|
||||
bgfx::UniformHandle m_zoomUniform;
|
||||
|
||||
FrameTime m_frameTime;
|
||||
|
||||
int m_gatherRadio = 0;
|
||||
bool m_gatherCheckbox = false;
|
||||
bool m_gatherMouseDown = false;
|
||||
|
||||
6
examples/common/s2h/s2h.sh
Normal file
6
examples/common/s2h/s2h.sh
Normal file
@@ -0,0 +1,6 @@
|
||||
// S2H core library. The .hlsl sources are shared unchanged with HLSL
|
||||
// integrations, so this is the entry point a bgfx shader includes.
|
||||
|
||||
#include "s2h/s2h_bgfx.sh"
|
||||
#include "s2h/s2h.hlsl"
|
||||
|
||||
5
examples/common/s2h/s2h_3d.sh
Normal file
5
examples/common/s2h/s2h_3d.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
// S2H 3D module.
|
||||
|
||||
#include "s2h/s2h.sh"
|
||||
#include "s2h/s2h_3d.hlsl"
|
||||
|
||||
31
examples/common/s2h/s2h_bgfx.sh
Normal file
31
examples/common/s2h/s2h_bgfx.sh
Normal file
@@ -0,0 +1,31 @@
|
||||
// S2H bgfx shaderc compatibility adapter. For the S2H library itself include
|
||||
// s2h/s2h.sh, s2h/s2h_3d.sh or s2h/s2h_scatter.sh.
|
||||
|
||||
#ifndef S2H_BGFX_INCLUDE
|
||||
#define S2H_BGFX_INCLUDE
|
||||
|
||||
#include <bgfx_shader.sh>
|
||||
|
||||
#define S2H_BGFX 1
|
||||
#define S2H_LOOP LOOP
|
||||
|
||||
// shaderc's generated HLSL does not permit asfloat() in a global const
|
||||
// initializer.
|
||||
#define S2H_FLT_MAX 1.0e30f
|
||||
|
||||
#include "s2h/s2h_glsl.hlsl"
|
||||
|
||||
// S2H uses a top-left pixel origin; bgfx_ndc.z is the OpenGL origin sign.
|
||||
float2 s2h_getPixelCoord(float2 _fragmentCoord)
|
||||
{
|
||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
||||
return float2(
|
||||
_fragmentCoord.x
|
||||
, mix(_fragmentCoord.y, u_viewRect.w - _fragmentCoord.y, 0.5f * (bgfx_ndc.z + 1.0f))
|
||||
);
|
||||
#else
|
||||
return _fragmentCoord;
|
||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||
}
|
||||
|
||||
#endif // S2H_BGFX_INCLUDE
|
||||
@@ -14,32 +14,36 @@
|
||||
#define float3x3 mat3
|
||||
#define float4x4 mat4
|
||||
#define lerp mix
|
||||
// GLSL does not support static globals, while shaderc's non-GLSL targets
|
||||
// need static const declarations for expressions such as _a = _A + 32u.
|
||||
#if !defined(S2H_BGFX) || BGFX_SHADER_LANGUAGE_GLSL
|
||||
#define static
|
||||
#endif
|
||||
#define rsqrt(_x) (1.0f / sqrt(_x))
|
||||
// bgfx provides its own mul macro. It must remain in control so matrix
|
||||
// multiplication is translated correctly for every bgfx renderer.
|
||||
#ifndef S2H_BGFX
|
||||
#define mul(a,b) (a) * (b)
|
||||
#endif
|
||||
#if !defined(S2H_BGFX) || BGFX_SHADER_LANGUAGE_GLSL
|
||||
#define atan2 atan
|
||||
#endif
|
||||
// GLSL does not support static globals, while shaderc's non-GLSL targets
|
||||
// need static const declarations for expressions such as _a = _A + 32u.
|
||||
#if !defined(S2H_BGFX) || BGFX_SHADER_LANGUAGE_GLSL
|
||||
#define static
|
||||
#endif
|
||||
#define rsqrt(_x) (1.0f / sqrt(_x))
|
||||
// bgfx provides its own mul macro. It must remain in control so matrix
|
||||
// multiplication is translated correctly for every bgfx renderer.
|
||||
#ifndef S2H_BGFX
|
||||
#define mul(a,b) (a) * (b)
|
||||
#endif
|
||||
// bgfx supplies atan2 on GLSL, and it is native everywhere else.
|
||||
#ifndef S2H_BGFX
|
||||
#define atan2 atan
|
||||
#endif
|
||||
#define asuint floatBitsToUint
|
||||
#define asfloat uintBitsToFloat
|
||||
#endif
|
||||
|
||||
#define sincos(x,s,c) {s=sin(x);c=cos(x);}
|
||||
#define saturate(x) clamp(x,0.0f,1.0f)
|
||||
// bgfx maps GLSL's fract() to HLSL's frac() for non-GLSL targets. Defining
|
||||
// the inverse here on those targets creates a macro cycle that leaves fract()
|
||||
// in generated DX11 HLSL. The alias is only needed when compiling GLSL.
|
||||
#if !defined(S2H_BGFX) || BGFX_SHADER_LANGUAGE_GLSL
|
||||
#define frac(x) fract(x)
|
||||
#endif
|
||||
// bgfx supplies saturate on GLSL, and it is native everywhere else.
|
||||
#ifndef S2H_BGFX
|
||||
#define saturate(x) clamp(x,0.0f,1.0f)
|
||||
#endif
|
||||
// bgfx maps GLSL's fract() to HLSL's frac() for non-GLSL targets. Defining
|
||||
// the inverse here on those targets creates a macro cycle that leaves fract()
|
||||
// in generated DX11 HLSL. The alias is only needed when compiling GLSL.
|
||||
#if !defined(S2H_BGFX) || BGFX_SHADER_LANGUAGE_GLSL
|
||||
#define frac(x) fract(x)
|
||||
#endif
|
||||
#define groupshared shared
|
||||
#define WaveActiveSum subgroupAdd
|
||||
#define WaveGetLaneCount() gl_SubgroupSize
|
||||
5
examples/common/s2h/s2h_scatter.sh
Normal file
5
examples/common/s2h/s2h_scatter.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
// S2H scatter module.
|
||||
|
||||
#include "s2h/s2h.sh"
|
||||
#include "s2h/s2h_scatter.hlsl"
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Shader To Human (S2H) - bgfx shaderc compatibility adapter //
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Include bgfx's common shader header before this adapter. It provides
|
||||
// shaderc's portable mul() and LOOP macros used by S2H.
|
||||
//
|
||||
// #include "common.sh"
|
||||
// #include "s2h_bgfx.sh"
|
||||
// #include "s2h.hlsl"
|
||||
//
|
||||
// The S2H source files retain their HLSL extension so they can be shared
|
||||
// unchanged with existing HLSL integrations.
|
||||
|
||||
#ifndef S2H_BGFX_INCLUDE
|
||||
#define S2H_BGFX_INCLUDE
|
||||
|
||||
#define S2H_BGFX 1
|
||||
#define S2H_LOOP LOOP
|
||||
|
||||
// shaderc's generated HLSL does not permit asfloat() in a global const
|
||||
// initializer. This finite value is far beyond any practical scene depth and
|
||||
// remains a literal expression on every shaderc backend.
|
||||
#define S2H_FLT_MAX 1.0e30f
|
||||
|
||||
#include "s2h_glsl.hlsl"
|
||||
|
||||
// S2H examples use a top-left pixel origin to match their source tools and
|
||||
// host mouse coordinates. u_viewRect is supplied by bgfx for every view;
|
||||
// bgfx_ndc.z is the OpenGL origin sign (and is substituted by the GL renderer).
|
||||
float2 s2h_getPixelCoord(float2 _fragmentCoord)
|
||||
{
|
||||
#if BGFX_SHADER_LANGUAGE_GLSL
|
||||
return float2(
|
||||
_fragmentCoord.x
|
||||
, mix(_fragmentCoord.y, u_viewRect.w - _fragmentCoord.y, 0.5f * (bgfx_ndc.z + 1.0f))
|
||||
);
|
||||
#else
|
||||
return _fragmentCoord;
|
||||
#endif // BGFX_SHADER_LANGUAGE_GLSL
|
||||
}
|
||||
|
||||
#endif // S2H_BGFX_INCLUDE
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
examples/runtime/shaders/essl/cs_s2h_scatter.bin
Normal file
BIN
examples/runtime/shaders/essl/cs_s2h_scatter.bin
Normal file
Binary file not shown.
BIN
examples/runtime/shaders/essl/cs_s2h_scatter_clear.bin
Normal file
BIN
examples/runtime/shaders/essl/cs_s2h_scatter_clear.bin
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user