Jump to content

Fixed Stencil Shadows


Recommended Posts

Posted

I'd like to request that stencil shadows to be fixed so it shades the model better. This is what we currently have in-game:

 

m9ng21.jpg

 

I'm thinking gouraud shade the model as seen in cg_shadows 1, but project shadows from other objects (including its own body) onto it - if that makes sense.

Bek likes this
Posted

I've not implemented stencil shadows before so I can't make a guess as to why the shadowing looks like that. It should certainly be possible to fix it though. I've got a lot of unfinished things I need to do though (some kind of release for ModView being priority atm) so I don't have the time to look at it.

Circa, Tempust85, AshuraDX and 1 other like this
  • 5 weeks later...
Posted

@@Xycaleth @@ensiform @@eezstreet

 

Well this is interesting, I've accidently enabled stencil shadows for MD3 models:

 

k3orj6.jpg

 

All I did was comment out the RF_SHADOW_PLANE line under R_AddMD3Surfaces in tr_mesh.cpp:

		// stencil shadows can't do personal models unless I polyhedron clip
		if ( !personalModel
			&& r_shadows->integer == 2 
			&& fogNum == 0
			&& (ent->e.renderfx & RF_SHADOW_PLANE )
			&& !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK))
			&& shader->sort == SS_OPAQUE ) {
			R_AddDrawSurf( (surfaceType_t *)surface, tr.shadowShader, 0, qfalse );
		}

 Thing is, I can't understand why commenting that one line out would suddenly enable the stencil shadows. I would think that having the line in there would enable the shadows, not disable them.

Posted

Stencil shadows looks to be opt-in per ref entity. Commenting that out means all ref entities are opted in automatically (unless it doesn't match the other conditions).

Tempust85 likes this
Posted

That only works on md3 models that are not in the bsp.

 

Also, misc_model_static is explicitly marked as RF_NOSHADOW in MP.  Where it is not in SP.

Posted

map objects (.md3) always cast a shadow when you set the shadows to /cg_shadows 3 ..i think that was the cmd in console

 

so where is this " tr_mesh.cpp "  located `?

Posted

map objects (.md3) always cast a shadow when you set the shadows to /cg_shadows 3 ..i think that was the cmd in console

 

so where is this " tr_mesh.cpp "  located `?

Only ones that are not part of the bsp can be affected regardless of option.

Posted

It's a simple change to the formula-- just delete the divide by 2... no?

Nope.  You think idsoftware put the division by 2 there just for the hell of it?  It requires two times the amount of verts for shadows, ergo only 500 will be allowed for shadows to work.  The / 2 exists in q3 as well.

Posted

I read a comment about vertex buffer or something which must be why they have the 500 limit on stencils. Doesn't matter anyways so long as your model has LODs, as there is code to switch to the models lowest LOD if LOD0 hits the 500 limit.

Posted

Stencil shadows are rendered by redrawing the model but with it "flattened" on to the ground, and this is done at the same time as the ordinary model is rendered. The maximum number of vertexes which can be rendered in one go is 1000, so with stencil shadows enabled, half the limit is allocated for the regular model render, the other half is used for the "flattened" model. This is where the division by two comes from.

Posted

I read a comment about vertex buffer or something which must be why they have the 500 limit on stencils. Doesn't matter anyways so long as your model has LODs, as there is code to switch to the models lowest LOD if LOD0 hits the 500 limit.

Stencil shadows are rendered by redrawing the model but with it "flattened" on to the ground, and this is done at the same time as the ordinary model is rendered. The maximum number of vertexes which can be rendered in one go is 1000, so with stencil shadows enabled, half the limit is allocated for the regular model render, the other half is used for the "flattened" model. This is where the division by two comes from.

So are you saying that if LOD0 violates the 1000/2 (500) vertex limit the game automatically reverts to the next lower LOD to calculate stencil shadows???

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...