Double sided shader that works with PSSM

Posted By: jumpman

Double sided shader that works with PSSM - 05/11/17 00:03

Hi everyone, I am using this 2 sided shader that cuts out the alpha information and correctly sorts polygons:

Code:
MATERIAL* mat_Correct_Alpha_3 =    //------------------------------- CORRECT SORTING OF TGA ALPHA IN A MODEL!! 2 sided
{


	specular_blue = 100;
	specular_green = 100;
	specular_red = 100;
	
	power = 10;



		flags =   ENABLE_TREE | PASS_SOLID;
	//my.transparent=on;
	
	effect="
	
	

		DWORD ref=128.0f;
	
	technique test
		{		pass p0	
		
		
			{			
			
			cullmode=NONE;
			zenable=true;
			zwriteenable=true;
			alphablendenable=false;
			alphatestenable=true;
			AlphaRef=<ref>;
        	AlphaFunc=Greater;
	
	
			}	
			
			}
			
				";
}



Is there a way to get this shader, or any shader to work on both sides for PSSM shadows? The shadows are correctly cast on the main side of a triangle, but the backside (cullmode=NONE) of the polygon, you can see the shadow through it!
Posted By: sivan

Re: Double sided shader that works with PSSM - 05/11/17 07:31

to be honest PSSM shadows are slow, I got much better performance AND quality in MapBuilder by the non-stencil-buffer based solution, using Slin's shadow cascade calculation... and never had problem with any transparent stuff.
Posted By: jumpman

Re: Double sided shader that works with PSSM - 05/15/17 06:09

Mapbuilder has a shadow solution that can only be run with Mapbuilder? Or can that shader be used with WED?
Posted By: sivan

Re: Double sided shader that works with PSSM - 05/16/17 04:25

it is modular and can be used in any project, similarly to the water and terrain shaders. I can help you...
Posted By: jumpman

Re: Double sided shader that works with PSSM - 05/16/17 04:37

I would like that! Where can I download a demo/source file? I can send you a message if you'd like
Posted By: txesmi

Re: Double sided shader that works with PSSM - 05/16/17 14:03

Originally Posted By: jumpman
Where can I download a demo/source file?

look at his signature wink
Posted By: jumpman

Re: Double sided shader that works with PSSM - 05/16/17 14:39

I see it, thank you! Im assuming I can find the shadow code in here and extract it for my project?

Also, Sivan, mapbuilder looks pretty amazing. Have you ever thought about making the actual mapbuilder into a game itself? Like a premise where you are a level designer and you have to create a level for a player (governed by an AI)?
Posted By: sivan

Re: Double sided shader that works with PSSM - 05/16/17 15:32

originally I made it for my RTS, which worked fine, but finally decided to switch to unreal engine 4 in 2015, because in long term I felt it is safer, and I think it was a good decision.

but if anybody is creating a nice game with 3dgs I can help, it would be at least motivating to fix the current bug causing a crash on loading materials... laugh
Posted By: 3run

Re: Double sided shader that works with PSSM - 05/16/17 16:46

@sivan, if I'm not mistaken, you used shadows from older shade-c, right? I even got the rip-off, did you add any adjustments/tweaks to it (version I have does have darkness adjustments + different blurring algorithms, but not moving shadows from trees and grass)? If it's the latest version, I could share my ripoff with jumpman, but if there is a newer version, I would like to get my hands on it as well grin

Greets
Posted By: sivan

Re: Double sided shader that works with PSSM - 05/17/17 10:19

originally I used old shade-c one, but it was full with problems (no smooth borders), and used a custom and a bit strange lighting, so I totally rewrote it.

first I corrected the variance shadowmapping, and finally replaced it with another nicer faster approach called exponential shadowmapping, which is still up to date, and enough to use only 1 or 2 cascades. this technique used in unreal engine too (but UE4 does it faster even for 4 cascades). you can find it in scsm.h and scsm.c

moreover I rewrote pssm shadows to use Slin's custom split calculation. you can find it in pssm.h and pssm.c

if you search the project for pssm/scsm _init() _start() and _close() functions you can see how simple to use it.
Posted By: 3run

Re: Double sided shader that works with PSSM - 05/18/17 08:58

Thank you! Can I rip it off the mapbuilder for personal use and to share it with those who is looking for shadowmapping? Do we need to give you any credits? laugh

Edit: ripped off the scsm, tried to run Scsm_Start in main loop, no errors, but no shadows (included all .fx files mentioned in both .c and .h files). Tried settings SHADOW flag for level_ent and even tried to set FLAG6 (saw in somewhere in your code, I guess in mapent.c ?) but no luck. Where can I find materials related to scsm to apply them for level blocks etc? Plus there is still issue with no moving shadows after terrain and grass models (which are animated via shader).
Posted By: sivan

Re: Double sided shader that works with PSSM - 05/18/17 13:19

materials are set dynamically in MBmaterials.c according to actual shadow_stencil value (can be -1, 1, 8)

Code:
else //if (shadow_stencil == (var)-1)
				{
					// MB materials got shader to have self shadows
					effect_load(mtl_detail		,"sc_obj_sprite_MB.fx");				// obj_animGrass1_MB (no shadow response, bad with height fog) or sc_obj_sprite_MB
					effect_load(mtl_shrub		,"sc_obj_sprite_MB.fx");
					effect_load(mtl_grass 		,"sc_obj_grass1_MB.fx");
					effect_load(mtl_obstacle	,"sc_obj_model_MB.fx");
					effect_load(mtl_tree			,"sc_obj_tree1_MB.fx");
					effect_load(mtl_mapent		,"sc_obj_level_MB.fx");
					effect_load(mtl_terrmdl		,"sc_obj_model_MB.fx");
					effect_load(mtl_building	,"sc_obj_model_MB.fx");
					
					// 3DGS materials can be used to not to have self shadow
//					effect_load(mtl_terrain		,"sc_obj_model_MB.fx");					// not used, in action own shader
					effect_load(mtl_model		,"sc_obj_model_MB.fx");
					effect_load(mtl_sprite		,"sc_obj_sprite_st_MB.fx");	
					effect_load(mtl_flat			,"sc_obj_level_MB.fx");
					effect_load(mtl_shaded		,"sc_obj_level_MB.fx");
					effect_load(mtl_sky			,"sc_obj_sky_MB.fx");
					
//					mtl_tree.flags |= ENABLE_TREE;											// ENABLE_RENDER or ENABLE_TREE
//					mtl_tree.event = sc_tree_billboard_event;
					
					// RTS unit materials 
{}
#ifdef PLAY02_PS
					effect_load(mtl_bonesanim	,"sc_obj_bones_MB.fx");	// FIL	 	// slower SM3.0 shader with pixel shader - capability of player colour display
#else
					effect_load(mtl_bonesanim	,"obj_bones_MB.fx");		// FIL		// no pixel shader
#endif					
				}



but as I mentioned in the MapBuilder thread yesterday, there is a bug in loading settings from a file, so next week it is going to be fixed.
Posted By: sivan

Re: Double sided shader that works with PSSM - 05/18/17 13:20

of course you can rip it off, just give me credits.
I think earlier I made a separate demo and shared in the forum...
Posted By: 3run

Re: Double sided shader that works with PSSM - 05/19/17 10:02

I'm getting black screen :<

Didn't load any settings, since they are set to default values in scsm header. Applied all shaders via effect_load, as in your example. Compiles with no errors, all .fx files are included. Maybe you remember facing this issue? I'm pretty sure that it's easy to fix, I'm just missing something. Also, what about not moving shadows for animated (via shader) grass and tress?

Edit: also another question, were you able to get shadows working for animated sprites?


Best regards!
Posted By: sivan

Re: Double sided shader that works with PSSM - 05/21/17 15:09

I used animated sprites (as far lods of characters) with shadows. I don't know why you get black geometries, some material settings could be wrong. I can help next week I'm really tired now, I have finished today morning a one day long ultra-marathon in a team...
Posted By: 3run

Re: Double sided shader that works with PSSM - 05/21/17 18:08

Sounds awesome man! Did your team win?

It would be great if you could help us out with this. Having some shaders seperated from your project MapBuilder could be helpful for those who are still torment gamestudio grin

Best regards!
Posted By: Reconnoiter

Re: Double sided shader that works with PSSM - 05/31/17 19:33

Howdy, Sivan does your MapBuilder's shadowmapping work in combination with the shade-c (evo)?
(I am using shade-c (evo) now and while the sun shadows are fairly sharp it drains fps alot)

Quote:
Having some shaders seperated from your project MapBuilder could be helpful for those who are still torment gamestudio grin
, yes please be our knight in shiny armor smile
Posted By: sivan

Re: Double sided shader that works with PSSM - 06/01/17 16:45

no they are incompatible, moreover evo uses a deferred renderer I have no experience with.

I wanted to update Mapbuilder this week, but I have been very-very busy, so it should happen next week only...

my shadowmapping was developed for my RTS game, so its main purpose was to have something fast beside acceptable quality, preferably using only one depth view. it can be okay with high resolution beside keeping shadow area small, but near sharp edges some defects are often visible. so for a 1st or 3rd person game a pssm is better, but since using the stencil buffer with 3dgs results in bugs (related to transparency, mirror views, or terrain lod I don't know), a shader only version would be a better choice. I think I made earlier such a test project...
Posted By: Reconnoiter

Re: Double sided shader that works with PSSM - 06/02/17 11:04

Okay thanks for the info.
Posted By: jumpman

Re: Double sided shader that works with PSSM - 06/21/17 16:48

Hey everyone, is there a way to change the shadow color of gamestudios PSSM shadow? Or can it only be black?
Posted By: sivan

Re: Double sided shader that works with PSSM - 06/22/17 10:49

imo it is possible..... maybe by stencil_color or something similar
Posted By: sivan

Re: Double sided shader that works with PSSM - 06/22/17 10:52

NO!

from manual:

The transparency of stencil shadows can be set through mtl_shadow.alpha (default = 50), and their color can be set through mtl_shadow.diffuse_blue, mtl_shadow.diffuse_green, and mtl_shadow.diffuse_red (default = 0,0,0 = black).
Posted By: jumpman

Re: Double sided shader that works with PSSM - 06/23/17 14:57

those settings are for stencil shadows only, correct? I changed these settings, switched to stencil shadows, and was able to change the shadow colors. However these settings dont change the PSSM shadow colors.
Posted By: sivan

Re: Double sided shader that works with PSSM - 06/24/17 13:19

ahh sorry. then you have to change the pssm shader. I remember once I made it for debugging the different cascades, not too tricky. but it's on my old pc, not yet ported my 3dgs stuff to the new one.
Posted By: jumpman

Re: Double sided shader that works with PSSM - 06/26/17 20:39

thank you, thats what im trying to figure out
© 2024 lite-C Forums