Author Topic: Help With SGL: Back-Face Culling and Camera Clipping  (Read 1617 times)

sbf2009

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Help With SGL: Back-Face Culling and Camera Clipping
« on: January 13, 2019, 04:55:12 am »
I've been struggling with implementing a couple things that relate to SGL. All of my attempts to play with said things have not gone well. Any help would be appreciated.

Back-Face Culling
First, I've had a short conversation on my Youtube channel with XL2 about back-face culling. If I understand correctly, I have to implement this on a quad by quad basis. My confusion is to how, since the documentation doesn't paint much of a picture on how to play with SGL. I am loading an object like so:

Code: [Select]
jo_vertice    metal_crate_1_v[] = JO_3D_CUBE_VERTICES(32);
jo_3d_quad    metal_crate_1_q[6];
int       metal_crate_1_nq;

// Load Texture
jo_sprite_add_tga(JO_ROOT_DIR, "BOX.TGA", JO_COLOR_Transparent);

//  Write textures
jo_3d_create_cube(metal_crate_1_q, metal_crate_1_v);
metal_crate_1_nq = 6;
for (int i = 0; i < metal_crate_1_nq; ++i)
{
    jo_3d_set_texture(&metal_crate_1_q[i], 0);
}

Drawing it:

Code: [Select]
//  Perform matrix manipulations and draw
jo_3d_push_matrix();
{
    jo_3d_translate_matrix(x, y, z);
    jo_3d_rotate_matrix(rx, ry, rz);
    jo_3d_draw_array(quads, num_quad);
}

//  Restore default matrix
jo_3d_pop_matrix()

If I understand correctly, the flag is an attribute under pdata. Should I be writing this line while writing textures for every quad I want culled? (excuse the bad C, I don't quite know what I'm doing):

Code: [Select]
quad->data->attbl->flag = 0;

Camera Clipping
Second, I've just encountered some trouble while implementing collision. It appears that quads just in front of the camera's position do not get rendered. Is there a way to change the camera's drawing plane (i.e. move the projection surface closer to the camera's position?) I believe this is controlled by a property called ScreenDist in SGL, but I am unsure where to implement said change.

XL2

  • Sr. Member
  • ****
  • Posts: 360
  • Karma: +88/-3
    • View Profile
Re: Help With SGL: Back-Face Culling and Camera Clipping
« Reply #1 on: January 13, 2019, 06:08:41 am »
For your first question, if you look at some pdata headers, like those generated by Jo engine map editor or my own model converters, you will be able to change the attributes there. I don't recommand the current technique you are using to create models as this means for a simple cube you need to transform 24 vertices instead of just 8.

For your second question, do something like slZdsplevel(7);
That is your near plane of your frustum,  where the value is screenDist/(1<<7) . So if you set it to 1, that means if your screen distance is 250, objects near 125 will get clipped.
The screen distance is exactly the same thing as your FOV, so you can just set your FOV instead for simplicity.

ponut64

  • Full Member
  • ***
  • Posts: 219
  • Karma: +22/-1
    • View Profile
Re: Help With SGL: Back-Face Culling and Camera Clipping
« Reply #2 on: January 13, 2019, 07:27:34 am »
Another note - that you probably already know, but I'll say it anyway - SGL does perform backface culling within the same mesh based on its normals. There's nothing extra you have to do, as long as the data tables are arranged properly by XL2's model converter or the one in Jo Map Editor.

There's much hubbub about this practice because the way SGL does it is not always ideal, but the process of solving that one is being worked on in libyaul (or otherwise by our local hero, XL2). Otherwise, I don't know anything.
« Last Edit: January 13, 2019, 07:30:20 am by ponut64 »

sbf2009

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Re: Help With SGL: Back-Face Culling and Camera Clipping
« Reply #3 on: January 15, 2019, 03:56:46 am »
My clipping issue was solved by
Code: [Select]
slZdsplevel(7);
, thanks guys.

It has, however, introduced a new issue. The camera seems to warp objects near the edge of the screen. I'm not sure if this is a fundamental issue with projections, a feature, or a setting I'm not changing. Images attached. I don't want to go full on orthographic, but the warping seems a bit extreme.

I have also made an attempt to use the Jo Map Editor to import a 3D file I made in Blender and exported as a Collada file, a simple textured cube. I'm fairly certain I created and exported the file correctly, but attempts at loading and drawing the converted 3d model + texture have left nothing on screen. I also discovered that the coordinate points that are apparently generated for my model are massive compared to the numbers I'm used to using. I tried moving backwards by more than the 3276800 units but still saw nothing and polygon counts confirm it. The generated header from the Map Editor .dae conversion is partially below:

Code: [Select]
static POINT    PointCube[] =
{
{3276800, 3276800, -3276800},
{3276800, -3276800, -3276800},
{-3276800, -3276799, -3276800},
{-3276799, 3276800, -3276800},
{3276800, 3276798, 3276800},
{3276798, -3276803, 3276800},
{-3276800, -3276799, 3276800},
{-3276800, 3276800, 3276800},
};

static POLYGON    PolygonCube[] =
{
{{0, 0, -65536}, {0, 1, 2, 3}},
{{0, -65536, 0}, {4, 7, 6, 5}},
{{-65536, 0, 0}, {0, 4, 5, 1}},
{{0, 0, 65536}, {1, 5, 6, 2}},
{{0, 65536, 65536}, {2, 6, 7, 3}},
{{65536, 65536, 0}, {4, 0, 3, 7}},
};


sbf2009

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Re: Help With SGL: Back-Face Culling and Camera Clipping
« Reply #4 on: January 15, 2019, 03:59:09 am »
I've attached the .dae I'm using to generate the header file if you wished to test it out yourself.

ponut64

  • Full Member
  • ***
  • Posts: 219
  • Karma: +22/-1
    • View Profile
Re: Help With SGL: Back-Face Culling and Camera Clipping
« Reply #5 on: January 15, 2019, 11:53:56 am »
1 - The Saturn has texture warping. It's going to happen. Particularly, it's going to happen whenever a polygon has one of its vertices leave the edge of the screen. This is completely normal, and you shouldn't worry about it, because you can't fix it without polygon subdivision. Which you shouldn't worry about yet.

2 - Try using a .obj file instead of .dae. I've never used .dae but I know .objs import fine.

3 - That model is definitely too big. You never saw it because the render space is a FIXED-point value (16 bit whole number, 16 bit decimal). At >32768, you can't leave the render space for that so you were always inside the model. Additionally, all 4 vertices of every face were always off-camera so nothing could come into view anyway.
« Last Edit: January 15, 2019, 11:57:05 am by ponut64 »

sbf2009

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Re: Help With SGL: Back-Face Culling and Camera Clipping
« Reply #6 on: January 16, 2019, 01:35:21 am »
The model is a simple cube in blender of default size 1.

I have been attempting to export it as a Wavefront (.obj) file. Using the Jo Map Editor,  I export it as a header. Simply including the header crashes my game to the point where even the printf statements don't appear. I think at this point, it'd be more appropriate to move over to the Jo Map Editor forum and pose my questions there, and return to the topic of backface culling later.

Thanks for the help.

 

Sitemap 1 2 3 4 5 6 7 8 9 10