5 Commits

Author SHA1 Message Date
Ray
8783e66e21 Update rlsw.h 2026-03-19 23:42:20 +01:00
7ae46fb2e6 [rlsw] Micro-optimizations, tighter pipeline and cleanup (#5673)
* auto generates all combinations of blending factors
This adds a macro system that generate a function for each possible combination of blending factors, resulting in 11*11 functions, hence 121.
This then allows for only one indirection and function call instead of two previously (assuming the first call was inlined).

* rename dispatch tables for consistency

* change blend funcs validity check
Simplifies the validation of blend functions.
Can allow `SW_SRC_ALPHA_SATURATE` as dst factor, but hey

* disables blending when it requires alpha and there is none

* review immediate rendering functions and attribute layout

* prevent state changes during immediate record

* reduce number of op for each vertex push + review primitive struct

* simplified draw functions

* review `sw_vertex_t`
removes `float screen[2]`; each step stores the transformed coordinates in `float coord[4]`.
This also simplifies vertex interpolation during triangle rasterization.

* reduces unnecessary interpolation costs during triangle rasterization + cleanup

* extends the simd color conversion to more cases

* affine interpolation per blocks

* long side check for each triangle line
My mistake in a previous commit

* style tweaks

* select the read function on texture load
This removes the per-pixel switch; it's slightly more efficient on my hardware, but probably a poor prediction
Should remain profitable or at worst the same

* use optionnal LUT for uint8_t -> float conversion

* sets internal the number of vertices post-clipping and the epsilon clipping + a little cleanup

* moves color conversion to math part

* prevents sampling if it's a depth texture that is bound
2026-03-19 23:39:52 +01:00
Ray
04c5dc4493 REVIEWED: PR #5674 2026-03-19 23:35:18 +01:00
bca4f83a02 required change for ESP-IDF 6 (#5674) 2026-03-19 23:19:44 +01:00
7fef65a3fe Make fogColor in the fog tutorial a parameter (#5672)
* uniform fogColor

fogColor is now a parameter

* use new fog color parameter

* convert ambient to Vector4
2026-03-19 23:17:27 +01:00
4 changed files with 1267 additions and 1113 deletions

View File

@ -37,6 +37,7 @@ struct Light {
uniform Light lights[MAX_LIGHTS];
uniform vec4 ambient;
uniform vec3 viewPos;
uniform vec4 fogColor;
uniform float fogDensity;
void main()
@ -77,10 +78,6 @@ void main()
// Fog calculation
float dist = length(viewPos - fragPosition);
// these could be parameters...
const vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0);
//const float fogDensity = 0.16;
// Exponential fog
float fogFactor = 1.0/exp((dist*fogDensity)*(dist*fogDensity));

View File

@ -72,8 +72,13 @@ int main(void)
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
// Ambient light level
Vector4 ambient = (Vector4){ 0.2f, 0.2f, 0.2f, 1.0f };
int ambientLoc = GetShaderLocation(shader, "ambient");
SetShaderValue(shader, ambientLoc, (float[4]){ 0.2f, 0.2f, 0.2f, 1.0f }, SHADER_UNIFORM_VEC4);
SetShaderValue(shader, ambientLoc, &ambient, SHADER_UNIFORM_VEC4);
Vector4 fogColor = ColorNormalize(GRAY);
int fogColorLoc = GetShaderLocation(shader, "fogColor");
SetShaderValue(shader, fogColorLoc, &fogColor, SHADER_UNIFORM_VEC4);
float fogDensity = 0.15f;
int fogDensityLoc = GetShaderLocation(shader, "fogDensity");

2358
src/external/rlsw.h vendored

File diff suppressed because it is too large Load Diff

View File

@ -682,6 +682,16 @@ void InitWindow(int width, int height, const char *title)
TRACELOG(LOG_WARNING, "SYSTEM: Failed to initialize platform");
return;
}
// Initialize render dimensions for embedded platforms
// NOTE: On desktop platforms (GLFW, SDL, etc.), CORE.Window.render.width/height are set during window creation
// On embedded platforms with no window manager, InitPlatform() doesn't set these values, so they should be initialized
// here from screen dimensions (which are set from the InitWindow parameters)
if ((CORE.Window.render.width == 0) || (CORE.Window.render.height == 0))
{
CORE.Window.render.width = CORE.Window.screen.width;
CORE.Window.render.height = CORE.Window.screen.height;
}
//--------------------------------------------------------------
// Initialize rlgl default data (buffers and shaders)