Hard Surface Shader Pack 
All assets and shader code created by Bruno Rime for the Unity3D engine.
Email Address brunorime@gmail.com

Hard Surface Shader Pack Overview

The Hard Surface shader pack has been designed to reproduce the surface and lighting qualities of any hard surface, including reflections, refractions, specular highlights, light transfer and much more. Perfect for special effects and presentation pieces .

The shader pack is ideal for applications where surfaces such as glass, metals, plastics, ceramics or even waxes need to be reproduced. The pack is available in three formats, each tailored to suit your own budget and requirements. 

Feature Descriptions

Shader Model 2 Fallback.
A feature that enables the shader pack to run on older and some mobile platforms, when Shader Model 3 hardware is unavailable.

Upgrade & Downgrade Compatible
All Hard Surface shaders are interchangeable and will allow you to swap shaders on the fly to suit your performance or visual requirements without having to re-adjust your material properties.

Non Additive Reflections
The method used in the Hard Surface Shader pack differs from the standard reflection model in that it always ensures the light reflected from a surface is never more than the total light energy of the scene. What does this mean for you? Quite simply it means that your reflections won't blow out in brightly lit scenes, while the same material will work properly in all lighting conditions. Finally, it's possible to easily create white reflective surfaces, without major headaches.

Opaque & Transparent Variations & Light Transfer
Because of the unique way that the shader pack has been designed, it is now easy to reproduce not only Opaque or Transparent surfaces, but everything in between as well. Semi-translucent surfaces, such as wax and porcelain, are able to be emulated using the Opaque shader set where the alpha property controls light transfer, but retains opacity. The Transparent shader set allows for Opacity & Light Transfer to occur, giving you full control over surfaces such as Glass or gems like jade etc.

Diffuse, Alpha, Bump Specular, Gloss, Reflection Properties and Masks
The Hard Surface shader pack features multiple variations of all the above combinations utilizing both slider properties and texture masks, giving you the ability to choose the exact feature set you require for your application without having to carry any extra performance overheads.

Metallic Reflections
A unique feature of the Hard surface shader pack is the metallic reflections property. It allows you to capture how reflections differ on surfaces of varying conductivity. A range of surfaces from gold to plastic can be achieved accurately and most importantly, easily.

Fresnel Reflections
For many surfaces the more obtuse the reflection angle becomes the more reflective the surface appears. The Fresnel reflection slider enables you to control these types of reflections to achieve a greater level of realism.

Edge Alpha
To capture surfaces like wax it is important to have control over both the light transfer and opacity of surface edges. The Edge Alpha property gives you this control.

Z-primed Transparent Surfaces.
This feature ensures that back facing surfaces won't draw over front facing surfaces. It also cleans up ugly internal faces that might normally ruin a great looking asset. This is especially important on complex shapes like characters.

Uncompiled Shaders (Standard & Pro only)
You paid for it, so you get full access to the Hard Surface Shader Code. Fully commented shaders and .cginc files will enable you to customize and merge Hard surface shaders with your own. Whether it's for professional, educational or just for your own curiosity, the full architecture is available for you to use.

Back-face rendering (Standard & Pro only)
An important addition to the Standard & Pro packs for replicating transparent surfaces is back-face rendering combined with Z priming. This allows for glitch free rendering of complex and detailed surfaces. On Direct X platforms using Shader model 3, back faces also feature a simple light diffusion effect based on opacity.

Draw First & Draw Last Variations (Standard & Pro only)
Shader variations to get you out of a tangle when the unity render refuses to play nicely. Forces the draw order of the Surface to ensure it renders when you need it to, especially useful for special effects or when you have multiple transparent/reflective surfaces that you need greater control over.

Screen Space Real-time Reflection (Pro Only)
Reflects any visible surface to the camera without having to re-render the scene! Fast and effective on any curved surface. Works particularly well on cars and characters. No scripts or extra scene management required. Takes into consideration all Hard surface reflective properties including Fresnel influence and Texture masks.

Screen Space Real-time Refraction (Pro Only)
Refracts any surface drawn before and behind the refractive surface. Comes with a Density property slider and takes into consideration all Hard Surface properties. It even self-refracts internal and back facing surfaces.

Chromatic Aberration (Pro Only)
Simulates the separation of Red, Green & Blue light through refractive surfaces. A key visual indicator of a surface's density.

FAQ

Advantages of screen spaced reflections.

How is it that Screen space reflections are so much faster to render than other methods?
Screen space reflections utilize the existing frame buffer to generate the reflection, where as other methods require the scene to be redrawn to a render texture from the point of view of each asset. In some applications traditional reflections require up to 6 scene redraws per reflective asset, often resulting in very poor frame-rates. 

Are Screen space reflections self reflecting?
Screen space reflections are self reflecting, unlike most other methods. This is an advantage for complex shapes where self reflection adds an extra layer of realism to the result.

How is it that you are able to render normally expensive effects like chromatic aberration without the cost?
Once the 2D reflection vector has been calculated, it is very easy to modify to create special effects. In the case of the chromatic aberration, the vector is merely scaled to look up each of the RGB components of the light source. For a traditional 3D reflection vector, each look up for the RGB components would require a complete recalculation of the reflection vector.

Will screen spaced techniques work with augmented reality?
Yes it will, because of the 2D nature of the effect. Any image source can be used to generate the reflection and or refraction. Your virtual objects can literally be reflecting or refracting your real world real-time captures!

Will the world pos have an effect on my reflective assets and batching?
No it won't. Unlike traditional methods that render the scene from the position of the reflective asset, Screen Space techniques don't generate any asset specific render targets. Because of this, multiple assets can share the same material and exist in completely unrelated world positions. If these assets are marked static in the Unity editor, they will batch render, saving you draw calls and gaining you performance.

Limitations of screen space reflections.

Why aren’t the screen space reflections always visible from all angles?
Screen space techniques utilize what's visible to the camera.  In the case of the reflections, only objects visible to the camera can be reflected in other surfaces.  To fill in the gaps, the Hard surface shaders fall back to a cube map when the reflection vector points towards the camera.

 I'm getting stretched reflections on  flat surfaces?
This artifact is a limitation of the screen space technique, which is essentially a 2D effect. Because there is very little angle variation on flat surfaces, the 2D reflection vector will remain relatively fixed over the surface. This results in the stretching effect. I recommend using other reflection techniques to achieve mirror perfect floor reflections. However if the reflection is subtle enough or warped by a normal map, the screen space technique will often be satisfactory and many times faster to render. It's worth noting that the Hard surface shaders can utilize cube maps with real-time updates should you choose to create them.

Some Transparent surfaces aren’t being reflected in my opaque surfaces?
Because the reflection is generated from a screen capture, if the Asset hasn’t been drawn yet, it can't be reflected. Transparent surfaces are normally drawn after opaque surfaces, resulting in the reflection not being visible.

Known Issues.

Depth based image effects don't always work with transparent assets.
Currently Unity 3.3 doesn’t recognize assets in the transparent render-queue that have zwrite enabled, this results in effects like DOF overwriting them. As this wasn't the case in Unity 3.2 and it also happens with the standard unity shaders I am unable to offer a solution. I am working with the Unity developers to resolve this issue.

Depth based image effects will occasionally and randomly flip the grabpass buffer.
The Unity developers are aware of this bug and are currently working on a fix. Unfortunately, it is very hard to reproduce consistently, which has made it difficult to track down. Again this bug is not limited to the Hard Surface shader package and also exists in the standard Unity shaders / image effects.

Tips & Tricks

Performance

Hard surface shaders are forward lighting based, even so, they will work perfectly in a deferred lighting scene. Because of this, the biggest performance impact on the shaders comes from the number of lights the surface interacts with. Try to keep this as low as possible. (I'm looking into the possibility of creating deferred based versions of the opaque shaders for a future release)

Whenever possible, mark your assets as static in the Unity Editor. This will enable the Unity Engine to batch render objects that share the same material. This greatly reduces draw calls and improves performance.

Use only the shader variation that you need to. A great feature of the Hard surface shader package is the large selection of shader variations. Each shader has been optimized for its specific application and it is well worth selecting the specific shader for the task. The image below shows how effective lower specification shaders can look if used the right way.

Material Editor Properties

Main Colour (Red, Green, Blue, Alpha)
RGB: Multiplies the diffuse colour or texture. Also determines the amount of light reflected or absorbed. Black = 100% absorption, white = 100% light reflected or transferred.

A: Multiplies the Diffuse Alpha. Also determines the amount of light transfer. 0 alpha = 100% light transfer, 256 alpha = no light transfer. On Transparent surfaces the Alpha value also determines the surfaces transparency and the amount of diffusion for back-face detail on D3D hardware.

Tip:
Use low alpha values with high RGB values to produce bright glass.
A low alpha value while using an opaque shader will produce a wax like effect and let the light pass through the surface.

Specular Colour (Red, Green, Blue)
Multiplies the lights source's Specular colour.

Tip:
Make the specular colour similar to the Diffuse/Main colour for a Metallic surface effect.
Use specular colours that are different to the Diffuse/Main colour to create pearl like paint effects.
Use a White specular colour to create plastic like surfaces.
 
Shininess Slider
Modifies the specular highlight falloff size. (Left: Large broad highlight, Right: Concentrated small highlight)

Tip:
The more polished a surface the smaller the specular highlight should be.
Very diffuse surfaces like chalk have a very broad specular highlight.

Gloss Slider
Slide the slider from left to right to modify the intensity of the specular highlight. (Left: no highlight, Right: full intensity highlight)

Tip:
Gloss and reflection are very similar. Normally a very glossy surface will also be very reflective.

Reflection Slider
Modifies the overall strength of the reflections. (Left: No reflections, Right: Full reflections)

Reflection Cube map
A texture that is used to represent distant object reflections. Also helps Pro screen space reflections by creating an impression of the reflection sources that are behind the camera.

Tip:
Simple reflection maps often look better than noisy complicated ones.
Often the Sky-box texture for a scene makes an ideal Reflection Cube map.

Fresnel Reflection Slider
Boosts the reflection & gloss value based on surface normal and camera/eye vector. Fall off for the Fresnel Reflection is controlled by the Fresnel/Edge Alpha Falloff Slider. (Left: No Fresnel reflection, Right: Strong Fresnel reflection)

Tip: 
Even very diffuse surfaces at obtuse angles to the eye can be quite reflective. Subtle use of Fresnel reflection on even chalky surfaces can add a great deal of realism.
Clever use of Fresnel Reflection can be used to create a refined version of rim lighting, which also looks more realistic and reacts better to extreme lighting conditions. This is very handy for surfaces like Hair.

Edge Alpha Slider
Modifies the Alpha of a surface using the Fresnel/Edge Alpha Falloff value.

Tip:
Use the Edge/Alpha slider to let more light pass through the areas of a surface the are perpendicular to the camera. Useful for Wax and ceramic like surfaces.

Metallic Slider
The more conductive a surface is, the more it will tint the reflection by its diffuse colour. (Left: Reflection will be the sources colour, Right: Reflection will be tinted by the diffuse colour)

Tip:
Plastics, waxes and ceramics are not very conductive and won't tint a reflection very much.
Metals such as gold are very conductive and tint reflections almost completely.

Diffuse Texture Map
(RGB) Use to create per pixel diffuse colour variation. (A) Use to set opacity and light transference properties.

Tip:
A Diffuse texture that features RGB variation and has little to no alpha will still show interesting surface variations on transparent surfaces. It can be used to create streaks and highlights that will only show under specific lighting conditions such as being back lit.

Normal Texture Map
Use to create per pixel normal variation.

Tip:
Use a normal map on a large flat surface to add some noise to the normals, if reflection stretching becomes an issue.

Spec(R) Gloss(A) Reflect(B)
Use to create Specular/Gloss/Reflection per pixel variation.

	Red Channel = Specular 
	Green Channel = Gloss
	Blue Channel = Reflection

Tip:
Look to the “Samplescene Metals.unity”  file for examples on how achieve surfaces like rust and brushed steel.

Density / Refraction Slider 
Changes the amount of refraction a surface will have. (Left: Less dense, Middle: Equal to atmosphere, Right: More dense). 

Tip:
Refractions are based on the front face surface angle and do not take into consideration the back face angle or the thickness of the surface. Because of this, higher density values are generally needed for larger objects.

All assets and shader code created by Bruno Rime for the Unity3D engine.
Email Address brunorime@gmail.com