Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Photorealistic car paint shaders(MoDyEn Shader Pack) now on Asset Store.

Discussion in 'Assets and Asset Store' started by Ravel, May 21, 2012.

  1. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    Because alot of you requested for my shaders, here they are.
    With these shaders you can get results close if not identical to top selling console games, such as GT5 Forza4
    Link to the Assets is Here.
    Demonstrative images:





    Some practical use:







    Features:
    Highly customizable, alpha masking(decals etc.), gradients(fresnel, metallic, candy), flakes that are affected by light, glass(every car has some), high speed because of unitys native shader code!

    Here is a piece of code to get realtime reflections working, it's not the best one, but it does the basics well.
    CarShaders.cs
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class CarShaders : MonoBehaviour
    6. {
    7.     public int cubemapSize = 1024;
    8.     public bool oneFacePerFrame = true;
    9.     public bool update = true;
    10.     public Vector2 viewDistance = new Vector2(0.1f,1000);
    11.  
    12.     public Vector3 offset;
    13.     public LayerMask cullingMask;      
    14.     //public Shader[] shaders;
    15.    
    16.     private Camera cam;
    17.     private RenderTexture Reflection;  
    18.     private Renderer[] renderers;  
    19.    
    20.     void Start ()
    21.     {
    22.         // render all six faces at startup
    23.         UpdateCubemap( 63 );
    24.     }
    25.    
    26.     void LateUpdate ()
    27.     {
    28.         if (update)
    29.         {
    30.             if (oneFacePerFrame)
    31.             {
    32.                 var faceToRender = Time.frameCount % 6;
    33.                 var faceMask = 1 << faceToRender;
    34.                 UpdateCubemap (faceMask);
    35.             }
    36.             else
    37.             {
    38.                 UpdateCubemap (63); // all six faces
    39.             }
    40.         }
    41.     }
    42.  
    43.     void UpdateCubemap (int faceMask)
    44.     {
    45.         if (!cam)
    46.         {
    47.             GameObject go = new GameObject("CubemapCamera");
    48.             go.AddComponent<Camera>();         
    49.             go.hideFlags = HideFlags.HideAndDontSave;
    50.             go.transform.position = transform.position;
    51.             go.transform.rotation = Quaternion.identity;
    52.             cam = go.camera;
    53.             cam.clearFlags = CameraClearFlags.Skybox;
    54.             cam.cullingMask = cullingMask;
    55.             cam.nearClipPlane = viewDistance .x; // don't render very close into cubemap
    56.             cam.farClipPlane = viewDistance.y; // don't render very far into cubemap
    57.             cam.enabled = false;
    58.         }
    59.    
    60.         if (!Reflection)
    61.         {
    62.             Reflection = new RenderTexture (cubemapSize, cubemapSize, 16);
    63.             Reflection.isPowerOfTwo = true;
    64.             Reflection.isCubemap = true;
    65.             Reflection.hideFlags = HideFlags.HideAndDontSave;
    66.  
    67.             // Set up renderers        
    68.             Renderer[] renderers = GetComponentsInChildren<Renderer>();
    69.             foreach (Renderer r in renderers)
    70.             {  
    71.                 // Set up materials
    72.                 if (r.materials !=null)
    73.                 {                  
    74.                     foreach (Material m in r.materials)
    75.                     {
    76.                        
    77.                         //foreach (Shader s in shaders)
    78.                         //{
    79.                             //if (m.shader == s )
    80.                                 if (m.HasProperty("_Cube"))
    81.                                     m.SetTexture ("_Cube", Reflection);                        
    82.                         //}
    83.                     }
    84.                 }  
    85.             }
    86.         }
    87.        
    88.         cam.transform.position = transform.position+offset;
    89.         cam.RenderToCubemap (Reflection, faceMask);
    90.     }
    91.    
    92.     void OnDisable ()
    93.     {
    94.         DestroyImmediate (cam);
    95.         DestroyImmediate (Reflection);
    96.     }
    97. }
    98.  
    Create a new .cs script, name it "CarShaders.cs" in your Unity editor and paste this code into the newly created script.
    Add this component to your GameObject that contains your models as children. It's also compatible with unity standard reflection shaders. And you can also select what to render to the cubemap with cullingMask. You can obviously change the resolution of the render and camera distance.
    NOTE that realtime reflections is Unity3d PRO only!
     
    Last edited: Dec 4, 2012
  2. Sir-Tiddlesworth

    Sir-Tiddlesworth

    Joined:
    Oct 19, 2011
    Posts:
    908
    Those are some nice shaders.
     
  3. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    Great work!
    Indie or Pro compatible?
     
  4. UnleadedGames

    UnleadedGames

    Joined:
    Feb 17, 2008
    Posts:
    242
    Agreed with everyone else here, awesome work! Have a quick question though, and at the risk of sounding like an idiot, how does one pull off a believable black paint job with your shader? All of the other colors look great, just can't seem to figure out the trick to pull off black paint.
     
    Fie1d likes this.
  5. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    bump
     
  6. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    Thanks!

    Clandestine,
    Indie and pro, both work.

    Msken, The demo randomization was built to just random through colors, and only the metallic channel was set from black to white range, so basically you cant get a black paint from the demo, but here is a demonstration of few extreme black paint variations:

    1.pitch black
    2.light metallic black
    3.devil red (the paint is black but it has a red candy gloss over it)

    Note. The rims are white by texture, i used the decal method to paint the rims black with a white outer color.

    As soon as i get some of my features working in my main project, I'll create a better demonstration of the shaders if there is a need for that (well my car selection screen will include a color selector anyways).
     
    Last edited: May 23, 2012
    Fie1d likes this.
  7. UnleadedGames

    UnleadedGames

    Joined:
    Feb 17, 2008
    Posts:
    242
    Beautiful man love it! Thank you for taking the time to show me this!
     
  8. Mishaps

    Mishaps

    Joined:
    Nov 28, 2011
    Posts:
    181
    Hi Ravel have you tried it on the iphone? I'd love a good carpaint shader for iOS.
     
  9. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    Hi mishaps, If iOS suports shader model 3 then it should work, i dont have a iOS device so i cant test it. I'm not sure if it would work on iPone, but iPad2 should be powerful enough to suport unity's shader language at its best, but this is just a theory.
     
  10. imRobert

    imRobert

    Joined:
    Feb 18, 2012
    Posts:
    41
    Your web player demo is not loading for me.

    BTW, great picture this :
     
    Last edited: Jul 10, 2012
  11. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    Hi Robert,

    My webdemo is not loading due to web maintance at the moment. Thanks for the comment, and hopefully the new demo will be out soon with planned features updated web page.
     
  12. imRobert

    imRobert

    Joined:
    Feb 18, 2012
    Posts:
    41
    OK, I understand. I got you bookmarked.
     
  13. Curious

    Curious

    Joined:
    Nov 19, 2009
    Posts:
    334
    Hmm, very interesting, does it support unity's new HDR rendering features?
     
  14. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    924
    Looking forward to seeing the webdemo...it appears to be down.
     
  15. Djiel

    Djiel

    Joined:
    Jun 25, 2012
    Posts:
    108
    A lot of this looks great, but how much is really reflected?
    If these are the exact same shaders used in your Sideways webdemo I tried some weeks ago then all I saw reflected was the sky (especially noticable in hood cam and looks espescially fake there).
    I'd love to know if more can be reflected than just that.

    I'm asking because:
    Forza4 reflects everything from the track, especially visible in the hood view.

    This amount of reflection is really something I'm looking for and I hope it's achievable with this because it otherwise looks excellent (especially with the gradient options).
     
  16. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    Hello Djiel.

    Realtime reflections are achievable and fully supported with the shaders.
    They can be achieved with a script that updates the cubemaps realtime,
    I have one but not that much optimized at the moment.
    The script will be available once i update the shaders (I have some small new feature plans for the shaders)
    The regular realtime reflection scripts in unity wiki work also.

    Best Regards,
    Ravel
     
  17. UnleadedGames

    UnleadedGames

    Joined:
    Feb 17, 2008
    Posts:
    242
    Great to hear Ravel, that was the only feature I thought I was really missing from your package, Will pick this up now! :)
     
  18. Djiel

    Djiel

    Joined:
    Jun 25, 2012
    Posts:
    108
    That's really great to hear. That means I'll pick them up somewhere in the future. Thanks :)
     
  19. zappapa

    zappapa

    Joined:
    Dec 12, 2010
    Posts:
    57
    What script(s) are you referring to exactly? Can't find anyone but mirror reflections and they only work on flat planes.
     
  20. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    And for free? Nice!
     
  21. Djiel

    Djiel

    Joined:
    Jun 25, 2012
    Posts:
    108
    Once you've finished with your update(s), if possible, I'd love to see the realtime reflections in action either by video or webplayer.
    It would be highly appreciated before I make a purchase.

    In the mean time I've subbed to the thread so I stay up-to-date :)
    Looking forward to updates (also to your physics!).
     
  22. imRobert

    imRobert

    Joined:
    Feb 18, 2012
    Posts:
    41
    +1
    Very interested in Toyota Mica car paint. The blacks.
     
  23. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    This image does not reflect the best realtime reflections possible, but it confirms the functionality with unity HDR feature, pay atention do the glass, it reflects blues more intensively than without HDR feature, also yes this image is realtime (tho the setings are at max so the fps is not that great) and this is a sneak peek to the photographic feature and replay camera effects for the demo that I am planning to releas(not so soon, as there are lots to do and i dont have that much time for it at the moment)





    I will add some screens to reflect the best realtime reflections possible. There will be no videos or webplayers at the time (I simply dont have time for small releases at the moment)
    But i will try post as many pictures as possible to keep things hot.
     
    Last edited: Aug 4, 2012
  24. Djiel

    Djiel

    Joined:
    Jun 25, 2012
    Posts:
    108
    That is understandable, thanks for your efforts though :) looking good.
     
  25. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    for those of you allready owning the shaders, this is how you set up a basic metalic paint:

    And it will look like this:

     
  26. skatermichi98

    skatermichi98

    Joined:
    Feb 5, 2012
    Posts:
    22
    Are those shaders based on the ati car paint shader ?
     
  27. Alven

    Alven

    Joined:
    Sep 12, 2012
    Posts:
    1
    Hi, Ravel ! Where can I found a car model to test the paint shader ?
     
  28. skatermichi98

    skatermichi98

    Joined:
    Feb 5, 2012
    Posts:
    22
  29. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    Hello Skatermichi98, nope they are not based on the ati car paint shader, i wrote them from scratch
     
  30. eyo

    eyo

    Joined:
    Jul 12, 2012
    Posts:
    35
    I'm really interested in this package but what's the performance/compatability on iOS - our target
     
  31. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    I dont own a iPhone so saddly i couldnt tell, tho there shouldn't be a huge performance hit because the code is unity3d native.
    Some recent shots of the shaders in action:



     
  32. napster

    napster

    Joined:
    Jun 15, 2012
    Posts:
    313
    Looks awesommmeee...
     
  33. PizzaGuy213

    PizzaGuy213

    Joined:
    Nov 23, 2010
    Posts:
    305
    These shaders look awesome. So awesome, im afraid to try them for our mobile project :p Maybe for our webplayer version?

    I'll give it a shot though, will report back with the results
     
  34. eyo

    eyo

    Joined:
    Jul 12, 2012
    Posts:
    35
    Interested to find out your results and what poly count your using for vehicles on your mobile app and the number of vehicles onscreen at once!
     
  35. Ravel

    Ravel

    Joined:
    Nov 21, 2010
    Posts:
    605
    I added a realtime reflection code to the main post, the update on the shaders is about to come soon, with much more realistic lightning effects and optimized code.
     
  36. Ironii

    Ironii

    Joined:
    Nov 21, 2012
    Posts:
    3
    I am using your shaders and they are awesome by the way :)

    But when I use them in the web player and I slap a texture on the _MainTex from a web service and then try to reset the _MainTex to a default color. The shader looks like it turns off and then my car has this Matte finish to it. Any idea why this is happening?
     
  37. centralvox

    centralvox

    Joined:
    Oct 16, 2012
    Posts:
    7
    Recently bought the shader only to find out that doesn't support ios unity..the shader is black in color when applied. I'm using unity 4.0..
     
  38. yezzer

    yezzer

    Joined:
    Oct 30, 2009
    Posts:
    143
    Can anyone confirm this will definitely not work on iOS?
     
  39. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,937
    "My webdemo is not loading due to web maintance at the moment. "

    I can confirm the webplayer is still not working. This is the longest web maintenance in history! Any idea when that webplayer link in your asset store description will work?
     
  40. zanozza

    zanozza

    Joined:
    Jan 28, 2013
    Posts:
    9
    Hi, Ravel!

    Can I change/edit this shaders? Or they are "baked" (compiled)?

    Thank you in advance!
     
  41. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Yeah I'd like to know this too.
     
  42. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    298
    @Ravel
    Does ths support mobile platforms. WP8 in particular. If yes i will make the purchase soon. Thanks.
     
  43. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    298
    Can anyone confirm if WP8 supports RenderToCubemap. With Pro version also i wasn able to achieve realtime reflection on test scene
     
  44. ortegam10

    ortegam10

    Joined:
    Aug 14, 2014
    Posts:
    1
    how do I get the second cars color? (blueish-pink)
     
  45. aarni123

    aarni123

    Joined:
    Mar 28, 2015
    Posts:
    3
    why web player demo is not working enymore


    plz i want play this
     
  46. Fie1d

    Fie1d

    Joined:
    Aug 17, 2017
    Posts:
    1