If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
// ...
pvr_init_params_t pvr_params = {
{ PVR_BINSIZE_16, PVR_BINSIZE_16, PVR_BINSIZE_16, PVR_BINSIZE_16, PVR_BINSIZE_16 },
512 * 1024
}; // changing any of this has no effect
//...
void main()
{
pvr_init (&pvr_params);
pvr_set_bg_color (0, 0, 0);
while(1)
{
pvr_wait_ready();
pvr_scene_begin();
pvr_list_begin(PVR_LIST_OP_POLY);
do_transforms();
render_scene();
pvr_list_finish();
pvr_list_begin(PVR_LIST_OP_MOD);
do_transforms();
render_modifier();
pvr_list_finish();
pvr_scene_finish();
}
}
// only parts related to setting up context are included below
void render_scene()
{
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
// ...
pvr_poly_cxt_col (&cxt, PVR_LIST_OP_POLY;);
cxt.gen.shading = PVR_SHADE_GOURAUD;
cxt.gen.culling = PVR_CULLING_NONE;
if (modifier_enabled)
{
cxt.fmt.modifier = PVR_MODIFIER_ENABLE;
cxt.gen.modifier_mode = PVR_MODIFIER_CHEAP_SHADOW;
}
pvr_poly_compile (&hdr, &cxt);
pvr_prim(&hdr, sizeof(hdr));
// vertex submissions...
}
void render_modifier()
{
pvr_mod_hdr_t mod_hdr;
pvr_mod_hdr_t mod_hdr_last;
pvr_modifier_vol_t mod_cur_vert;
pvr_mod_compile (&mod_hdr, PVR_LIST_OP_MOD, PVR_MODIFIER_OTHER_POLY,
PVR_CULLING_NONE);
pvr_mod_compile (&mod_hdr_last, PVR_LIST_OP_MOD, PVR_MODIFIER_INCLUDE_LAST_POLY,
PVR_CULLING_NONE);
mod_cur_vert.d1 = mod_cur_vert.d2 = mod_cur_vert.d3 =
mod_cur_vert.d4 = mod_cur_vert.d5 = mod_cur_vert.d6 = 0;
pvr_set_shadow_scale (1, transparency);
for(i = 0; i < f_count; i++)
{
fa = faces[i].a;
fb = faces[i].b;
fc = faces[i].c;
mod_cur_vert.flags = PVR_CMD_VERTEX_EOL;
mod_cur_vert.ax = trans_verts[fa].x;
mod_cur_vert.ay = trans_verts[fa].y;
mod_cur_vert.az = trans_verts[fa].z;
mod_cur_vert.bx = trans_verts[fc].x;
mod_cur_vert.by = trans_verts[fc].y;
mod_cur_vert.bz = trans_verts[fc].z;
mod_cur_vert.cx = trans_verts[fb].x;
mod_cur_vert.cy = trans_verts[fb].y;
mod_cur_vert.cz = trans_verts[fb].z;
if (i < (f_count-1))
{
// 5f current triangle is not the last one,
// then send it as OTHER_POLY
pvr_prim(&mod_hdr, sizeof(mod_hdr));
pvr_prim((void*)&mod_cur_vert, sizeof(mod_cur_vert));
}
else
{
// otherwise, send it as INCLUDE_LAST_POLY
pvr_prim(&mod_hdr_last, sizeof(mod_hdr_last));
pvr_prim((void*)&mod_cur_vert, sizeof(mod_cur_vert));
}
}
}
At this point, I believe I've tried everything to fix this with no luck. What was already tested and did not help:
- disabling\changing culling order
- changing triangles order
- testing other convex shapes
- sending ALL modifier triangles as INCLUDE_LAST_POLY. Now this one is interesting. While it does result in this:
Spoiler!
which is obviously not the result I needed, at least it works the same way on the real hardware, which confirms that the problem is not related to clipping\culling.
I really can't see anything wrong here. Do I miss something? Any ideas?
FIXED!
In order for this to work properly on real HW, you must set bit 6 (PVR_TA_CMD_MODIFIERMODE) in "cmd" parameter of pvr_mod_hdr_t for the last triangle (as described in "DCDBSysArc990907E.pdf")
All credit goes to MetalliC (one of the developers of Demul ) , without his help, I would never figure it out myself.
I've never worked with any version control systems and I'm not bothered enough to deal with git just for one commit, so someone else should do that instead I guess.
For such a small change it doesn't really matter. If you make bigger changes just use "git diff --no-prefix" and post the output on the forums (you can save it as a pvr-mod-fix.patch text file for example).
The patch seems to make sense, but I'll let others chime in too.