Skip to content

Commit

Permalink
fix bug with am.cull_face node where winding was reversed
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Jul 31, 2018
1 parent 0cc7773 commit 97cc1e3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions doc/scene_nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,10 @@ Culls triangles with a specific winding.

The possible values for `face` are:

- `"back"`: Cull back-facing triangles (same as `"cw"` below)
- `"front"`: Cull front-facing triangles (same as `"ccw"` below)
- `"cw"`: Cull clockwise wound triangles.
- `"ccw"`: Cull counter-clockwise wound triangles.
- `"back"`: Cull back-facing triangles (same as `"cw"`)
- `"front"`: Cull front-facing triangles (same as `"ccw"`)
- `"none"`: Do not cull any triangles.

Fields:
Expand Down
2 changes: 1 addition & 1 deletion examples/3dsandbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function init()
am.lookat(vec3(0, 0, 0), vec3(0, 0, -1), vec3(0, 1, 0)) ^ objects

win.scene =
am.cull_face("ccw")
am.cull_face("back")
^am.use_program(shader)
^am.bind{P = math.perspective(math.rad(70), win.width/win.height, near_clip, far_clip)}
^camera
Expand Down
10 changes: 5 additions & 5 deletions src/am_culling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ void am_cull_face_node::render(am_render_state *rstate) {
am_cull_face_state old_state = rstate->active_cull_face_state;
switch (mode) {
case AM_CULL_FACE_MODE_FRONT:
rstate->active_cull_face_state.set(true, AM_FACE_WIND_CCW, AM_CULL_FACE_FRONT);
rstate->active_cull_face_state.set(true, AM_CULL_FACE_FRONT);
break;
case AM_CULL_FACE_MODE_BACK:
rstate->active_cull_face_state.set(true, AM_FACE_WIND_CCW, AM_CULL_FACE_BACK);
rstate->active_cull_face_state.set(true, AM_CULL_FACE_BACK);
break;
case AM_CULL_FACE_MODE_NONE:
rstate->active_cull_face_state.set(false, AM_FACE_WIND_CCW, AM_CULL_FACE_BACK);
rstate->active_cull_face_state.set(false, AM_CULL_FACE_BACK);
break;
}
render_children(rstate);
Expand Down Expand Up @@ -154,9 +154,9 @@ void am_open_culling_module(lua_State *L) {
am_open_module(L, AMULET_LUA_MODULE_NAME, funcs);
am_enum_value cull_face_enum[] = {
{"front", AM_CULL_FACE_MODE_FRONT},
{"cw", AM_CULL_FACE_MODE_FRONT},
{"ccw", AM_CULL_FACE_MODE_FRONT},
{"back", AM_CULL_FACE_MODE_BACK},
{"ccw", AM_CULL_FACE_MODE_BACK},
{"cw", AM_CULL_FACE_MODE_BACK},
{"none", AM_CULL_FACE_MODE_NONE},
{NULL, 0}
};
Expand Down
6 changes: 2 additions & 4 deletions src/am_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,16 @@ void am_stencil_test_state::bind(am_render_state *rstate, bool force) {

am_cull_face_state::am_cull_face_state() {
enabled = false;
winding = AM_FACE_WIND_CCW;
side = AM_CULL_FACE_BACK;
}

void am_cull_face_state::set(bool enabled, am_face_winding winding, am_cull_face_side side) {
void am_cull_face_state::set(bool enabled, am_cull_face_side side) {
am_cull_face_state::enabled = enabled;
am_cull_face_state::winding = winding;
am_cull_face_state::side = side;
}

void am_cull_face_state::restore(am_cull_face_state *old) {
set(old->enabled, old->winding, old->side);
set(old->enabled, old->side);
}

void am_cull_face_state::bind(am_render_state *rstate, bool force) {
Expand Down
3 changes: 1 addition & 2 deletions src/am_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ struct am_stencil_test_state {
};

struct am_cull_face_state {
am_face_winding winding;
bool enabled;
am_cull_face_side side;

am_cull_face_state();
void set(bool enabled, am_face_winding winding, am_cull_face_side side);
void set(bool enabled, am_cull_face_side side);
void restore(am_cull_face_state *old);
void bind(am_render_state *rstate, bool force);
};
Expand Down

0 comments on commit 97cc1e3

Please sign in to comment.