This project is read-only.

goblin xna transparency and other effects

Aug 23, 2010 at 6:41 PM


i've tortured myself with making goblin xna render transparency in a normal way for a long time. i even make code for rendering models using xna - that helped actually. but in this case i had to write code for caculating all transformations obtained from marker node and apply them on a model. that was not perfect, thats why i decided to return back to model rendering using goblin. 

but still, i haven't succeded.

i really need wise guru advice: how to make effects such as transparency, blur, bloom or others available within goblin xna?

thank you in advance.

Aug 24, 2010 at 12:43 AM

The current DefaultTransparencyComparer does not take the marker transformation into consideration for sorting transparency, so you need to implement one that considers the marker transform as well (you can simply take DefaultTransparencyComparer. and multiply x.BoundingVolume.Center with x.MarkerTransform to get the actual position in AR world, and use that to sort the transparency). I just realized that 

if (thisDist > otherDist)                return 1;            else if (thisDist == otherDist)                return 0;            else                return -1;

should be:

if (thisDist > otherDist)                return -1;            else if (thisDist == otherDist)                return 0;            else                return 1;

Also, you need to change the line in Scene.cs where the transparent nodes are sorted to be sorted every frame since marker transform changes every frame. Right now, it resorts them only when eye transform changes or a new transparency object is added to the scene.

For post process effects such as blur or bloom, it can be tricky in AR scene since you may want to separate the background image with the 3D objects. I'm still experimenting with it to find a general and optimal way to perform them in Goblin.


Aug 24, 2010 at 12:53 AM

thank you for your reply!! i will try transparency trick shortly.

and what about reflection? are there any ways to implement this effect with goblin?

Aug 24, 2010 at 1:14 AM

For any effects other than the default shader we provide, you should implement yourself. Please see Tutorial 11 for how to implement your own shader and use it with Goblin. You will need to have a good understanding of HLSL and how to deal with Effect loaded from model files. You may need to implement your own ModelContentProcessor if you need additional vertex info passed to the shader file such as Tangent or Binormal. For implementing shaders, it's good to take look at XNA samples in Creators Club.

Also, reflection can be computationally expensive if you want to generate dynamic environment cubemap since it requires your to draw the scene 6 times plus the actual rendering.


Aug 24, 2010 at 11:41 AM

i've tried to apply the bloom sample ( ideas to the goblin models. there is written a GameComponent (BloomComponent inherited from GameComponent) that uses the shader for bloom effect and it is added to the game components list in initialization. i did the same in my goblin xna game (added BloomComponent to the Components list), but i'm not succeeded with that. no video background neither model were bloomed.

maybe i'm doing wrong? should be this component added in a different way? i noticed that there are also some goblin xna component in a Component list in the game. maybe it makes postprocess after bloom component does, so i cant see the effect?...

thanks in advance in thanks for your help and explanations=)

Aug 24, 2010 at 4:05 PM
Edited Aug 24, 2010 at 4:07 PM

ok. i succeeded with bloom on whole image, including video picture as well =) the problem solved simply - by changing DrawOrder in bloom component to more that 101, because goblin xna component has DrawOrder 101.

so now, next step - is how to make model bloomed, not the video. one approach i found on xna forums is to use alpha channels as mask. that works for sample. the main idea is to change BloomExtract.fx shader so it could pick the data should be bloomed and dont touch those pixels, which shouldn't. you can find here a discussion

the main steps as i understood are these:

1. erase alpha channel for buffer before rendering background 

2. render background

3. fill the alpha channel for buffer (that would be like an indicator for shader to enable bloom effect)

4. render model.

as a result we obtain bloomed model on a normal background - that what we need in our goblin game, right?

as far as i see, the problem with goblin is to somehow get into the moment and add some code (like filling and erasing alpha channels) before rendering background video and after rendering background video.

i would appreciate any help from those who knows how to implement this =) or maybe there are some other ways?

ohanoda, you said, that you're experimenting with it, arent you? may be we can exchange our ideas?

thanks in advance 

Sep 2, 2010 at 12:06 PM

Thanks for the suggestions. I will think about the best steps once I'm done with my deadlines in mid-October. Some examples may be included with the next release if it works well.