Force 2 sided rendering

Posted By: Stratego

Force 2 sided rendering - 07/15/13 23:28

This is probably a stupid question, but off-hand does anyone know how to force 2-sided rendering for things like tree leaves? Is there a flag to set?
Posted By: Superku

Re: Force 2 sided rendering - 07/15/13 23:32

You have to use a shader for this (for instance the diffuse lighting shader from the online tutorial -> shader workshops), then write
CullMode = None;
in the pass before the shader compile instructions.
Posted By: Stratego

Re: Force 2 sided rendering - 07/15/13 23:35

So, then do you think it makes more sense to just have double the leaf polygons, or go the shader way.

Thanks for the quick answer!
Posted By: Superku

Re: Force 2 sided rendering - 07/15/13 23:36

Always the shader way!
Posted By: Stratego

Re: Force 2 sided rendering - 07/15/13 23:39

I'll give it a shot. Do you foresee me having any problems with transparency?

Thanks again! You are awesome!
Posted By: Anonymous

Re: Force 2 sided rendering - 07/15/13 23:59

Lol I remember when I ask for this as a flag in WED. And now we had a double sided material.
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Main=45446&Number=378337#Post378337

Manual says its in mtlFx.c
Quote:
mtl_twosided
mtl_twosided_alpha
Posted By: Stratego

Re: Force 2 sided rendering - 07/16/13 00:32

Well, setting CullMode = None; in the Diffuse shader worked good. I had to set the OVERLAY flag for it to sort correctly. Is that the correct way to do it? Or does anyone know of a better way?

Thanks Malice! I'll try that way too.

Edit: I have A7 Commercial which seems to not have the double sided material.
Posted By: Anonymous

Re: Force 2 sided rendering - 07/16/13 00:45

Hum A7 , what version of the A7 engine?
Posted By: Stratego

Re: Force 2 sided rendering - 07/16/13 00:47

7.866. Latest addition as stated in my profile. Why do you ask?
Posted By: Anonymous

Re: Force 2 sided rendering - 07/16/13 00:59

I had A7 when I ask jcl for the two-sided material and I thought it was add to the A7. I must be mistaken.

Looking at the timeline I must have had A8.
Posted By: Stratego

Re: Force 2 sided rendering - 07/16/13 01:05

Okay so this is my result:



I threw this tree together today. It's not quite done, but I decided to see if I could get it running real-time. So I dusted off good old Gamestudio.

If anyone else has any suggestions for vegetation, let me know.

Also, this seems like something common, since outdoor scenes will likely require it. Maybe there should a place where common questions and answers are listed?
Posted By: Anonymous

Re: Force 2 sided rendering - 07/16/13 01:12

Is this any different then what you have?

Code:
effect = "technique { pass { CullMode = None; AlphaTestEnable = True; ZWriteEnable = true;} }";

Posted By: Stratego

Re: Force 2 sided rendering - 07/16/13 01:14

Yes, actually. I put it in a diffuse shader. I'll give that a try.
Posted By: Stratego

Re: Force 2 sided rendering - 07/16/13 01:27

Okay, so I tried what Malice suggested:

effect = "technique { pass { CullMode = None; AlphaTestEnable = True; ZWriteEnable = true;} }";

Here's the result:



This results has a much more prevalent blue outline around the transparent areas then when I used the OVERLAY flag and putting CullMode = None; into the diffuse shader from the workshops.

I think this way looks worse. Am I just getting lucky with OVERLAY, because I'm not sure it is supposed to help in this case, but I was fiddling around?

Edit: actually after looking at them, I'm not sure which I like more.
Posted By: Stratego

Re: Force 2 sided rendering - 07/16/13 02:00

In case anyone cares, I adjusted the lighting in the diffuse shader to better match the default lighting.

Result:



I think this is the better of the two, the difference is (and experts correct me if I'm wrong) the OVERLAY flag cuts off transparency completely while the other method allows gradients in transparency, so the outline effect is more prevalent. For my situation this looks better, but mileage may vary.

Edit: One last thing of note. The blue outline I was referring to earlier that seems to outline transparencies seems directly related to the background color (sky_color) even though I have a sky cube set up. Setting sky_color to a more desaturated color helped an incredible amount.
Posted By: Anonymous

Re: Force 2 sided rendering - 07/16/13 16:33

Sky_color should be set to vector(0,0,0) if you use a sky_cube. You pick up many fps if you do this but I have no idea what will happen to the outline.
Posted By: Stratego

Re: Force 2 sided rendering - 07/16/13 16:48

Thanks Malice! It's been so long I've forgotten just about everything. It took me a half hour just to find sky_color!

Looks like if sky_color is set to 0,0,0 then the outline picks up the colors of the sky cube, so in some cases (like if you have a crazy sky) it might be beneficial to still use sky color for a dimmer outline if the fps hit isn't that bad.
Posted By: sivan

Re: Force 2 sided rendering - 07/17/13 06:35

hi ,

I use the following and fine with overlay too:

Code:
technique animTree
{
	pass 
		{
			ZWriteEnable 		= True;		
			AlphaTestEnable 	= True;
		   AlphaBlendEnable 	= False;		   
			VertexShader = compile vs_2_0 animTree_VS(); 
		}
}

Posted By: Stratego

Re: Force 2 sided rendering - 07/17/13 15:27

So I've settled on this for now. In hindsight it seems pretty simple, but maybe it will be helpful for someone new who digs up this thread in the future.

I set up a material for the tree, and added the line:

effect = "technique { pass { AlphaTestEnable = True; ZWriteEnable = True; AlphaBlendEnable = False; CullMode = None;} }";

Thanks to everyone for all their help! I think this does what I wanted originally. I won't reply to this thread anymore as I have started a new one in "shaders" for more complicated tree techniques.
Posted By: Stratego

Re: Force 2 sided rendering - 07/17/13 17:35

Okay, so I lied. I have one more thing to add.

After some testing I have concluded that it makes more sense to use double the polygons for the leaves (undersides' normals are flipped). This way leaves are lit correctly -the undersides of leaves aren't lit the same as the top sides. This leads to much better tree lighting in my opinion. Here is an example of the same tree but with both sides of leaf planes modeled out (ambient probably needs to be adjusted, but you get the idea):



Also, after trying out the animTree.fx I've come to the conclusion that trunk and leaves should should be separate models because the trunk looks really funky when the vertices are waving around, but the leaves look great.
Posted By: Anonymous

Re: Force 2 sided rendering - 07/17/13 17:45

Could you maybe post a video of the animTree.fx with the shader soon?
© 2024 lite-C Forums