Skip to content

Commit

Permalink
color math adjustments
Browse files Browse the repository at this point in the history
- set pixel32 as a typedef
- adjust member names in real_argb_color and real_rgb_color
  • Loading branch information
Berthalamew committed Dec 1, 2024
1 parent 5237eba commit a388a8e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 43 deletions.
8 changes: 4 additions & 4 deletions xlive/Blam/Engine/cartographer/tag_fixes/tag_fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ static void tag_fixes_brute(void)
if (brute_shader_index != NONE && brute_head_shader_index != NONE)
{
s_shader_definition* shader = (s_shader_definition*)tag_get_fast(brute_shader_index);
shader->postprocess_definition[0]->pixel_constants[0]->color = D3DCOLOR_RGBA(87, 79, 69, 0);
shader->postprocess_definition[0]->pixel_constants[1]->color = D3DCOLOR_RGBA(180, 179, 189, 0);
*shader->postprocess_definition[0]->pixel_constants[0] = D3DCOLOR_RGBA(87, 79, 69, 0);
*shader->postprocess_definition[0]->pixel_constants[1] = D3DCOLOR_RGBA(180, 179, 189, 0);

shader = (s_shader_definition*)tag_get_fast(brute_head_shader_index);
shader->postprocess_definition[0]->pixel_constants[0]->color = D3DCOLOR_RGBA(255, 255, 255, 0);
shader->postprocess_definition[0]->pixel_constants[1]->color = D3DCOLOR_RGBA(180, 179, 189, 0);
*shader->postprocess_definition[0]->pixel_constants[0] = D3DCOLOR_RGBA(255, 255, 255, 0);
*shader->postprocess_definition[0]->pixel_constants[1] = D3DCOLOR_RGBA(180, 179, 189, 0);
}
return;
}
Expand Down
3 changes: 1 addition & 2 deletions xlive/Blam/Engine/interface/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ void render_splitscreen_line(void)
const int32 line_size = resolution_y / 480;

rectangle2d line;
pixel32 color;
color.color = k_splitscreen_line_colour;
pixel32 color = k_splitscreen_line_colour;
if (player_window_count > 1)
{
if (get_display_split_type() == _display_split_type_horizontal)
Expand Down
18 changes: 8 additions & 10 deletions xlive/Blam/Engine/math/color_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,18 @@ const real_rgb_color* const global_real_rgb_darkgreen = &global_real_argb_color_
const real_rgb_color* const global_real_rgb_salmon = &global_real_argb_color_table[15].rgb;
const real_rgb_color* const global_real_rgb_violet = &global_real_argb_color_table[16].rgb;

const pixel32 global_white_pixel32 = { D3DCOLOR_ARGB(255, 255, 255, 255) };
const pixel32 global_yellow_pixel32 = { D3DCOLOR_ARGB(255, 255, 255, 0) };
const pixel32 global_white_pixel32 = D3DCOLOR_ARGB(255, 255, 255, 255);
const pixel32 global_yellow_pixel32 = D3DCOLOR_ARGB(255, 255, 255, 0);

/* public code */

pixel32 real_argb_color_to_pixel32(const real_argb_color* color)
{
pixel32 result = { D3DCOLOR_ARGB(
(int32)(color->alpha * 255),
(int32)(color->red * 255),
(int32)(color->green * 255),
(int32)(color->blue * 255)
) };
return result;
return D3DCOLOR_ARGB(
(int32)(color->alpha * 255),
(int32)(color->red * 255),
(int32)(color->green * 255),
(int32)(color->blue * 255));
}

void pixel32_to_real_rgb_color(pixel32 pixel_color, real_rgb_color* out_color)
Expand All @@ -85,6 +83,6 @@ void pixel32_to_real_rgb_color(pixel32 pixel_color, real_rgb_color* out_color)
pixel32 real_alpha_to_pixel32(real32 alpha)
{
ASSERT(alpha >= 0.f && alpha <= 1.f);
pixel32 color = { (int32)(alpha * 255.f) << 24 };
pixel32 color = (int32)(alpha * 255.f) << 24;
return color;
}
10 changes: 3 additions & 7 deletions xlive/Blam/Engine/math/color_math.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#pragma once

/* structures */
struct pixel32
{
D3DCOLOR color;
};
ASSERT_STRUCT_SIZE(pixel32, sizeof(uint8) * 4);
typedef D3DCOLOR pixel32;

union real_rgb_color
{
real32 v[3];
real32 n[3];
struct { real32 red, green, blue; };
};
ASSERT_STRUCT_SIZE(real_rgb_color, sizeof(real32) * 3);

/* channel intensity is represented on a 0 to 1 scale */
union real_argb_color
{
real32 v[4];
real32 n[4];
struct
{
real32 alpha;
Expand Down
2 changes: 1 addition & 1 deletion xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void rasterizer_dx9_perf_event_begin(const char* event_description, real_argb_co

// If color is null set the color of the event to white
pixel32 d3dcolor = (color ? real_argb_color_to_pixel32(color) : global_white_pixel32 );
D3DPERF_BeginEvent(d3dcolor.color, (LPCWSTR)wide_string);
D3DPERF_BeginEvent(d3dcolor, (LPCWSTR)wide_string);
#endif
return;
}
Expand Down
4 changes: 2 additions & 2 deletions xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_fog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool __cdecl rasterizer_dx9_atmospheric_fog_pipeline_setup(void* data)
rasterizer_dx9_set_render_state(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA);
rasterizer_dx9_set_render_state(D3DRS_ALPHABLENDENABLE, TRUE);
rasterizer_dx9_set_render_state(D3DRS_SRCBLEND, D3DBLEND_BLENDFACTOR);
rasterizer_dx9_set_render_state(D3DRS_BLENDFACTOR, global_white_pixel32.color);
rasterizer_dx9_set_render_state(D3DRS_BLENDFACTOR, global_white_pixel32);
rasterizer_dx9_set_render_state(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
rasterizer_dx9_set_render_state(D3DRS_BLENDOP, D3DBLENDOP_ADD);
rasterizer_dx9_set_render_state(D3DRS_ALPHATESTENABLE, FALSE);
Expand Down Expand Up @@ -159,7 +159,7 @@ bool rasterizer_dx9_patchy_fog_apply_separate_layers_pipeline_setup(void* data)
rasterizer_dx9_set_render_state(D3DRS_SRCBLEND, D3DBLEND_BLENDFACTOR);
rasterizer_dx9_set_render_state(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
rasterizer_dx9_set_render_state(D3DRS_BLENDOP, D3DBLENDOP_ADD);
rasterizer_dx9_set_render_state(D3DRS_BLENDFACTOR, global_white_pixel32.color);
rasterizer_dx9_set_render_state(D3DRS_BLENDFACTOR, global_white_pixel32);
rasterizer_dx9_set_render_state(D3DRS_ALPHATESTENABLE, false);
rasterizer_dx9_set_render_state(D3DRS_CULLMODE, D3DCULL_NONE);
rasterizer_dx9_set_render_state(D3DRS_ZENABLE, FALSE);
Expand Down
15 changes: 7 additions & 8 deletions xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ static const D3DPOOL** g_d3d9_texture_pool_get(void);
static const uint32** g_d3d9_vertex_usage_get(void);
static const D3DPOOL** g_d3d9_vertex_pool_get(void);

static void __cdecl rasterizer_dx9_clear_target(uint32 flags, D3DCOLOR color, real32 z, bool stencil);
static void __cdecl rasterizer_set_stream_source(void);
static void __cdecl debug_frame_usage_draw(void);
static void __cdecl rasterizer_present_backbuffer(void);
Expand Down Expand Up @@ -342,7 +341,7 @@ void rasterizer_dx9_present(bitmap_data* screenshot_bitmap, bool a2)
result = false;
}
rasterizer_dx9_set_render_target_internal(dx9_globals->global_d3d_surface_render_primary, (IDirect3DSurface9*)NONE, true);
rasterizer_dx9_clear_target(0, global_white_pixel32.color, 0.0f, false);
rasterizer_dx9_clear_render_target(0, global_white_pixel32, 0.0f, false);
}

rasterizer_set_stream_source();
Expand Down Expand Up @@ -892,6 +891,12 @@ bool __cdecl rasterizer_dx9_render_scene_end(void)
return INVOKE(0x262215, 0x0, rasterizer_dx9_render_scene_end);
}

void __cdecl rasterizer_dx9_clear_render_target(uint32 flags, D3DCOLOR color, real32 z, bool stencil)
{
INVOKE(0x25FC2A, 0x0, rasterizer_dx9_clear_render_target, flags, color, z, stencil);
return;
}

/* private code */

static PALETTEENTRY* g_d3d_palettes_get(void)
Expand Down Expand Up @@ -929,12 +934,6 @@ static const D3DPOOL** g_d3d9_vertex_pool_get(void)
return Memory::GetAddress<const D3DPOOL**>(0xA3C634);
}

static void __cdecl rasterizer_dx9_clear_target(uint32 flags, D3DCOLOR color, real32 z, bool stencil)
{
INVOKE(0x25FC2A, 0x0, rasterizer_dx9_clear_target, flags, color, z, stencil);
return;
}

static void __cdecl rasterizer_set_stream_source(void)
{
INVOKE(0x26F4D3, 0x0, rasterizer_set_stream_source);
Expand Down
16 changes: 8 additions & 8 deletions xlive/Blam/Engine/rasterizer/dx9/rasterizer_dx9_weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool __cdecl rasterizer_dx9_weather_plate_setup_pipeline(const c_animated_backgr
rasterizer_dx9_set_render_state(D3DRS_SRCBLEND, D3DBLEND_BLENDFACTOR);
rasterizer_dx9_set_render_state(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
rasterizer_dx9_set_render_state(D3DRS_BLENDOP, D3DBLENDOP_ADD);
rasterizer_dx9_set_render_state(D3DRS_BLENDFACTOR, global_white_pixel32.color);
rasterizer_dx9_set_render_state(D3DRS_BLENDFACTOR, global_white_pixel32);
rasterizer_dx9_set_render_state(D3DRS_ZENABLE, FALSE);
rasterizer_dx9_set_render_state(D3DRS_ZWRITEENABLE, FALSE);
rasterizer_dx9_set_render_state(D3DRS_ZFUNC, D3DCMP_ALWAYS); // D3DCMP_LESSEQUAL on xbox?
Expand Down Expand Up @@ -194,15 +194,15 @@ bool rasterizer_dx9_draw_weather_particles(c_particle_system_lite* system)
rasterizer_dx9_initialize_camera_projection(false, &global_window_parameters->camera, &global_window_parameters->projection, *rasterizer_dx9_main_render_target_get());

real_vector2d rain_vector;
pixel32 lower_rain_color;
pixel32 upper_rain_color;
pixel32 lower_rain_alpha;
pixel32 upper_rain_alpha;
if (is_rain)
{
rain_vector.i = global_window_parameters->camera.forward.i;
rain_vector.j = global_window_parameters->camera.forward.j;

lower_rain_color = real_alpha_to_pixel32(system->m_opacity.lower);
upper_rain_color = real_alpha_to_pixel32(system->m_opacity.upper);
lower_rain_alpha = real_alpha_to_pixel32(system->m_opacity.lower);
upper_rain_alpha = real_alpha_to_pixel32(system->m_opacity.upper);
}
else
{
Expand Down Expand Up @@ -251,20 +251,20 @@ bool rasterizer_dx9_draw_weather_particles(c_particle_system_lite* system)
current_primitive->position.y = render_data->m_position.y - update_data->m_velocity.j * scale * dt;
current_primitive->position.z = render_data->m_position.z - update_data->m_velocity.k * scale * dt;
current_primitive->scale = 1.f;
current_primitive->color = { lower_rain_color.color | render_data->m_color.color & 0x00FFFFFF };
current_primitive->color = { lower_rain_alpha| render_data->m_color & 0x00FFFFFF };
++current_primitive;

current_primitive->position = render_data->m_position;
current_primitive->scale = 1.f;
current_primitive->color = { upper_rain_color.color | render_data->m_color.color & 0x00FFFFFF };
current_primitive->color = { upper_rain_alpha| render_data->m_color & 0x00FFFFFF };

++current_primitive;

current_primitive->position.x = render_data->m_position.x - system->m_rain_line_width * rain_vector.j;
current_primitive->position.y = render_data->m_position.y + system->m_rain_line_width * rain_vector.i;
current_primitive->position.z = render_data->m_position.z;
current_primitive->scale = 1.f;
current_primitive->color = { upper_rain_color.color | render_data->m_color.color & 0x00FFFFFF };
current_primitive->color = { upper_rain_alpha | render_data->m_color & 0x00FFFFFF };
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion xlive/Blam/Engine/render/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ void __cdecl render_scene(
0,
NULL,
D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
global_white_pixel32.color,
global_white_pixel32,
1.f,
0);

Expand Down

0 comments on commit a388a8e

Please sign in to comment.