23 January 2021, 17:18 | #41 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Just a little update,
I've implemented culling of objects and their calculations (and shadows separately) based on distance from the camera, a faster more 16 bit route for things won't cross the view plane , and I've implemented the the precalculating step that was explained in http://eab.abime.net/showthread.php?...66#post1259966 (which I wish I'd done earlier, but at least I was smart enough to design my objects to take advantage of it), and I've simplified some stuff (like, buildings and runways now can't have an arbitrary orientation). The changes mean I can't give an fps comparision, but the code is definitely faster. It's also more complicated, as I calculate centre points before deciding if I need to calculate more, but the calculation phase is more clearly separated from the drawing phase, so pluses and minuses there. There's still a bunch of work to do, the runway is glitching at points where I overflow, which is tomorrow's job, and I still need to add different levels of detail for the models. I'm not doing that right now because I want to optimise the drawing while everything is at its most complex, and also because designing objects is not what I'm best at. The calculation phase still takes longer than the blitter takes to clear the screen, so I'll keep working on it, but now I want to start also optimising the drawing phase, which is where the bulk of the time is spent. Apart from that I still need to see if I can reduce the use of 32 bit pointers in my data structures, as suggested (I think) by Jobbo. Not sure how I'll approach that. Attached is an approx 1 minute clip, 250 frames at average 4.25fps. 3 planes, 3 tanks and a runway with stripes and a control tower. Last edited by Ernst Blofeld; 23 January 2021 at 18:23. |
23 January 2021, 18:00 | #42 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,409
|
That's a nice boost in performance!
|
24 January 2021, 13:03 | #43 | |
Registered User
Join Date: Dec 2017
Location: Denmark
Posts: 179
|
Quote:
Attached is an image and model where I reduced it to: 45 verts, 35 faces (+3 for wings underside) the "Pal resolution" picture, is a faked picture, where I tried to simulate the low resolution 320*256. and I don't think you can tell the difference. Canopy is reduced from 10 faces to 4. Upper nose and Cockpit not reduced, but moved faces around to allow for nose and upper fuselage reduction Upper Fuselage From 4 to 2 Lower nose and Cockpit from 6 to 4 Last edited by LaBodilsen; 24 January 2021 at 13:14. |
|
24 January 2021, 13:41 | #44 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
But first, I need to fix my clipping code to work with the very large numbers that my runway creates. |
|
24 January 2021, 14:36 | #45 | |
Registered User
Join Date: Dec 2017
Location: Denmark
Posts: 179
|
Quote:
I have one with 36 verts, 26 faces +3. (attached). at that distance, you might not even need the front wing at all, and save 4 verts and 4 faces. |
|
24 January 2021, 15:06 | #46 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Difficult to say, it's not just the vertex and face count we need to minimise, it's also the unique x, y and z component values of the vertices, while keeping the faces planar (or planar enough with the splitting planes being exact), I reckon you probably can't go much lower.
|
24 January 2021, 15:19 | #47 | |
Registered User
Join Date: Dec 2017
Location: Denmark
Posts: 179
|
Quote:
of course up close it looks very bad. |
|
24 January 2021, 15:24 | #48 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
I am currently stuck with my polygon clipping code and handling very large polygons, such as my runway.
The runway starts as a small object as it's scaled down by 1024, so 1 is approx 1 metre, but as I get to the end of the calculation phase the numbers become 1 is 1 pixel so approx 1 milimetre. I don't currently see another way to do this. When I get to my clipping stage, if you're looking at the runway the wrong way, it's possible to get polygon edges that cross the screen and which are very long. The standard calculation to clip those edges involves a multiplication which often overflows a long. and glitches out. What to do? I've tried a binary search type approach, bisecting the line until the intersection is found, which initially appeared to work, but at each bisection a rounding error is introduced and the result ends up out by several pixels. I've tried swapping the start and end pixels over, so working out the distances from the other end. This sometimes works, but introduces inconsistencies as the direction of the rounding changes too, and I worry I might lose precision. I've looked at how I can right shift the divisor and divisee parts of the equation, but I'm not sure quite how to work out how many bits to shift each part, and will I introduce more errors. So, yeah, I'm a bit stuck. |
24 January 2021, 15:37 | #49 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,409
|
You could try to have the runway be two or three objects rather than a single object perhaps? I believe quite a few older 3D games did this with larger objects.
|
24 January 2021, 15:52 | #50 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Or even just divide the long edges into multiple shorter ones. I'm not sure how to work out the maximum size of object or edge that I'd be safely allowed, but it could add up to a lot of extra vertices that have to be transformed.
|
24 January 2021, 16:34 | #51 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
r_y = s_y + (p_y - s_y) * (c_r - s_x) / (p_x - s_x) (so (p_x - s_x) and (p_y - s_y) are the x and y deltas, and (c_r - s_x) is the x distance from the start point to the clipping edge) And widening the question a bit more to not just avoiding overflow, but also fitting within efficient 68k divs operations... we need: - basically every single one of these numbers to fit into 16 bits I have little control over s_x. If each chunk of runway was really its own object then I could make sure I've culled the bits where s_x might be too big, but I'm not in love with that idea - I'd need to divide a runway into around 50 chunks. |
|
26 January 2021, 17:06 | #52 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
In the end I've fixed this by introducing some 64-bit maths. Works out around the same speed, or a tiny bit faster, as it's only used when very big things get very close to the camera, so only the runway at the moment, and it all happens inside one piece of assembly - three 32-bit numbers enter, one 32-bit number leaves.
Next problem? EDIT: Next problem is redesigning the data structures for my models to replace the pointers with indices for efficiency. It would be a mistake to not do this before I add all the lower detail models. Last edited by Ernst Blofeld; 26 January 2021 at 19:12. |
26 January 2021, 17:17 | #53 |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,409
|
Cool! Very nice it's also not any slower
|
26 January 2021, 19:03 | #54 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Things I wish I knew more about:
A: Other clipping algorithms:
B: Silhouette Edges:
C: A + B => Do I need a rasterisation routine that can cope with complex polygons?
Last edited by Ernst Blofeld; 26 January 2021 at 19:11. |
26 January 2021, 19:28 | #55 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Also, how would I pack something like this into something that doesn't use pointers and the address of "&" everywhere? My guess is that I can't do it in C?
Code:
static Face lowerFuselageLeftFrontFace = { .name = "Lower Fuselage, Left Front Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_SIDES_COLOUR, .numVertices = 3, .vertices = { 25, 44, 46 } }; static Face lowerFuselageLeftMiddleFace = { .name = "Lower Fuselage, Left Middle Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_SIDES_COLOUR, .numVertices = 3, .vertices = { 4, 25, 46 } }; static Face lowerFuselageLeftRearFace = { .name = "Lower Fuselage, Left Rear Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_SIDES_COLOUR, .numVertices = 3, .vertices = { 4, 46, 5 } }; static Face lowerFuselageBottomFace = { .name = "Lower Fuselage, Bottom Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_COLOUR, .numVertices = 4, .vertices = { 5, 46, 48, 8 } }; static Face lowerFuselageRightFrontFace = { .name = "Lower Fuselage, Right Front Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_SIDES_COLOUR, .numVertices = 3, .vertices = { 28, 48, 49 } }; static Face lowerFuselageRightMiddleFace = { .name = "Lower Fuselage, Right Middle Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_SIDES_COLOUR, .numVertices = 3, .vertices = { 9, 48, 28 } }; static Face lowerFuselageRightRearFace = { .name = "Lower Fuselage, Right Rear Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_SIDES_COLOUR, .numVertices = 3, .vertices = { 8, 48, 9 } }; static Region lowerFuselageSection = { .type = REGION, .name = "Lower Fuselage Section", .faces = { &lowerFuselageLeftFrontFace, &lowerFuselageLeftMiddleFace, &lowerFuselageLeftRearFace, &lowerFuselageBottomFace, &lowerFuselageRightFrontFace, &lowerFuselageRightMiddleFace, &lowerFuselageRightRearFace, NULL } }; static Face cockpitLowerLeftFace = { .name = "Cockpit, Lower Left Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_SIDES_COLOUR, .numVertices = 4, .vertices = { 23, 50, 45, 44 } }; static Face cockpitLowerFace = { .name = "Cockpit, Lower Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_COLOUR, .numVertices = 4, .vertices = { 45, 50, 51, 47 } }; static Face cockpitLowerRightFace = { .name = "Cockpit, Lower Right Face", .colour = EUROFIGHTER_FUSELAGE_LOWER_SIDES_COLOUR, .numVertices = 4, .vertices = { 24, 49, 47, 51 } }; static Face noseLowerLeftFace = { .name = "Nose, Lower Left Face", .colour = EUROFIGHTER_NOSE_LOWER_COLOUR, .numVertices = 3, .vertices = { 22, 50, 23 } }; static Face noseLowerFace = { .name = "Nose, Lower Face", .colour = EUROFIGHTER_NOSE_LOWER_COLOUR, .numVertices = 3, .vertices = { 22, 51, 50 } }; static Face noseLowerRightFace = { .name = "Nose, Lower Right Face", .colour = EUROFIGHTER_NOSE_LOWER_COLOUR, .numVertices = 3, .vertices = { 22, 24, 51 } }; static Region lowerNoseAndCockpitSection = { .type = REGION, .name = "Lower Nose and Cockpit Section", .faces = { &cockpitLowerLeftFace, &cockpitLowerFace, &cockpitLowerRightFace, &noseLowerLeftFace, &noseLowerFace, &noseLowerRightFace, NULL } }; static Face Canopy_Base = { .name = "(invisible) Canopy Base Face", .colour = INVISIBLE_COLOUR, .numVertices = 3, .vertices = { 16, 20, 19 } }; static Face Bulkhead = { .name = "(invisible) Bulkhead Face", .colour = INVISIBLE_COLOUR, .numVertices = 3, .vertices = { 28, 25, 21 } }; static Face XY_Plane = { .name = "(invisible) XY Plane Face", .colour = INVISIBLE_COLOUR, .numVertices = 3, .vertices = { 33, 41, 42 } }; static Partition inFrontOfBulkheadSection = { .name = "In Front of Bulkhead Section", .splittingPlane = &Canopy_Base, .above = (Section *) &canopySection, .below = (Section *) &upperNoseAndCockpitSection }; |
26 January 2021, 21:12 | #56 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Are you talking about ensuring correctness, maintainability, or performance when you mention you would like to get rid of pointers?
|
26 January 2021, 21:35 | #57 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
For instance, if I drop the name strings, which are just debugging info, all the face data is just words, so I could just pack it all together, but I would need to know where each face starts to create an index into the array, because there's no way I can count them by hand. Last edited by Ernst Blofeld; 26 January 2021 at 21:42. |
|
27 January 2021, 10:38 | #58 | |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
Quote:
I'll have an array of words for my faces: Code:
static WORD faceData [] = { #define LEFT_EXHAUST_FACE 0 #define _LEFT_EXHAUST_FACE_NUM_VERTICES 6 #define _AFTER_LEFT_EXHAUST_FACE LEFT_EXHAUST_FACE + 2 * (2 + _LEFT_EXHAUST_FACE_NUM_VERTICES) EXHAUST_COLOUR, _LEFT_EXHAUST_FACE_NUM_VERTICES, 1, 2, 3, 4, 5, 6, #define RIGHT_EXHAUST_FACE _AFTER_LEFT_EXHAUST_FACE #define _RIGHT_EXHAUST_FACE_NUM_VERTICES 6 #define _AFTER_RIGHT_EXHAUST_FACE RIGHT_EXHAUST_FACE + 2 * (2 + _RIGHT_EXHAUST_FACE_NUM_VERTICES) EXHAUST_COLOUR, _RIGHT_EXHAUST_FACE_NUM_VERTICES, 1, 7, 8, 9, 10, 11, #define CANOPY_FRONT_LEFT_LOWER_FACE _AFTER_RIGHT_EXHAUST_FACE #define _CANOPY_FRONT_LEFT_LOWER_FACE_NUM_VERTICES 3 #define _AFTER_CANOPY_FRONT_LEFT_LOWER_FACE CANOPY_FRONT_LEFT_LOWER_FACE + 2 * (2 + _CANOPY_FRONT_LEFT_LOWER_FACE_NUM_VERTICES) CANOPY_COLOUR, _CANOPY_FRONT_LEFT_LOWER_FACE_NUM_VERTICES, 12, 13, 14 // ... }; Code:
static WORD sectionData [] = { #define EXHAUST_SECTION 0 #define _EXHAUST_SECTION_NUM_FACES 2 #define _AFTER_EXHAUST_SECTION EXHAUST_SECTION + 2 * (2 + _EXHAUST_SECTION_NUM_FACES) REGION, LEFT_EXHAUST_FACE, RIGHT_EXHAUST_FACE, END, #define CANOPY_SECTION AFTER_EXHAUST_SECTION #define _CANOPY_SECTION_NUM_FACES 10 #define _AFTER_CANOPY_SECTION CANOPY_SECTION + 2 * (2 + _CANOPY_SECTION_NUM_FACES) REGION, CANOPY_FRONT_LEFT_LOWER_FACE, CANOPY_FRONT_LEFT_UPPER_FACE, CANOPY_FRONT_FACE, CANOPY_FRONT_RIGHT_UPPER_FACE, CANOPY_FRONT_RIGHT_LOWER_FACE, CANOPY_REAR_LEFT_LOWER_FACE, CANOPY_REAR_LEFT_UPPER_FACE, CANOPY_REAR_FACE CANOPY_REAR_RIGHT_UPPER_FACE, CANOPY_REAR_RIGHT_LOWER_FACE, END, #define IN_FRONT_OF_BULKHEAD_SECTION _AFTER_CANOPY_SECTION #define _AFTER_IN_FRONT_OF_BULKHEAD_SECTION _IN_FRONT_OF_BULKHEAD_SECTION + SIZE_OF_PARTITION PARTITION, CANOPY_BASE_PLANE, CANOPY_SECTION, NONE, NONE, UPPER_NOSE_AND_COCKPIT_SECTION, #define BEHIND_BULKHEAD_SECTION _AFTER_IN_FRONT_OF_BULKHEAD_SECTION #define _AFTER_BEHIND_BULKHEAD_SECTION BEHIND_BULKHEAD_SECTION + SIZE_OF_PARTITION PARTITION, UPPER_FUSELAGE_TOP_FACE, TAIL_SECTION, UPPER_FUSELAGE_TOP_SECTION, NONE, UPPER_FUSELAGE_MAIN_SECTION // ... }; Last edited by Ernst Blofeld; 27 January 2021 at 10:50. |
|
27 January 2021, 10:55 | #59 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,211
|
Why do you need all those defines ?
Surely, you just need raw data to define vertices, edges + faces etc... Imagine you have 50 different objects, and you have to make changes to every object etc.. |
27 January 2021, 11:00 | #60 |
<optimized out>
Join Date: Sep 2020
Location: <optimized out>
Posts: 321
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
68000 optimisation | Galahad/FLT | Coders. Asm / Hardware | 9 | 20 August 2016 00:29 |
Picasso IV optimisation | Tony Landais | support.Hardware | 10 | 01 September 2006 19:54 |
|
|