Search Unity

Front Row like Reflections

Discussion in 'Shaders' started by alejobrainz, Mar 24, 2006.

  1. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    I'm attempting to build a gui similar to the front row black environment with subtle reflections, but in 3D. Is there any way to achieve this reflections/environment with unity pro?

    Thanks.
     
  2. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Yeah, render to texture can do this. You pick a camera to render as a texture. I think it is a matter of drag and drop, not sure I dont have pro, but yes you can do this. Very cool pro feature, you can use it for things like security cameras cameras too.

    Bill
     
  3. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Any pointers onto how to do this thorugh render to texture?
     
  4. PeterDahl

    PeterDahl

    Joined:
    Jun 13, 2005
    Posts:
    61
    Do you have a enviroment map (skybox) that you use ? It it is allright that it is static, you do not even need a pro but can just use the reflective shaders we ship.

    Are you talking about 3d buttons that are placed on the screen, and that can be moved around? it might be a little more dificult to do that... explain a little more of what the scene should look like, and I might be able to help. Reflections from dynamic scenes can be expensive to render though.

    - Peter
     
  5. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    The idea is to have a dark studio setup where a set of 3d buttons appear. These buttons do indeed move (actually roate) and I want to have a reflective ground plane. The idea is to achieve somthing like:

    http://www.apple.com/imac/frontrow.html
     
  6. PeterDahl

    PeterDahl

    Joined:
    Jun 13, 2005
    Posts:
    61
    I would recomend mirroring the geometry, and rendering it again with a slightly darker color. If you render under the reflecting plane you want to make blend the mirrored geometry in. If your buttons can move outside the plane, you would need to mask using the stencil or some other method, that might be a little more complicated.
    Another way could be to render the buttons only into a texture. You should set up the camera to render from under the plane, orthogonal to the view direction. This might only work from specific scenes though, where you are somewhat far away from the reflecting buttons.

    I think the mirroring is the best choice, especially if the reflecting is only on the plane and the buttons are always over the plane.

    - Peter
     
  7. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    Here is a quick reflection using render to texture. This is the first time I have tried this (and I am not experienced in this graphics stuff),so keep that in mind. I assume someone who knew what they were doing could clean it up, but as a proof of concept I think it shows what you might want to accomplish (movement being mirrored). This is the PPC binary.
     

    Attached Files:

  8. PeterDahl

    PeterDahl

    Joined:
    Jun 13, 2005
    Posts:
    61
    Come to think of it, since you have the pro (I think I misunderstood something perhaps) you can just use the water shader with no ripples... That should give you what you want I think..

    - Peter
     
  9. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    I tried the water reflection, but somehow it simply des not work right. I named the camera as needed, and it actuaally reflects, but the reflected image does not seem to refresh correctly. For example if I make a sphere over a reflective plane it starts correctly, but if I move the sphere, the plane will add the whole trajectory of the reflection, thus looking very odd. ie the reflection for the previous frames is not removed, but added! Am I missing something?

    Thanks!

    Alejandro
     
  10. PeterDahl

    PeterDahl

    Joined:
    Jun 13, 2005
    Posts:
    61
    It seems to work pretty well here...

    What is the "clear flags" set to on the camera that renderes the reflection? It should be set to solid color I guess, it sounds like it is set to dont clear.
    That should clear the render texture so it does not accumulate each frame.

    - Peter
     
  11. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Thanks. will try!
     
  12. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Did you drag in the water prefab?

    There is a lot more to setup than just attaching the water material to a plane. So i is best to just drag the water prefab in and modify the material from there to not have any ripples.
     
  13. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Worked like a charm ;)
     
  14. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
  15. PeterDahl

    PeterDahl

    Joined:
    Jun 13, 2005
    Posts:
    61
    It looks nice, but I thought you did not want any ripples on the water ? :)

    - Peter
     
  16. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Once I saw the prefab I just fell for it. I will post one with icons soon.

    I have a question.

    I want the camera to move slightly, just subtle slow rolls (+- 5 degree) and very slow movements always mantining its point of view. Is there a prefab or easy way to achieve this random slow moves?

    Thanks.
     
  17. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  18. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    I can see the mip-levels switch quite clearly on the water bumpmap... You should consider setting to trilinear and aniso sampling in the texture inspector....
     
  19. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Joachim,

    I implemented the look at controles an a random local position, but have no idea on hoy to damp the result of the position vector to make it really slow and smooth.

    Please look at this to have a laugh. Talk about handshake!!

    http://www.zerofractal.com/FractalReality/060406-menu-test.html

    This is the main concept but really really slow and smooth. This is my current component :)


    Code (csharp):
    1.  
    2.  
    3. //Smooth Camera shake Component - Zerofractal Studio
    4. var Radius = 0.25;
    5.  
    6. function Update () {
    7.     transform.localPosition = Random.insideUnitSphere * Radius;
    8. }
    9.  
     
  20. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Try smoothing it. (Note i haven't actually tried this)

    Code (csharp):
    1.  
    2. //Smooth Camera shake Component - Zerofractal Studio
    3. var Radius = 0.25;
    4. var smooth = 1.0;
    5. function Update () {
    6.    transform.localPosition = Vector3.Lerp(transform.localPosition, Random.insideUnitSphere * Radius, Time.deltaTime * smooth);
    7. }
    8.  
     
  21. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Thanks, but while this smoothes it out, it is equivalent to reducing the radius of the postiton vector, so I need to increase the radius, which again increses the speed and shkyness..

    What I have in mind is very slow but continuous translations, so that for example the camera moves slowly in one direction, then in another, etc etc. all in one smooth, chaotic single trajectory.
     
  22. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Noise is art. Fortunately many books have been written on the topic.

    Been toying around with fractal noise years ago so here comes the overkill solution. The Perlin noise based smooth position script.

    Put the Noise.cs script in a folder called Plugins or Standard Assets, this way you can access it from javascript.
    Then put the SmoothRandomPosition.js script anywhere.
     

    Attached Files:

  23. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Wow. thanks! just a problem. When assigning the js to my gameobject I get the following error:

    "Can't add script behaviour to SmoothRandomPosition. The script needs to derive from MonoBehaviour". Looking a bit further the problem narrows to unity not being able to loas script class "noise". any clues? I put the class on the root of standard assets with no luck.
     
  24. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Hmm. Try putting it into "Plugins"
     
  25. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Did you get it to work?
     
  26. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    worked like a charm. It seemed to be loading the script before the cs, just put the script outside the standard assets and it worked.

    It should be a nice addition to the camera scripts!

    http://www.zerofractal.com/fractalreality/060409-menu-test.html

    Just one side note. It seems that the range prosition in added to the original location, thus making the movement displace drom the original location. I think that by simply subtratting it from the position variable might do the trick.

    Thanks once again!
     
  27. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Man the water in pro looks good... *wimper* :(
    -Jeremy
     
  28. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Here is a small update:

    http://www.zerofractal.com/fractalreality/060410-menu-test.html

    Added images of the levels, and a higher res sky. One thing that bugs me is thta if you look at the box's semas you see a black line. Is there any way to aovid this? I'm cedrtain the skybox's edges are semaless.

    Now I have to work on the arrow navigation, and on the button click operations.

    I have anothe question. Is there a way to create the menu items on the fly? I am planning on writing a component in which you say how many buttons you want and the respective textures for each, and voila.

    Thanks
     
  29. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Make all the textures wrap mode to be clamped instead of repeating.
    This is setup in the texture inspector.
     
  30. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Worked!! Not really clear it should be like this, but nice to know.

    One question, is there a place where one could write/read this tips for newbies?
     
  31. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    I added it to the documentation for next release.
     
  32. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Thanks. Talking about skyboxes, is there a way to rotate the orientation of the skybox?
     
  33. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    Another Question.

    Is there any way to change the geometry of the water prefab? I want ot make a rectangular pool, and the prefab is an elliptic ocean.

    Thanks!
     
  34. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Yes. Just drag a mesh from project view onto the water.

    (All meshes of an imported asset are shown when you fold out the asset in the project view)
     
  35. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    And if its a plane created within unity and does not appear in the project view?
     
  36. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    There is no easy way to fit it around that. Just import a new mesh.
     
  37. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
  38. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    That looks fantastic! May I ask, what resolution is your skybox/pano?

    cheers.
     
  39. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288
    1024 x 6 maps
     
  40. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    thanks for that. also what FOV is your camera set at in the 3D world?

    cheers.
     
  41. alejobrainz

    alejobrainz

    Joined:
    Sep 10, 2005
    Posts:
    288