corregides les scanlines per a paletes amb fondo blanc
This commit is contained in:
@@ -131,7 +131,11 @@ if(NOT APPLE)
|
|||||||
if(GLSLC_EXE)
|
if(GLSLC_EXE)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${SHADER_VERT_H}" "${SHADER_FRAG_H}"
|
OUTPUT "${SHADER_VERT_H}" "${SHADER_FRAG_H}"
|
||||||
COMMAND "${CMAKE_SOURCE_DIR}/tools/shaders/compile_spirv.sh"
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-D GLSLC=${GLSLC_EXE}
|
||||||
|
-D SHADERS_DIR=${CMAKE_SOURCE_DIR}/data/shaders
|
||||||
|
-D HEADERS_DIR=${CMAKE_SOURCE_DIR}/source/core/rendering/sdl3gpu
|
||||||
|
-P ${CMAKE_SOURCE_DIR}/tools/shaders/compile_spirv.cmake
|
||||||
DEPENDS "${SHADER_VERT_SRC}" "${SHADER_FRAG_SRC}"
|
DEPENDS "${SHADER_VERT_SRC}" "${SHADER_FRAG_SRC}"
|
||||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||||
COMMENT "Compilando shaders SPIR-V..."
|
COMMENT "Compilando shaders SPIR-V..."
|
||||||
|
|||||||
@@ -101,12 +101,13 @@ void main() {
|
|||||||
// calcular la posición dentro de la fila en coordenadas físicas.
|
// calcular la posición dentro de la fila en coordenadas físicas.
|
||||||
// 3x: 1 dark + 2 bright. 4x: 1 dark + 3 bright.
|
// 3x: 1 dark + 2 bright. 4x: 1 dark + 3 bright.
|
||||||
// bright=3.5×, dark floor=0.42 (mantiene aspecto CRT original).
|
// bright=3.5×, dark floor=0.42 (mantiene aspecto CRT original).
|
||||||
|
// ** MOD ** bright=1.0×, dark floor=0.42 (mantiene aspecto CRT original).
|
||||||
if (u.scanline_strength > 0.0) {
|
if (u.scanline_strength > 0.0) {
|
||||||
float ps = max(1.0, round(u.pixel_scale));
|
float ps = max(1.0, round(u.pixel_scale));
|
||||||
float frac_in_row = fract(uv.y * u.screen_height);
|
float frac_in_row = fract(uv.y * u.screen_height);
|
||||||
float row_pos = floor(frac_in_row * ps);
|
float row_pos = floor(frac_in_row * ps);
|
||||||
float is_dark = step(ps - 1.0, row_pos);
|
float is_dark = step(ps - 1.0, row_pos);
|
||||||
float scan = mix(3.5, 0.42, is_dark);
|
float scan = mix(1.0, 0.42, is_dark);
|
||||||
colour *= mix(1.0, scan, u.scanline_strength);
|
colour *= mix(1.0, scan, u.scanline_strength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1445,5 +1445,6 @@ static const uint8_t kpostfx_vert_spv[] = {
|
|||||||
0x38,
|
0x38,
|
||||||
0x00,
|
0x00,
|
||||||
0x01,
|
0x01,
|
||||||
0x00};
|
0x00,
|
||||||
|
};
|
||||||
static const size_t kpostfx_vert_spv_size = 1444;
|
static const size_t kpostfx_vert_spv_size = 1444;
|
||||||
|
|||||||
@@ -135,12 +135,14 @@ fragment float4 postfx_fs(PostVOut in [[stage_in]],
|
|||||||
// calcular la posición dentro de la fila en coordenadas físicas.
|
// calcular la posición dentro de la fila en coordenadas físicas.
|
||||||
// 3x: 1 dark + 2 bright. 4x: 1 dark + 3 bright.
|
// 3x: 1 dark + 2 bright. 4x: 1 dark + 3 bright.
|
||||||
// bright=3.5×, dark floor=0.42 (mantiene aspecto CRT original).
|
// bright=3.5×, dark floor=0.42 (mantiene aspecto CRT original).
|
||||||
|
// ** MOD ** bright=1.0×, dark floor=0.42 (mantiene aspecto CRT original).
|
||||||
if (u.scanline_strength > 0.0f) {
|
if (u.scanline_strength > 0.0f) {
|
||||||
float ps = max(1.0f, round(u.pixel_scale));
|
float ps = max(1.0f, round(u.pixel_scale));
|
||||||
float frac_in_row = fract(uv.y * u.screen_height);
|
float frac_in_row = fract(uv.y * u.screen_height);
|
||||||
float row_pos = floor(frac_in_row * ps);
|
float row_pos = floor(frac_in_row * ps);
|
||||||
float is_dark = step(ps - 1.0f, row_pos);
|
float is_dark = step(ps - 1.0f, row_pos);
|
||||||
float scan = mix(3.5f, 0.42f, is_dark);
|
//float scan = mix(3.5f, 0.42f, is_dark);
|
||||||
|
float scan = mix(1.0f, 0.42f, is_dark);
|
||||||
colour *= mix(1.0f, scan, u.scanline_strength);
|
colour *= mix(1.0f, scan, u.scanline_strength);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,10 +390,10 @@ namespace Rendering {
|
|||||||
std::memcpy(mapped, pixels, static_cast<size_t>(width * height * 4));
|
std::memcpy(mapped, pixels, static_cast<size_t>(width * height * 4));
|
||||||
} else {
|
} else {
|
||||||
// Path con supersampling: expande cada pixel a OS×OS, oscurece última fila.
|
// Path con supersampling: expande cada pixel a OS×OS, oscurece última fila.
|
||||||
// Replica la fórmula del shader: mix(3.5, 0.42, scanline_strength).
|
// Replica la fórmula del shader: mix(1.0, 0.42, scanline_strength).
|
||||||
auto* out = static_cast<Uint32*>(mapped);
|
auto* out = static_cast<Uint32*>(mapped);
|
||||||
const int OS = oversample_;
|
const int OS = oversample_;
|
||||||
const float BRIGHT_MUL = 1.0F + (baked_scanline_strength_ * 2.5F); // rows 0..OS-2
|
const float BRIGHT_MUL = 1.0F; // rows 0..OS-2 (bright = 1.0×, sin amplificación)
|
||||||
const float DARK_MUL = 1.0F - (baked_scanline_strength_ * 0.58F); // row OS-1
|
const float DARK_MUL = 1.0F - (baked_scanline_strength_ * 0.58F); // row OS-1
|
||||||
|
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
|
|||||||
55
tools/shaders/compile_spirv.cmake
Normal file
55
tools/shaders/compile_spirv.cmake
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# compile_spirv.cmake
|
||||||
|
# Compila shaders GLSL a SPIR-V y genera headers C++ embebibles.
|
||||||
|
# Multiplataforma: Windows, macOS, Linux (no requiere bash, xxd ni /tmp/).
|
||||||
|
#
|
||||||
|
# Invocado por CMakeLists.txt con:
|
||||||
|
# cmake -D GLSLC=<path> -D SHADERS_DIR=<path> -D HEADERS_DIR=<path> -P compile_spirv.cmake
|
||||||
|
#
|
||||||
|
# También puede ejecutarse manualmente desde la raíz del proyecto:
|
||||||
|
# cmake -D GLSLC=glslc -D SHADERS_DIR=data/shaders -D HEADERS_DIR=source/core/rendering/sdl3gpu -P tools/shaders/compile_spirv.cmake
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
foreach(SHADER vert frag)
|
||||||
|
set(SRC "${SHADERS_DIR}/postfx.${SHADER}")
|
||||||
|
set(SPV "${HEADERS_DIR}/postfx_${SHADER}.spv")
|
||||||
|
set(HDR "${HEADERS_DIR}/postfx_${SHADER}_spv.h")
|
||||||
|
set(VAR "kpostfx_${SHADER}_spv")
|
||||||
|
|
||||||
|
message(STATUS "Compilando ${SRC} ...")
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${GLSLC}" "${SRC}" -o "${SPV}"
|
||||||
|
RESULT_VARIABLE GLSLC_RESULT
|
||||||
|
ERROR_VARIABLE GLSLC_ERROR
|
||||||
|
)
|
||||||
|
if(NOT GLSLC_RESULT EQUAL 0)
|
||||||
|
message(FATAL_ERROR "glslc falló para ${SRC}:\n${GLSLC_ERROR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Leer binario SPV como hex (sin separadores: "0302230700...")
|
||||||
|
file(READ "${SPV}" HEX_DATA HEX)
|
||||||
|
# Dividir en pares de caracteres hex → lista de bytes
|
||||||
|
string(REGEX MATCHALL ".." BYTES "${HEX_DATA}")
|
||||||
|
list(LENGTH BYTES NUM_BYTES)
|
||||||
|
|
||||||
|
# Construir el cuerpo del array C++ con un byte por línea
|
||||||
|
set(ARRAY_BODY "")
|
||||||
|
foreach(BYTE ${BYTES})
|
||||||
|
string(APPEND ARRAY_BODY " 0x${BYTE},\n")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
file(WRITE "${HDR}"
|
||||||
|
"#pragma once\n"
|
||||||
|
"#include <cstddef>\n"
|
||||||
|
"#include <cstdint>\n"
|
||||||
|
"static const uint8_t ${VAR}[] = {\n"
|
||||||
|
"${ARRAY_BODY}"
|
||||||
|
"};\n"
|
||||||
|
"static const size_t ${VAR}_size = ${NUM_BYTES};\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
file(REMOVE "${SPV}")
|
||||||
|
message(STATUS " -> ${HDR} (${NUM_BYTES} bytes)")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
message(STATUS "Shaders SPIR-V compilados correctamente.")
|
||||||
Reference in New Issue
Block a user