Join us on Discord!
You can help CodeWalrus stay online by donating here.
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - catastropher

#31
Nice work so far! :D I'm sure you know this, but I'm just throwing it out there. If you have a texture dimension that is a power of two (2^n), logical anding the u and v values with (2^n - 1) will give you texture wrapping. So your loop would look something this (this isn't real code, I just wrote it as an example):

[spoiler]
typedef struct {
    int x;
    fp16x16 u, v;   // 16.16 fixed point
    fp16x16 z;
} ScanlineValue;

typedef struct {
    unsigned char size;
    unsigned char* texels;
} Texture;

void draw_scanline(ScanlineValue* left, ScanlineValue* right, Texture* tex, int y, short* zbuf) {
    int dx = (right->x - left->x != 0 ? right->x - left->x : 1);
   
    fp16x16 du = (right->u - left->u) / dx;
    fp16x16 dv = (right->v - left->v) / dx;
    fp16x16 dz = (right->z - left->z) / dx;
   
    fp16x16 u = left->u;
    fp16x16 v = left->v;
    fp16x16 z = left->z;
   
    for(int x = left->x; x <= right->x; ++x) {
        int zz = z >> 16;
       
        if(zz < zbuf[y * SCREEN_WIDTH + x]) {
            int uu = (u >> 16) & (tex->size - 1);
            int vv = (v >> 16) & (tex->size - 1);
           
            screen[y * SCREEN_WIDTH + x] = tex->texels[vv * tex->size + uu];
            zbuf[y * SCREEN_WIDTH + x] = zz;
        }
       
        u += du;
        v += dv;
        z += dz;
    }
}

[/spoiler]
#32
Quote from: DJ Omnimaga on September 25, 2016, 05:06:50 PM
I don't want to see what :walrii: would look like if seam carving was applied to it O.O
I still have my source code, maybe I should run Walrii through it? :P
#33
We had to implement seam carving in my algorithms class (which I took like 3 years ago). It's a fun dynamic programming problem! :D
#34
Nice work! I can't wait to see this once it's done! I have two questions:

  • Is this doing affine texture mapping or perspective correct? X3D does affine, but at one point I had it doing the perspective correction every 16 pixels (just like Descent did)
  • Is this only for drawing triangles or can it handle other polygons as well? You can use the polyline property of convex polygons to split a polygon into two polylines and then draw each scanline by walking down the edges. This saves a lot of time because e.g. to draw a hexagon you only need one poly instead of 4.
A lot of people think you have to sort all the points in the polygon or something, but I just this method that I came up with (which runs in linear time):

[spoiler]
typedef struct X3D_PolyVertex {
    X3D_Vex2D v2d;
    int16 intensity;
    int32 u, v;
    int32 z;
} X3D_PolyVertex;

typedef struct X3D_PolyLine {
    uint16 total_v;
    X3D_PolyVertex** v;
} X3D_PolyLine;

_Bool x3d_polyline_split(X3D_PolyVertex* v, uint16 total_v, X3D_PolyLine* left, X3D_PolyLine* right) {
    // Force the polygon to be clockwise
    x3d_polyvertex_make_clockwise(v, total_v);
   
    int16 top_left = 0;
    int16 top_right = 0;
    int32 max_y = v[0].v2d.y;
   
    int16 i;
    // Find the top left point, the top right point, and the maximum y value
    for(i = 1; i < total_v; ++i) {
        if(v[i].v2d.y < v[top_left].v2d.y) {
            top_left = i;
            top_right = i;
        }
        else if(v[i].v2d.y == v[top_left].v2d.y) {
            if(v[i].v2d.x < v[top_left].v2d.x)    top_left = i;
            if(v[i].v2d.x > v[top_right].v2d.x)   top_right = i;
        }
       
        max_y = X3D_MAX(max_y, v[i].v2d.y);
    }
   
    left->total_v = 0;
    right->total_v = 0;
   
    // Grab the points for the left polyline
    do {
        left->v[left->total_v] = v + top_left;
        top_left = (top_left + 1 < total_v ? top_left + 1 : 0);
    } while(left->v[left->total_v++]->v2d.y != max_y);
   
    // Grab the points for the right polyline
    do {
        right->v[right->total_v] = v + top_right;
        top_right = (top_right != 0 ? top_right - 1 : total_v - 1);
    } while(right->v[right->total_v++]->v2d.y != max_y);
   
    return left->total_v > 1 && right->total_v > 1;
}
[/spoiler]
#35
Hey DJ, check this out:

[spoiler=Thing DJ should check out][/spoiler]
#36
Quote from: DJ Omnimaga on September 23, 2016, 03:39:04 AM
I wonder how good this engine would look like with textures from Pokéwalrus? :P
Feel free to send any textures my way!

Quote from: DJ Omnimaga on September 23, 2016, 03:39:04 AM
Looks very good, as always, by the way. :)
Thanks! :D

So I heavily optimized lightmap rendering. Things actually look pretty smooth now! Want to give it a try? Check out the attached demo program!

Keys:

       
  • Look around: arrow keys
  • Move forward/backward: 7/4
  • Add a new light at the camera's current position and angle: enter
  • Quit: esc
A few notes:

       
  • You can add a light but you can't remove one (they become "baked" into the level)
  • Adding a light might take a few seconds - computing light takes a lot of calculations (in floating point)! Also the screen will be flat shaded with weird colors as it's calculating. This is for debug purposes
  • Only spotlights with a fixed angle are implemented currently - this will change in the future
  • Don't walk outside the level because there's no collision detection! haha
  • I use affine texture mapping so the textures may shift strangely at certain angles
  • X3D now renders in 256 color mode (I stole Quake's color palette haha)
Please give me any feedback you may have! :D
#37
Quote from: DJ Omnimaga on September 22, 2016, 02:01:28 AM
Just be sure that the programmer can enable/disable engine features by just changing certain config values so that if they want their games to run on lower-end models (the TI-84 Plus CE, for example, if it ever gets supported), then they can run at decent speed at the cost of not having shading or lightning, for example.
Yeah, I made sure to implement the engine so that it has a number of different rendering modes (currently it has line, flat shading, gouraud shading, texture, texture + gouraud shading, and texture + lightmap).

Quote from: TheMachine02 on September 22, 2016, 09:59:11 AM
Quote from: DJ Omnimaga on September 22, 2016, 02:01:28 AM
the TI-84 Plus CE, for example, if it ever gets supported

* TheMachine02 prepares for benchmarking  :P
Anyway, more serioulsy, the light map is just awesome. Btw, how do you do your blending ? Your lightmap hold an intesnity or directy a light color ?
Thanks! Right now the lightmap holds the intensity, but I'm going to be changing the engine to use 256 color mode. This means I can use the following approach:

  • The lightmaps are calculated using a very expensive preprocessing step in low-resolution, storing intensity
  • When a polygon is visible, a high-resolution lightmap is built from the low-res one by using bilinear filtering
  • The polygon's texture is combined with the lightmap to create the final texture that is displayed (this can be done using a color table)
  • This final texture map can be cached and reused between frames. If it hasn't been used for a few frames it can be freed.
This sounds expensive, but will actually be very fast. I think I'm going to use Quake's color palette (https://quakewiki.org/wiki/Quake_palette). Although, I may allow the user to customize it.

In the last screenshot, I only had lightmap generator working. Here is the lightmap combined with texture mapping (using a very slow two texture method - this will be replaced with the above algorithm once I change the engine to use 256 color mode):

[spoiler=X3D Lightmap + Texture][/spoiler]

I will post more of my progress when I make it!
#38
Quote from: Ivoah on September 21, 2016, 01:47:40 AM
Looks great! What would be required to allow dynamic light sources?
Thanks! Probably an insane amount of computation power haha I'm going to do some research into how Quake did things. I'll let you know if I find a way to do it!

Quote from: DJ Omnimaga on September 21, 2016, 06:17:13 AM
Glad to see you again Catastropher. That lightning effect looks cool! If you can manage to make it run at good speed I am starting to wonder if this engine will not end up having better shading and lightning than PS2/Dreamcast games? O.O
Thanks, it's good to be back! Also, thank you! I'm hoping to really push the calc to its limits! :D

Quote from: p4nix on September 21, 2016, 05:09:43 PM
Very great work @catastropher, as a person who only got displaying and moving away from a triangle (on one axis, lol) done yet I'm really jealous of your work :P

Keep it up and good luck optimizing your code.
Thank you as well! If you ever need any help with anything, let me know!
#39
I have returned! Mwhahaha! I have been working on something new for X3D. It runs very very slow at the moment, but it will be much faster after some optimization. May I present: light maps!

[spoiler=X3D Light Map][/spoiler]

I only implemented this today so it still has a long way to go (implementing shadow mapping was hard but fun!). Light maps, which were used in Quake, allow for semi-realistic lighting by precomputing "light textures" for every polygon in the level. These are then applied on top of regular textures to create a lit, textured mapped environment. The only caveat is that they can only be used to for static lights and static objects. Still, I think the results will be very impressive! This currently runs at 1 fps on the calculator for a number of reasons (one of the reasons is that I'm using floats for the rasterizer instead of fixed point). I'm very guilty of too much optimization too soon so I will optimize once I get everything working.
#40
Quote from: DJ Omnimaga on July 17, 2016, 03:40:28 PM
Wow I didn't know that kind of textures was possible. I assume you can assign them to each wall like with regular textures? I think this could be handy for writings and other effects.
That is indeed how they work! You'll also be able to attach them to the faces of models (which is what I plan to do for the companion cube and other things).

Quote from: DJ Omnimaga on July 17, 2016, 03:40:28 PM
Also can you mix both wireframe and textured mode? Someone could make a Celshading-like game like Zelda: Windwaker.
Hmmm... that's an interesting question. For right now, I'm just focusing on wireframe mode but I'll keep this in the back of my mind.

Quote from: Ivoah on July 17, 2016, 04:50:11 PM
Now you need to add the ability to render SVGs :P
Tbh, that's what they practically are, just with lines XD The great thing is that the "line textures" can be rotated and scaled without looking crappy! :D

Btw, I'm going to need beta testers at some point (phase 1 is almost done). Any takers?
#41
I've been working more on the "line texture" abilities; now it's possible to add more complex line-art to walls. This will allows for fairly detailed scenes using art that is made entirely of lines. I may be in the minority here, but I actually like the look of sold wireframe rendering - it feels really retro to me for some reason!

[spoiler=Line-art][/spoiler]

XBuilder has a simple line art editor now (though it kinda sucks because I implemented it all in one day). Making that aperture logo by hand with lines was really hard though XD
#42
Thank you very much for the mention! :D
#43
X3D has been in development for over a year now. At times, progress has been very fast, and other times, it's gone painfully slow. I've learned many hard lessons on how to become a good developer over the course of writing it. However, I have tended to rush things and, overall, have made a terrible mess of the project. While I am not totally starting over, I am creating a development plan on how to move forward because, right now, the code is too terrible to continue. It's time to do things right so that the project actually makes some progress.

The new version of X3D will following the following development strategy:

       
  • Development will be broken into phases, or iterations. That way, we have a goal that we're moving towards.
  • At the end of each phase will be a small, working game that the community can play around with.
  • Feedback will be welcome at anytime and bugs will no longer hang around for months :) It would be awesome if some programmers would be willing to mess around with the library and create some things so I can get feedback!
  • A phase must be stable before moving onto the next one.
  • No hacky solutions will be implemented to rush things, as this just creates technical debt that must be dealt with later. Also, code must be kept clean at all times!
  • The entire development process will be transparent so people know what's being developed. Also, people can join the project anytime if they want to contribute.
If you're curious as to what the current development plan looks like, take a look here.
At anytime, to see what's currently in development, please see the Trello board here.

Please let me know if you have any feedback or suggestions!
#44
Hey guys, it's been a long time since I've posted anything. Things have been crazy busy because I started my internship and have been going to physical therapy for some tendon issues. I am still working on the project (I'm working really hard to improve the code quality) but there haven't been too many visible changes yet. There will be several cool things coming soon though! :D
#45
Awesome job! Can you send the walrii model my way when you're done? I'd love to import it into my 3D engine! :D
Powered by EzPortal