[SOLVED] Cheap Shadows rendering issue

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.
Post Reply
111
DCEmu Junior
DCEmu Junior
Posts: 42
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Jul 07, 2016 7:11 pm
Has thanked: 0
Been thanked: 6 times

[SOLVED] Cheap Shadows rendering issue

Post by 111 »

So I have this simple scene with a cube (used as modifier volume):
Spoiler!
Image
(disregard translucent teapot, removing it does not change anything)

That 's how it is supposed to work and it does so on emulators.

However, testing on real hardware gives me this:
Spoiler!
Image
Here is the code:
Spoiler!

Code: Select all

// ...

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!
Image
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?


By the way, I'm well aware of other issues with modifiers (as described here: http://yam.20to4.net/dreamcast/index_old.html), but it's not related.
Last edited by 111 on Mon Jun 19, 2017 10:34 pm, edited 1 time in total.
111
DCEmu Junior
DCEmu Junior
Posts: 42
Joined: Thu Jul 07, 2016 7:11 pm
Has thanked: 0
Been thanked: 6 times

Re: Cheap Shadows rendering issue

Post by 111 »

... switching to pvr_vertex_pcm_t does not help either (same result). Now I'm totally lost :\
111
DCEmu Junior
DCEmu Junior
Posts: 42
Joined: Thu Jul 07, 2016 7:11 pm
Has thanked: 0
Been thanked: 6 times

Re: Cheap Shadows rendering issue

Post by 111 »

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.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: [SOLVED] Cheap Shadows rendering issue

Post by bogglez »

Thanks for sharing the solution and sorry we were of no help :D
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
111
DCEmu Junior
DCEmu Junior
Posts: 42
Joined: Thu Jul 07, 2016 7:11 pm
Has thanked: 0
Been thanked: 6 times

Re: [SOLVED] Cheap Shadows rendering issue

Post by 111 »

^ that's fine.

However, I do suggest to include this fix to kos. Something like this should do:
void pvr_mod_compile(pvr_mod_hdr_t *dst, pvr_list_t list, uint32 mode,
uint32 cull) {
dst->cmd = PVR_CMD_MODIFIER;
dst->cmd |= (list << PVR_TA_CMD_TYPE_SHIFT) & PVR_TA_CMD_TYPE_MASK;

if (mode) // if not PVR_MODIFIER_OTHER_POLY
dst->cmd |= (1 << PVR_TA_CMD_MODIFIERMODE_SHIFT);


dst->mode1 = (mode << PVR_TA_PM1_MODIFIERINST_SHIFT) & PVR_TA_PM1_MODIFIERINST_MASK;
dst->mode1 |= (cull << PVR_TA_PM1_CULLING_SHIFT) & PVR_TA_PM1_CULLING_MASK;

dst->d1 = dst->d2 = dst->d3 = dst->d4 = dst->d5 = dst->d6 = 0;
}
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.
User avatar
bogglez
Moderator
Moderator
Posts: 578
Joined: Sun Apr 20, 2014 9:45 am
Has thanked: 0
Been thanked: 0

Re: [SOLVED] Cheap Shadows rendering issue

Post by bogglez »

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.
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
BB Hood
DC Developer
DC Developer
Posts: 189
Joined: Fri Mar 30, 2007 12:09 am
Has thanked: 41 times
Been thanked: 10 times

Re: [SOLVED] Cheap Shadows rendering issue

Post by BB Hood »

I see that nobody has discussed this and it is not included in the current KOS. BUMP

NOTE: I have not tested this and have no knowledge of modifier volumes.
Attachments
pvr-mod-fix.patch
diff file
(764 Bytes) Downloaded 80 times
Post Reply