void rend_horizontal_stripe(int32 draw_length, int32 floor_x__fp, int32 floor_y__fp, int32 floor_step_x__fp, int32 floor_step_y__fp, u_int8* lightmap__READY, int8* texture_256__READY, const u_int8 tex_size, u_int32* output_buffer_32__READY, int32* texture_intensity, int32* distance_shading_flats__LUT__READY) { while (draw_length >= 0) { // 01. Lets find current x,y coords in lightmap bitmap. The lightmap bitmap is 32 x 32 px. // BEFORE OPTIMALIZATION // int32 lm_tx = (int32)((floor_x__fp << 5) >> 18) & (IO_LIGHTMAP_SIZE - 1); // int32 lm_ty = (int32)((floor_y__fp << 5) >> 18) & (IO_LIGHTMAP_SIZE - 1); // AFTER OPTIMALIZATION: int32 lm_x = (int32)((floor_x__fp) >> 13) & (32 - 1); int32 lm_y = (int32)((floor_y__fp) >> 13) & (32 - 1); // 02. Now we can get intensity valie from ligtmap - its 8-bit value from 0 to 127. int32 lm_intensity_value = lightmap__READY[lm_x + (lm_y << 5)]; // 03. Lets find current x,y coords in texture bitmap. // BEFORE OPTIMALIZATION // int32 tx = (int32)((floor_x__fp << 8) >> 18) & (255); // int32 ty = (int32)((floor_y__fp << 8) >> 18) & (255); // AFTER OPTIMALIZATION: int32 tx = (int32)((floor_x__fp) >> 10) & (tex_size); int32 ty = (int32)((floor_y__fp) >> 10) & (tex_size); // 04. Now we can get index to color table from texture bitmap. u_int8 texture_pixel_index = texture_256__READY[tx + (ty << 8)]; // 05. We would like also to use distance shading. // Lets take our intensity value from lighmap (from 02) and use it in precalculated array "distance_shading_flats__LUT__READY" // to get lightmap intensity value affected by distance. // With that final lightmap intensity value we can move pointer to correct color table for that texture u_int32* texture_intensity_lm = texture_intensity + distance_shading_flats__LUT__READY[lm_intensity_value]; // 06. Use texture index (from 04) to get RGBA pixel from correct color table. Put the pixel in output_buffer. *output_buffer_32__READY = texture_intensity_lm[texture_pixel_index]; output_buffer_32__READY++; floor_x__fp += floor_step_x__fp; floor_y__fp += floor_step_y__fp; draw_length--; } }
@Don_Adan, post #2
_rend: movem.l a6/a5/a4/a3/a2/d7/d6/d5/d4/d3/d2,-(sp) lea (48,sp),a1 move.l (a1)+,d4 move.l (a1)+,d0 move.l (a1)+,d1 move.l (a1)+,(60,sp) move.l (a1)+,d6 move.l (a1)+,a2 move.l (a1)+,d7 move.l (a1)+,d3 move.l (a1)+,a0 move.l (a1)+,a3 move.l (a1),a4 and.l #255,d3 tst.l d4 jlt .L1 moveq #1,d2 and.l d4,d2 move.l d2,a1 move.l d1,d2 lsr.l #8,d2 move.l #992,d5 and.l d2,d5 bfextu d0{#14:#5},d2 or.l d2,d5 move.b (a2,d5.l),d5 and.l #255,d5 move.l d1,d2 asr.l #8,d2 asr.l #2,d2 and.l d3,d2 lsl.l #8,d2 move.l d2,a5 move.l d0,d2 asr.l #8,d2 asr.l #2,d2 add.l d7,a5 and.l d3,d2 move.b (a5,d2.l),d2 add.l (a4,d5.l*4),d2 move.l (a3,d2.l*4),(a0)+ add.l (60,sp),d0 move.l d4,a5 add.l d6,d1 subq.l #1,a5 cmp.w #-1,a5 jeq .L1 move.l a1,d2 jeq .L9 move.l d1,d2 lsr.l #8,d2 and.l #992,d2 bfextu d0{#14:#5},d5 or.l d5,d2 move.b (a2,d2.l),d2 and.l #255,d2 move.l d2,a6 move.l d1,d2 asr.l #8,d2 asr.l #2,d2 and.l d3,d2 lsl.l #8,d2 move.l d2,a1 move.l d0,d2 asr.l #8,d2 asr.l #2,d2 add.l d7,a1 and.l d3,d2 move.b (a1,d2.l),d2 add.l (a4,a6.l*4),d2 move.l (a3,d2.l*4),(a0)+ add.l (60,sp),d0 add.l d6,d1 move.l a5,d2 jeq .L1 .L9: lsr.l #1,d4 subq.l #1,d4 .L5: move.l d1,d2 lsr.l #8,d2 and.l #992,d2 bfextu d0{#14:#5},d5 or.l d5,d2 move.b (a2,d2.l),d2 and.l #255,d2 move.l d2,a5 move.l d1,d2 asr.l #8,d2 asr.l #2,d2 and.l d3,d2 lsl.l #8,d2 move.l d0,d5 asr.l #8,d5 asr.l #2,d5 move.l d7,a1 and.l d3,d5 add.l d2,a1 clr.l d2 move.b (a1,d5.l),d2 add.l (a4,a5.l*4),d2 move.l (a3,d2.l*4),(a0)+ add.l (60,sp),d0 add.l d6,d1 move.l d1,d2 lsr.l #8,d2 and.l #992,d2 bfextu d0{#14:#5},d5 or.l d5,d2 move.b (a2,d2.l),d2 and.l #255,d2 move.l d2,a5 move.l d1,d2 asr.l #8,d2 asr.l #2,d2 and.l d3,d2 lsl.l #8,d2 move.l d0,d5 asr.l #8,d5 asr.l #2,d5 move.l d7,a1 and.l d3,d5 add.l d2,a1 clr.l d2 move.b (a1,d5.l),d2 add.l (a4,a5.l*4),d2 move.l (a3,d2.l*4),(a0)+ add.l (60,sp),d0 add.l d6,d1 subq.l #1,d4 jcc .L5 .L1: movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2/a3/a4/a5/a6 rts
@mateusz_s, post #4
or.l d5,d2 move.b (a2,d2.l),d2 and.l #255,d2 move.l d2,a5 move.l d1,d2 asr.l #8,d2 asr.l #2,d2 and.l d3,d2 lsl.l #8,d2 move.l d0,d5
or.l d2,d5 moveq #0,d2 move.b (a2,d5.l),d2 ; and.l #255,d2 move.l d2,a5 move.l d1,d2 asr.l #8,d2 asr.l #2,d2 ; nie pamietam juz czy ; moveq #10,d5 ; asr.l d5,d2 ; jest szybsze niz 2x asr.l, czy taka sama szybkosc ma and.l d3,d2 lsl.l #8,d2 move.l d0,d5
@Don_Adan, post #5
// -- Step 07. -- // After points are projected, segments clipped and rasterized into x0 and x1 buffers, // the current floor and ceil polygons can be rendered. // Render the FLOOR if the final floor poly has more than 2 segments. if (floor_poly_size > 2) { int8* texture_256__READY = LV_map[pvc_cell_id].flat_texture__PTR[0]; int32* texture_intensity = LV_map[pvc_cell_id].flat_texture_intensity__PTR[0]; u_int8* lightmap__READY = LV_map[pvc_cell_id].flat_lightmap__PTR[0]; for (int32 ray_y = floor_y_min; ray_y <= floor_y_max; ray_y++) { float32 ray_y_pos = ray_y - GR_horizont; float32 straight_distance_to_point = fabsf(pp_z__floor / ray_y_pos); // Calculate distance intensity value based on wall distance. int32 distance_intensity = (int32)(straight_distance_to_point * GR_DISTANCE_INTENSITY_SCALE); //int32 distance_intensity = (int32)(straight_distance_to_point *4/** GR_DISTANCE_INTENSITY_SCALE*/); distance_intensity = MA_MIN_2(distance_intensity, (GR_DISTANCE_INTENSITY_LENGTH - 1)); // u_int32* texture_intensity__READY = texture_intensity + 127 * 128; // Move pointer to correct distance in distance shading LUT. int32* distance_shading_flats__LUT__READY = GR_distance_shading_flats__LUT[distance_intensity]; float32 floor_step_x = (straight_distance_to_point * rdx1__sub__rdx0__div__width) ; float32 floor_step_y = (straight_distance_to_point * rdy1__sub__rdy0__div__width) ; float32 floor_x = (PL_player.x + (straight_distance_to_point * ray_dir_x0)) + floor_step_x * GR_fv_buf_x[0][ray_y]; float32 floor_y = (PL_player.y + (straight_distance_to_point * ray_dir_y0)) + floor_step_y * GR_fv_buf_x[0][ray_y]; floor_x -= (int8)floor_x; floor_y -= (int8)floor_y; int32 floor_step_x__fp = (int32)(floor_step_x * 262144.0f); int32 floor_step_y__fp = (int32)(floor_step_y * 262144.0f); int32 floor_x__fp = (int32)(floor_x * 262144.0f); int32 floor_y__fp = (int32)(floor_y * 262144.0f); int32 draw_start_in_buffer = GR_fv_buf_x[0][ray_y] + ray_y * GR_render_width; u_int32* output_buffer_32__READY = IO_prefs.output_buffer_32 + draw_start_in_buffer; int32 draw_length = GR_fv_buf_x[1][ray_y] - GR_fv_buf_x[0][ray_y]; GR_Render_Flats_Horizontal_Stripe( draw_length, 255, 8, 10, floor_x__fp, floor_y__fp, floor_step_x__fp, floor_step_y__fp, lightmap__READY, texture_256__READY, texture_intensity, distance_shading_flats__LUT__READY, output_buffer_32__READY); } }
@mateusz_s, post #8