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

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

using UnityEngine;
using System.Collections;

public class CarShaders : MonoBehaviour
{
	public int cubemapSize = 1024;
	public bool oneFacePerFrame = true;
	public bool update = true;
	public Vector2 viewDistance = new Vector2(0.1f,1000);

	public Vector3 offset;
	public LayerMask cullingMask;		
	//public Shader[] shaders;
	
	private Camera cam;
	private RenderTexture Reflection;	
	private Renderer[] renderers;	
	
	void Start ()
	{
		// render all six faces at startup
		UpdateCubemap( 63 );
	}
	
	void LateUpdate ()
	{
		if (update)
		{
			if (oneFacePerFrame)
			{
				var faceToRender = Time.frameCount % 6;
				var faceMask = 1 << faceToRender;
				UpdateCubemap (faceMask);
			}
			else 
			{
				UpdateCubemap (63); // all six faces
			}
		}
	}

	void UpdateCubemap (int faceMask)
	{
		if (!cam) 
		{
			GameObject go = new GameObject("CubemapCamera");
			go.AddComponent<Camera>();			
			go.hideFlags = HideFlags.HideAndDontSave;
			go.transform.position = transform.position;
			go.transform.rotation = Quaternion.identity;
			cam = go.camera;
			cam.clearFlags = CameraClearFlags.Skybox; 
			cam.cullingMask = cullingMask;
			cam.nearClipPlane = viewDistance .x; // don't render very close into cubemap
			cam.farClipPlane = viewDistance.y; // don't render very far into cubemap
			cam.enabled = false;
		}
	
		if (!Reflection)
		{
			Reflection = new RenderTexture (cubemapSize, cubemapSize, 16);
			Reflection.isPowerOfTwo = true;
			Reflection.isCubemap = true;
			Reflection.hideFlags = HideFlags.HideAndDontSave;

			// Set up renderers			
			Renderer[] renderers = GetComponentsInChildren<Renderer>();
	        foreach (Renderer r in renderers)
			{	
				// Set up materials
				if (r.materials !=null)
				{					
					foreach (Material m in r.materials)
					{
						
						//foreach (Shader s in shaders)
						//{
							//if (m.shader == s )
								if (m.HasProperty("_Cube"))
									m.SetTexture ("_Cube", Reflection);							
						//}
					}
				}	
	        }
		}
		
		cam.transform.position = transform.position+offset;
		cam.RenderToCubemap (Reflection, faceMask);
	}
	
	void OnDisable ()
	{
		DestroyImmediate (cam);
		DestroyImmediate (Reflection);
	}
}

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!

Those are some nice shaders.

Great work!
Indie or Pro compatible?

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.

1 Like

bump

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).

1 Like

Beautiful man love it! Thank you for taking the time to show me this!

Hi Ravel have you tried it on the iphone? I’d love a good carpaint shader for iOS.

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.

Your web player demo is not loading for me.

BTW, great picture this :

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.

OK, I understand. I got you bookmarked.

Hmm, very interesting, does it support unity’s new HDR rendering features?

Looking forward to seeing the webdemo…it appears to be down.

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).

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

Great to hear Ravel, that was the only feature I thought I was really missing from your package, Will pick this up now! :slight_smile:

That’s really great to hear. That means I’ll pick them up somewhere in the future. Thanks :slight_smile:

What script(s) are you referring to exactly? Can’t find anyone but mirror reflections and they only work on flat planes.

And for free? Nice!