Jump to content

Fixed Stencil Shadows


Recommended Posts

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
Link to comment
  • 5 weeks later...

@@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.

Keyten, Stoiss, Lancelot and 2 others like this
Link to comment

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.

Link to comment

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.

Link to comment

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.

Link to comment

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

Link to comment

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...