@michal_zukowski, post #180
@mateusz_s, post #181
// get pixel coords in texture u_int32 texture_current_pixel = level_textures[0].row[texture_pixel_x][texture_pixel_y];
// get pixel coords in texture u_int32 texture_current_pixel = level_textures[texture_index].row[texture_pixel_x][texture_pixel_y];
inline void RC_Raycast_Floor_Ceiling()
{
// get local copy of RC_level_textures
sBM_Bitmap_row* level_textures = RC_level_textures;
// ray direction for leftmost ray (x = 0) and rightmost ray (x = width)
float32 r_dx0 = RC_pp_dx - RC_pp_nsize_x_d2;
float32 r_dy0 = RC_pp_dy - RC_pp_nsize_y_d2;
float32 r_dx1 = RC_pp_dx + RC_pp_nsize_x_d2;
float32 r_dy1 = RC_pp_dy + RC_pp_nsize_y_d2;
// precalculated helpers for performance
float32 r_dx1_m_dx0_div_width = (r_dx1 - r_dx0) * RC_render_width_1d_f;
float32 r_dy1_m_dy0_div_width = (r_dy1 - r_dy0) * RC_render_width_1d_f;
// casting floor and ceiling - horizontal line by line - from left to right
for (u_int16 ry = 0; ry < RC_render_height_i; ++ry)
{
// whether this section is floor or ceiling
u_int8 is_floor = ry > RC_render_height_d2_i + RC_player_pitch;
// current ray y position compared to the center of the screen (the horizon)
float32 ry_pos = (float32)(is_floor ? (ry - RC_render_height_d2_i - RC_player_pitch) : (RC_render_height_d2_i - ry + RC_player_pitch));
// vertical position of projection plane, 0.5 is between floor and ceiling
float32 pp_z = (float32)(is_floor ? (RC_render_height_d2_i + RC_player_z) : (RC_render_height_d2_i - RC_player_z));
float32 straight_distance_to_point = pp_z / ry_pos;
// calculate the real world step vector we have to add for each x (parallel to camera plane)
// adding step by step avoids multiplications with a weight in the inner loop
float32 floor_step_x = straight_distance_to_point * r_dx1_m_dx0_div_width;
float32 floor_step_y = straight_distance_to_point * r_dy1_m_dy0_div_width;
float32 floor_x = RC_player_x + straight_distance_to_point * r_dx0;
float32 floor_y = RC_player_y + straight_distance_to_point * r_dy0;
// convert that values to fixed point
int32 floor_x__fp = (int32)(floor_x * 65536.0f);
int32 floor_y__fp = (int32)(floor_y * 65536.0f);
int32 floor_step_x__fp = (int32)(floor_step_x * 65536.0f);
int32 floor_step_y__fp = (int32)(floor_step_y * 65536.0f);
u_int32 ry_m_render_width = ry * RC_render_width_i;
// drawing floor and ceiling from left to right
for (u_int16 ry_x = 0; ry_x < RC_render_width_i; ++ry_x)
{
u_int32 output_pixel_index = ry_x + ry_m_render_width;
floor_x += floor_step_x;
floor_y += floor_step_y;
floor_x__fp += floor_step_x__fp;
floor_y__fp += floor_step_y__fp;
// the cell coord is simply got from the integer parts of floorX and floorY
u_int32 curr_cell_x = (floor_x__fp & FP_INTEGER_MASK_16) >> 16;
u_int32 curr_cell_y = (floor_y__fp & FP_INTEGER_MASK_16) >> 16;
// prevent overflow
curr_cell_x &= LV_MAP_SIZE_m1;
curr_cell_y &= LV_MAP_SIZE_m1;
u_int32 curr_cell_x_fraction__fp = (floor_x__fp & FP_FRACTION_MASK_16) >> 8;
u_int32 curr_cell_y_fraction__fp = (floor_y__fp & FP_FRACTION_MASK_16) >> 8;
// get the texture coordinate from the fractional part, masking avoids overflow
u_int32 texture_pixel_x = (u_int32)((128 * 256 * curr_cell_x_fraction__fp) >> 16);
u_int32 texture_pixel_y = (u_int32)((128 * 256 * curr_cell_y_fraction__fp) >> 16);
// get the texture index depending on the cell
u_int8 texture_index;
if (is_floor)
{
texture_index = RC_level->map[curr_cell_x + (curr_cell_y << LV_MAP_SIZE_BITSHIFT)].floor_id;
}
else
{
texture_index = RC_level->map[curr_cell_x + (curr_cell_y << LV_MAP_SIZE_BITSHIFT)].ceil_id;
}
// ----------------------------------------- DIFFERENCE - level_textures[0]
// get pixel coords in texture
u_int32 texture_current_pixel = level_textures[0].row[texture_pixel_x][texture_pixel_y];
// ----------------------------------------- -------------------------------------------------
RC_output_buffer_32[output_pixel_index] = texture_current_pixel;
}
}
}inline void RC_Raycast_Floor_Ceiling()
{
// get local copy of RC_level_textures
sBM_Bitmap_row* level_textures = RC_level_textures;
// ray direction for leftmost ray (x = 0) and rightmost ray (x = width)
float32 r_dx0 = RC_pp_dx - RC_pp_nsize_x_d2;
float32 r_dy0 = RC_pp_dy - RC_pp_nsize_y_d2;
float32 r_dx1 = RC_pp_dx + RC_pp_nsize_x_d2;
float32 r_dy1 = RC_pp_dy + RC_pp_nsize_y_d2;
// precalculated helpers for performance
float32 r_dx1_m_dx0_div_width = (r_dx1 - r_dx0) * RC_render_width_1d_f;
float32 r_dy1_m_dy0_div_width = (r_dy1 - r_dy0) * RC_render_width_1d_f;
// casting floor and ceiling - horizontal line by line - from left to right
for (u_int16 ry = 0; ry < RC_render_height_i; ++ry)
{
// whether this section is floor or ceiling
u_int8 is_floor = ry > RC_render_height_d2_i + RC_player_pitch;
// current ray y position compared to the center of the screen (the horizon)
float32 ry_pos = (float32)(is_floor ? (ry - RC_render_height_d2_i - RC_player_pitch) : (RC_render_height_d2_i - ry + RC_player_pitch));
// vertical position of projection plane, 0.5 is between floor and ceiling
float32 pp_z = (float32)(is_floor ? (RC_render_height_d2_i + RC_player_z) : (RC_render_height_d2_i - RC_player_z));
float32 straight_distance_to_point = pp_z / ry_pos;
// calculate the real world step vector we have to add for each x (parallel to camera plane)
// adding step by step avoids multiplications with a weight in the inner loop
float32 floor_step_x = straight_distance_to_point * r_dx1_m_dx0_div_width;
float32 floor_step_y = straight_distance_to_point * r_dy1_m_dy0_div_width;
float32 floor_x = RC_player_x + straight_distance_to_point * r_dx0;
float32 floor_y = RC_player_y + straight_distance_to_point * r_dy0;
// convert that values to fixed point
int32 floor_x__fp = (int32)(floor_x * 65536.0f);
int32 floor_y__fp = (int32)(floor_y * 65536.0f);
int32 floor_step_x__fp = (int32)(floor_step_x * 65536.0f);
int32 floor_step_y__fp = (int32)(floor_step_y * 65536.0f);
u_int32 ry_m_render_width = ry * RC_render_width_i;
// drawing floor and ceiling from left to right
for (u_int16 ry_x = 0; ry_x < RC_render_width_i; ++ry_x)
{
u_int32 output_pixel_index = ry_x + ry_m_render_width;
floor_x += floor_step_x;
floor_y += floor_step_y;
floor_x__fp += floor_step_x__fp;
floor_y__fp += floor_step_y__fp;
// the cell coord is simply got from the integer parts of floorX and floorY
u_int32 curr_cell_x = (floor_x__fp & FP_INTEGER_MASK_16) >> 16;
u_int32 curr_cell_y = (floor_y__fp & FP_INTEGER_MASK_16) >> 16;
// prevent overflow
curr_cell_x &= LV_MAP_SIZE_m1;
curr_cell_y &= LV_MAP_SIZE_m1;
u_int32 curr_cell_x_fraction__fp = (floor_x__fp & FP_FRACTION_MASK_16) >> 8;
u_int32 curr_cell_y_fraction__fp = (floor_y__fp & FP_FRACTION_MASK_16) >> 8;
// get the texture coordinate from the fractional part, masking avoids overflow
u_int32 texture_pixel_x = (u_int32)((128 * 256 * curr_cell_x_fraction__fp) >> 16);
u_int32 texture_pixel_y = (u_int32)((128 * 256 * curr_cell_y_fraction__fp) >> 16);
// get the texture index depending on the cell
u_int8 texture_index;
if (is_floor)
{
texture_index = RC_level->map[curr_cell_x + (curr_cell_y << LV_MAP_SIZE_BITSHIFT)].floor_id;
}
else
{
texture_index = RC_level->map[curr_cell_x + (curr_cell_y << LV_MAP_SIZE_BITSHIFT)].ceil_id;
}
// ----------------------------------------- DIFFERENCE - level_textures[texture_index]
// get pixel coords in texture
u_int32 texture_current_pixel = level_textures[texture_index].row[texture_pixel_x][texture_pixel_y];
// ----------------------------------------- -------------------------------------------------
RC_output_buffer_32[output_pixel_index] = texture_current_pixel;
}
}
} @mateusz_s, post #182
@kiero, post #183
@mateusz_s, post #184
@kiero, post #185
I wszystko jasne. To jest kompilowane pod vampire. Nie polecam uruchamiania tego kodu na 040/060. Bardzo nie polecam.
@mateusz_s, post #186
@mateusz_s, post #187
@mateusz_s, post #189
@mateusz_s, post #190
*(output_buffer_32__ptr - 1) = intensity_premultipled_CH1[prev_texture_pixel >> 16 & 0xff] |
intensity_premultipled_CH2[prev_texture_pixel >> 8 & 0xff] |
intensity_premultipled_CH3[prev_texture_pixel & 0xff];poza petla:
u_int32* intensity_premultipled = &intensity_premultipliedLUT[intensity_value];
petla
{
u_int8 tex_index = current_texture_columnptr[current_v];
*bufor = intensity_premultipled[tex_index];
}@mateusz_s, post #191
@mateusz_s, post #192
@mateusz_s, post #193
@Kefir_Union, post #195
@mateusz_s, post #200
dla każdego kafelka dla każdej lini poziomej kafelka wstaw pixel od xmin do xmax
@mateusz_s, post #201
@mateusz_s, post #203
@selur, post #207