Search Unity

Relief maps with self-shadowing

Discussion in 'Made With Unity' started by cblarsen, May 21, 2008.

  1. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266




    Edit Nay 25: Should now work on more cards, particularly X800 Package also included again.
    Please let me know, if it doesn't run on your Shader Model 2 compatible graphics card


    Webplayer (1.1 MB):
    http://proglet.com/software/Relief_Pro/Relief_Pro_0_0_5.html

    Note: You can play with some settings by hitting <TAB> in the webplayer.

    The package is included below.
    Edit: ONLY WORKS ON PRO
    For Indie users, I previously posted a simpler version without shadows: http://forum.unity3d.com/viewtopic.php?t=10927

    To use:
    - Create a userdefined layer (I have used layer 8 and called it ReliefObjects)
    - Create an object with a renderer attached
    - Put the object on the ReliefObjects layer
    - set the material to use the Relief/Pro/Spec shader
    - Attach the "Relief" script to the object
    - Set the "Shadow light" variable to point to an object. The nearest light would be a good one.

    The shader will look weird in the editor view or the game view, if they are both open, and you may have to maximize the game view (to hide the editor view) for the effect to work properly.

    The self-shadowing only works with one light. The calculated shadow is applied to all pixel lighting.
     

    Attached Files:

  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That looks really amazing. Alas, the webplayer doesn't work on my X800. Instead, I get black lines and noise artifacts, and flickering rectangles. None of the controls seem to have any effect. The indie version worked without issues, and while it's still amazing, it's not quite as amazing as this version looks. ;)

    --Eric
     

    Attached Files:

  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I only see a pink background on my Macbook :/

    Needs more fallback shaders?
     
  4. Charles Hinshaw

    Charles Hinshaw

    Joined:
    Feb 6, 2008
    Posts:
    1,070
    MBP - all great.
    The floor looks painful to walk on... I kinda cringed as I walked around.
     
  5. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Damn. I had similar problems earlier on myself because of a race condition. Trouble is, if the GPU is deeply pipelined, the result of the first trace passes are not written to texture memory before the next pass tries to read the intermediate results. I solved it on my machine by actually having separate camera render calls for each phase.

    Or it might just be an X800 bug :(

    Have you tried switching all options off, so you just have the most simple trace?

    Actually it should fallback to bumped specular. That works fine under emulation.
    I should probably do some more explicit checking of the intermediate shaders and switch the main shader, if one of them fails.
     
  6. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    For those who had problems running this demo, please try again. I probably over-optimized a bit too much the first time around.
    A number of fallback shaders more in the style of the indie version are now included.

    If the demo doesn't run on your machine, please try checking the console log, and see if it says anything.

    Note that fragment shaders are necessary for the effect to work, but it should at least fallback nicely.
     
  7. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Awesome! Works fine on my iMac w/ X1600.
     
  8. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
  9. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
  10. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    No problems here. MBP Peryn Generation, OSX 10.5.2

    Looks very nice, thank you for sharing :)

    This kind of things is what makes me consider Unity Pro even more than I already do ... dooohhh :?
     
  11. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Didn't they ship a new graphics card with that one?
     
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    NVIDIA 8600M GT 256MB here

    Given you had 256MB before they would be identical.
     
  13. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Hmm. On paper, your card should be capable.
    I can' teally figure out version numbers on graphics cards, but I believe that x1600 is newer than R9000, which works under emulation.

    Do you see any error messages in the log?

    I think this type of problem might have to do with timing, pipelining and stuff like that. I am going to start a thread in ShaderLab about it.
     
  14. chiefbobo

    chiefbobo

    Joined:
    Dec 26, 2007
    Posts:
    25
    That is just plain cool. Nice work. My crappy work computer has an ancient vid card with 64 MB of VRAM but it can still run this at the "fast" setting. And it looks great! (Sure I'm only pulling 3 fps, but at least it runs!)

    Please keep working on this idea. This is major. Thanks for sharing.
     
  15. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    This is from my console (Intel Core Duo 2 MBP with ATI X1600 graphics):

    Code (csharp):
    1. np_entry: NP_Initialize called
    2. np_entry: NP_GetEntryPoints called
    3. 080522 09:30:48 Datafile [url]http://proglet.com/software/Relief_Pro/Relief_Pro.unity3d[/url]
    4. 080522 09:30:48 Loading Unity Player
    5. 080522 09:30:48 loader: unity function UnityBundleStart load failed
    6. 080522 09:30:48 loader: unity function UnityBundleSetupScreen2 load failed
    7. Player: init engine
    8. 080522 09:30:51 Loader: Start Success
    9. host: proglet_2ecom Pref folder: /Users/ImAUser/Library/Preferences
     
  16. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    ... and I'll add that I don't have this problem with my 17" iMac that uses the same graphics chip. I've posted a bug report on the off chance that it might be a Unity issue rather than an Apple drivers issue.
     
  17. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    You should never run into such race conditions (assuming proper drivers). Basically, whenever driver sees that some operation will need result of something that is "still being rendered", it stalls until it gets the result.

    However, if you're doing something that is undefined by it's nature, for example rendering into a texture while reading from the same texture, then all bets are off. That particular case would depend on GPU speed, rasterization pattern, moon phase and whatnot.
     
  18. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Ok. I thought I might get away with it, if I never looked at neighbouring pixels. (Yeah the depth-blur shader does do that after all).

    To anybody else listening: I am going to try a ping-pong technique with two rendertextures that Aras suggested in ShaderLab. I'll probably get the time for it within a day or two.
     
  19. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Just thought I'd chime in and say that this looks quite cool indeed. Nice work!
     
  20. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    Doesn't work here : I tried everything to escape from this welcoming place, but with no success :evil:

    Seriously, it works perfectly (iMac alu 24', Radeon HD2600). Thanks a lot for sharing your amazing work ! :D
     
  21. Dragon Rider

    Dragon Rider

    Joined:
    Jan 17, 2008
    Posts:
    280
    Sah-weet! Awesome job.
     
  22. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    Not working on my desktop (nVidia 7800 GTX). Walls just look like diffuse textures with no shadowing/shading. They do some strange popping though.
     
  23. Alpha-Loup

    Alpha-Loup

    Joined:
    Jun 23, 2006
    Posts:
    797
    Too bad i cannot test this stunning shader (still missin UnityPro)...
    I can a imagine a thousand cool things to do with this code-beauty.

    Really great work!!!

    I am looking forward to utilize this as soon as possible ;)

    Cheers Frank
     
  24. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    43 fps on my x1600 MBP. Very cool!
     
  25. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Huh, yet on my x1600 MBP it looks like the attached screenshot. I'm running 10.4.11 and double checked software update to make sure I'm current.
     

    Attached Files:

  26. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    No errors.
     
  27. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Ok, BigKahuna and AngryAnt, I think I know what is happening on your machines. Please try this one:

    Edit: Link removed. Go to the first post in the thread for an up-to-date version

    I haven't updated the package yet. First I want to see, if this works.
     
  28. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Whatever you did, it fixed it! Looks cool and I'm getting roughly 50 fps on my MBP.
     
  29. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Goody. It was Aras, who told me, that I was using some reserved variables in a wrong way.

    Are the 50 fps fullscreen? Because in the webplayer window, the rate is usually capped at 50 fps.
     
  30. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Oops, yeah you're right but full screen isn't getting me faster frame rates. "Fast" setting gets 20-23 fps full screen and roughly 50 fps windowed. "Medium" gets roughly 18 fps full screen and 40-43 fps windowed.
     
  31. louis

    louis

    Joined:
    Jan 23, 2006
    Posts:
    62
    Windows XP - SeaMonkey Browser - NVidia GeForce 8600GT
    Same result with both the html versions:

     
  32. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Thanks for testing. I am currently working with Eric5h5 to fix some more problems, and so far we are progressing, so no need for more tests right now. A new version will be coming.
     
  33. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Fix version working. The rendering is a bit fuzzy around the edges of the shadows through.
     
  34. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    I think at least some of that is because the heightmap was made by an amateur texture artist. On the walls for example, the edges of the stones are actually as jagged as the shadow looks.
     
  35. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Ok. Latest version ready.
    The link is in the first post in the thread.

    It contains

    - Fixes for ATI X800
    Thanks to Eric5h5 for helping me debug on the X800
    - Better precision at sharp angles
    - 5 "debug spheres" that illustrate the intermediate steps of the shader in the texture buffer.

    Yes, you have to look closely to see the difference between the leftmost three.

    Package also included again.

    Let me know if your gfx card still has problems. Or if problems have returned.
     
  36. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Seems to work equally well on both my 17" iMac x1600 and 15" MBP x1600, but you removed the relief map from the floor, right?
     
  37. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Works worse than the initial one at least unless I missed the "line per line" shadowing on the rounded parts where the shadow is meant to fall.
     
  38. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    @Bigkahuna: Yep, I turned if off on the floor. It _did_ look painful to walk on.

    The spheres were not in the original. And I can see what you mean. It is a common problem with shadowing, that calculations become badly defined when the direction to the light is at a 90 degree angle to the surface normal. You see similar types of problems with the built-in shadows.

    Something for me to think about.
     
  39. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Looking very nice now. Great piece of work.
     
  40. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
  41. Alpha-Loup

    Alpha-Loup

    Joined:
    Jun 23, 2006
    Posts:
    797
    0.0.6 looks better. The effect displays more clearly.

    Really good work!

    Cheers

    Frank
     
  42. Dragon Rider

    Dragon Rider

    Joined:
    Jan 17, 2008
    Posts:
    280
    Try using Firefox or Safari. I don't think the browser would really make a difference, but it could be that they run the plug-in differently.
     
  43. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Same here.



    Nvidia 8600 GTS Dual SLI
     
  44. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
  45. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Well, based on this screenshot, it looks as if it is hardly running at all. As if perhaps rendertextures were disabled. Do you know if you have rendertextures working in e.g. projects that use reflective/refractive water?
     
  46. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    I'm running on a windows box. Send me links to any players you want to see screenshots for.

    It's possible my graphics card is just lacking a minor capability. Since I can run Crysis decently.
     
  47. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    In the island demo
    http://unity3d.com/gallery/live-demos/tropical-paradise

    the water should look something like this (with reflections)

    And I think your graphics card is plenty powerful. But I think there was some problem with some Nvidia drivers leaking memory (and therefore getting rendertextures disabled). Just wanted to check if that was it. If not, probably a bug in my code.
     

    Attached Files:

  48. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    The terrain reflects in the water beautifully.

     
  49. cblarsen

    cblarsen

    Joined:
    Mar 10, 2007
    Posts:
    266
    Well, I guess I have a bug then.
    I don't expect to have time to look at it anytime soon, but if I do fix it, the fix will be posted to this thread.
     
  50. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    You know it could be an issue with your shader pipeline. Maybe you are referencing a parameter in the fragment program that wasn't initialized or passed through the vertex program.

    I've noticed when you do that, you'll see weird camera effects.