Add an initial rhi implementation that mimics the opengl implementation

This commit is contained in:
luisangelsm
2026-01-17 22:46:27 +01:00
parent 91b8a31727
commit 3381754c12
25 changed files with 2739 additions and 21 deletions

View File

@ -0,0 +1,49 @@
# YACReader Flow RHI Shaders
This directory contains the GLSL 4.50 shaders for the QRhiWidget-based flow implementation.
## Files
- `flow.vert` - Vertex shader (GLSL 450)
- `flow.frag` - Fragment shader (GLSL 450)
- `flow.vert.qsb` - Compiled vertex shader (multi-platform)
- `flow.frag.qsb` - Compiled fragment shader (multi-platform)
- `compile_shaders.bat` - Windows compilation script
- `compile_shaders.sh` - Unix/macOS compilation script
- `shaders.qrc` - Qt resource file
## Compiling Shaders
The shaders must be compiled to `.qsb` format using Qt's `qsb` tool before building YACReader.
### Prerequisites
Ensure `qsb` is in your PATH. It's typically located in:
- Windows: `C:\Qt\6.x.x\msvc2019_64\bin\qsb.exe`
- macOS: `/opt/Qt/6.x.x/macos/bin/qsb`
- Linux: `/opt/Qt/6.x.x/gcc_64/bin/qsb`
### Compilation
**Windows:**
```cmd
cd common/rhi/shaders
compile_shaders.bat
```
**Unix/macOS:**
```bash
cd common/rhi/shaders
chmod +x compile_shaders.sh
./compile_shaders.sh
```
The compiled `.qsb` files contain shader variants for:
- OpenGL ES 2.0, 3.0
- OpenGL 2.1, 3.0+
- HLSL (Direct3D 11/12)
- Metal Shading Language (macOS/iOS)
## Note
The `.qsb` files are included in the repository for convenience. Recompile only if you modify the shader source.

View File

@ -0,0 +1,19 @@
@echo off
REM Compile shaders to .qsb format for Qt RHI
REM Requires qsb tool from Qt installation
echo Compiling flow vertex shader...
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o flow.vert.qsb flow.vert
if %ERRORLEVEL% NEQ 0 (
echo Error compiling vertex shader
exit /b 1
)
echo Compiling flow fragment shader...
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o flow.frag.qsb flow.frag
if %ERRORLEVEL% NEQ 0 (
echo Error compiling fragment shader
exit /b 1
)
echo Shader compilation complete!

View File

@ -0,0 +1,19 @@
#!/bin/bash
# Compile shaders to .qsb format for Qt RHI
# Requires qsb tool from Qt installation
echo "Compiling flow vertex shader..."
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o flow.vert.qsb flow.vert
if [ $? -ne 0 ]; then
echo "Error compiling vertex shader"
exit 1
fi
echo "Compiling flow fragment shader..."
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o flow.frag.qsb flow.frag
if [ $? -ne 0 ]; then
echo "Error compiling fragment shader"
exit 1
fi
echo "Shader compilation complete!"

View File

@ -0,0 +1,44 @@
#version 450
// Inputs from vertex shader
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec4 vColor;
layout(location = 2) in float vIsReflection;
// Output
layout(location = 0) out vec4 fragColor;
// Uniform buffer
layout(std140, binding = 0) uniform UniformBuffer
{
mat4 viewProjectionMatrix;
vec3 backgroundColor;
float _pad0;
vec3 shadingColor;
float _pad1;
float reflectionUp;
float reflectionDown;
int isReflection;
float _pad2;
};
// Texture and sampler
layout(binding = 1) uniform sampler2D coverTexture;
void main()
{
vec4 texColor = texture(coverTexture, vTexCoord);
// Apply shading: multiply texture by vColor.r to darken
float shadingAmount = vColor.r;
// For reflections, apply gradient fade (darker at bottom, fading to black)
if (vIsReflection > 0.5) {
// vTexCoord.y goes from 1 (top of reflection, near cover) to 0 (bottom, far from cover)
// We want it brightest near the cover and fading away
float gradientFade = mix(0.0, 0.33, vTexCoord.y);
shadingAmount *= gradientFade;
}
fragColor = vec4(texColor.rgb * shadingAmount, texColor.a);
}

Binary file not shown.

View File

@ -0,0 +1,59 @@
#version 450
// Per-vertex attributes
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 texCoord;
// Per-instance attributes (mat4 split into 4 vec4s for better D3D11 compatibility)
layout(location = 2) in vec4 instanceModel_row0;
layout(location = 3) in vec4 instanceModel_row1;
layout(location = 4) in vec4 instanceModel_row2;
layout(location = 5) in vec4 instanceModel_row3;
layout(location = 6) in vec4 instanceShading1;
layout(location = 7) in float instanceOpacity;
layout(location = 8) in float instanceFlip;
// Outputs to fragment shader
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out vec4 vColor;
layout(location = 2) out float vIsReflection;
// Uniform buffer
layout(std140, binding = 0) uniform UniformBuffer
{
mat4 viewProjectionMatrix;
vec3 backgroundColor;
float _pad0;
vec3 shadingColor;
float _pad1;
float reflectionUp;
float reflectionDown;
int isReflection;
float _pad2;
};
void main()
{
// Reconstruct instance model matrix from 4 vec4 rows
mat4 instanceModel = mat4(instanceModel_row0, instanceModel_row1, instanceModel_row2, instanceModel_row3);
gl_Position = viewProjectionMatrix * instanceModel * vec4(position, 1.0);
vTexCoord = texCoord;
// Flip texture vertically per-instance when requested (reflection)
if (instanceFlip != 0.0) {
vTexCoord.y = 1.0 - texCoord.y;
}
float leftUpShading = instanceShading1.x;
float leftDownShading = instanceShading1.y;
float rightUpShading = instanceShading1.z;
float rightDownShading = instanceShading1.w;
float leftShading = mix(leftDownShading, leftUpShading, (position.y + 0.5));
float rightShading = mix(rightDownShading, rightUpShading, (position.y + 0.5));
float shading = mix(leftShading, rightShading, (position.x + 0.5));
vColor = vec4(shading * instanceOpacity);
vIsReflection = instanceFlip;
}

Binary file not shown.

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/shaders">
<file>flow.vert.qsb</file>
<file>flow.frag.qsb</file>
</qresource>
</RCC>