Tree Issues with Toon Shader /Transparency and other stuffs

Hi guys ,



I imported a tree model that i have made in 3DSMAX as a XML , and i’m using toon shader from JME3 i have this following issue :



http://img713.imageshack.us/img713/2179/treeissue.png





As you can see there are some edge around every rectangle , also i have a strange alpha layer around some leaf only but not in other leaf… very strange.



Here is my Material code :



[java]

material mat_tronc

{



technique

{

pass

{

ambient 0.588235 0.588235 0.588235 1

diffuse 0.588235 0.588235 0.588235 1

specular 0 0 0 1 10

emissive 1 1 1 1





texture_unit

{

texture texture_arbre_01.jpg

}

}



}



}







material mat_feuilles

{



technique

{

pass

{

lighting off

ambient 0.588235 0.588235 0.588235 1

diffuse 0.588235 0.588235 0.588235 1

specular 0 0 0 1 10

emissive 0.000000 0.000000 0.000000 1.000000

cull_hardware none

cull_software none

scene_blend alpha_blend

depth_write off

alpha_rejection greater 128

texture_unit

{

texture feuilles3.png

colour_op modulate

}







}



}



}

[/java]



Finally , is there any way to turn the rectangle in front of the camera so i never see plans at their side ?



Hope someone will help thank you

Well the cartoon edge shader, create edges around the meshes using depth and does not take transparency into account that’s why you have edges around the quads, it’s the same issue for SSAO, we’ll eventually fix it.



For the strange alpha layer, do you have the same issue without the cartoon edge shader?



For the last question you’ll have to attach each leaves quad to a billborad control. Look at TestBillBoard for an example.

Thanks nehon i’ll look into BillBoard , yes alpha layer i have the same issue without edge , and about the cell shader , how do i disable the shader on 1 model especially ?



Thanks again

one more question , i just tried to attach a billboard on my model , when i turn the camera the model is moving , how do i make it static and have only leaf moving since everything are on the same model ? thank you

danath said:
how do i disable the shader on 1 model especially ?

The toon shading is done with a color ramp, remove it on the model you don't want to use it, but the edge are in a full screen pass so you can't disable it for one model.

danath said:
one more question , i just tried to attach a billboard on my model , when i turn the camera the model is moving , how do i make it static and have only leaf moving since everything are on the same model ? thank you

no the model must be split into several geometries, you must look into the model node for it's children and attach a billboard control to each geometry except for the trunk.

I’ll do that thanks ,



So i guess we can’t do any game at the moment with Cell Shading and Tree ? Maybe another suggestion ?

No one is using trees with Cell shader ?

Just disable the cell shader for the leaf textures and add it manually to the leaf texture externally .

As chell shading is only supposed to surround the geometry with lines, no the content of it.



Or use a tree model that fits better for cell shading

EmpirePhoenix said:
Just disable the cell shader for the leaf textures and add it manually to the leaf texture externally .
As chell shading is only supposed to surround the geometry with lines, no the content of it.

Or use a tree model that fits better for cell shading



nehon just said ( and he's right i checked ) that the edge is full pass , how do you disable and add it manually ?

Hm right, onyl read the first part of that sentence :confused:

I wish to know how to create a shader , i didn’t understood anything at all of how to do this , i could modify the edge shader to have a function like the maketoonish one but i don’t know how to do that , if you are in mind to do this then it would be wonderful :slight_smile:

honestly it’s not a trivial matter, and it does not only require to know your way around with shaders.

It’s the same issue for SSAO, I know how to do this, but i need to figure out the best way of doing this in jME3 because it implies some changes in the way depth is computed for Filters.



Your options are :

  • turn off toon shading on your entire game (I guess it’s not really an option :p)
  • As EmpirePhoenix advised, use a tree model with a one mesh foliage with no transparency
  • Wait until I make this work and keep the edges on your foliage for now.

I’ll choose option 3 and i’ll wait , anyway thank you so much nehon you’ll have credits on my project in the thanks room.



Good luck for this !



i really need to study about shaders >_<

You mean i’m gonna be famous ?? :stuck_out_tongue:



Shader are not as complicated as one would think. I made an overview that could help you in the jME3 doc here

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:jme3_shaders



Then i guess you’ll have to search google. There are plenty of tutorials, explanations, example codes out there.

And…you’ll probably have to refresh your math (at least i had to :p)

nehon said:
You mean i'm gonna be famous ?? :p

Shader are not as complicated as one would think. I made an overview that could help you in the jME3 doc here
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:jme3_shaders

Then i guess you'll have to search google. There are plenty of tutorials, explanations, example codes out there.
And...you'll probably have to refresh your math (at least i had to :p)


I will also add normen , momoko_fan , void (<3) and empirephoenix who helped me a lot when i needed help !

I'll give a try i have a math professor on my team maybe he will explain to me some good stuffs lol.

Alright this is in.

In last SVN you have a nice TestTransparentCartoonEdge test case that does exactly what you want.



BUT…in order to make it work properly you have to add a parameter to your leaves material.

in your material file (or directly in your code) set the AlphaDiscardThreshold to a value between 0 and 1.

like this



Material Leaves : Common/MatDefs/Light/Lighting.j3md {



Transparent On



MaterialParameters {

DiffuseMap : Models/Tree/Leaves.png

UseAlpha : true

AlphaDiscardThreshold : 0.5

UseMaterialColors : true

Ambient : .5 .5 .5 .5

Diffuse : 0.7 0.7 0.7 1

Specular : 0 0 0 1

Shininess : 16

}

AdditionalRenderState {

Blend Alpha

AlphaTestFalloff 0.50

FaceCull Off

}

}



0.5 means any pixels that have an Alpha value below 0.5 will be discarded.



This is tweakable by materials so if you have a translucent material it still works :smiley:



Also i added some parameters to the cartoonEdgeFilter



edgeWidth = 1.0;

edgeIntensity = 1.0;

normalThreshold = 0.5;

depthThreshold = 0.1;

normalSensitivity = 1.0;

depthSensitivity = 10.0;



try them to tweak the appearance of the edges.

YOU are the best ! thank you i’ll test it asap !

Don’t forget to post a screenshot when it’s done :smiley:

we like screenshots a lot

Sure i’ll do that tomorow , since i couldn’t access to the game for personnal reason i’ll test it today thanks again !

It didn’t work , i have exactly the same problem , here are my materials :





[java]

Material Leaves : Common/MatDefs/Light/Lighting.j3md {



Transparent On



MaterialParameters {

DiffuseMap : Models/Terrain/Arbre/feuilles3.png

UseAlpha : true

AlphaDiscardThreshold : 0.5

UseMaterialColors : true

Ambient : .5 .5 .5 .5

Diffuse : 0.7 0.7 0.7 1

Specular : 0 0 0 1

Shininess : 16

}

AdditionalRenderState {

Blend Alpha

AlphaTestFalloff 1

FaceCull Off

}

}

[/java]



[java]

Material Trunk : Common/MatDefs/Light/Lighting.j3md {

MaterialParameters {

DiffuseMap : Repeat Models/Terrain/Arbre/texture_arbre_01.jpg

UseMaterialColors : true

Ambient : 0 0 0 1

Diffuse : 1 1 1 1

Specular : 0 0 0 1

Shininess : 16

}

}

[/java]



I don’t need to retake a screenshot since it’s the same issue. How can i debug this ?