Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Shader "Volund/Standard Scatter (Metallic, Surface)" {
Properties {
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo", 2D) = "white" {}
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
[Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
_MetallicGlossMap("Metallic", 2D) = "white" {}
_BumpScale("Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02
_ParallaxMap ("Height Map", 2D) = "black" {}
_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
_EmissionColor("Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
_DetailMask("Detail Mask", 2D) = "white" {}
_DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {}
_DetailNormalMapScale("Scale", Float) = 1.0
_DetailNormalMap("Normal Map", 2D) = "bump" {}
[Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0
// Blending state
[HideInInspector] _Mode ("__mode", Float) = 0.0
[HideInInspector] _SrcBlend ("__src", Float) = 1.0
[HideInInspector] _DstBlend ("__dst", Float) = 0.0
[HideInInspector] _ZWrite ("__zw", Float) = 1.0
// Volund properties
[HideInInspector] _CullMode ("__cullmode", Float) = 2.0
[HideInInspector] _SmoothnessInAlbedo ("__smoothnessinalbedo", Float) = 0.0
_MetaAlbedoDesaturation("Meta Albedo Desaturation", Range (0.0, 1.0)) = 0.0
[HDR] _MetaAlbedoTint("Meta Albedo Tint", Color) = (1.0,1.0,1.0,1.0)
[HDR] _MetaAlbedoAdd("Meta Albedo Add", Color) = (0.0,0.0,0.0,0.0)
Category {
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]
// - Physically based Standard lighting model, metallic workflow
// - 'fullforwardshadows' to enable shadows on all light types
// - 'addshadow' to ensure alpha test works for depth/shadow passes
// - 'keepalpha' to allow alpha blended output options
// - Custom vertex function to setup detail UVs as expected by Standard shader,
// and to setup atmospheric scattering.
// - Custom finalcolor function to output controlled final alpha, and to apply
// atmospheric scattering.
// - 'exclude_path:prepass' since we have no use for this legacy path
#pragma surface Surf Standard fullforwardshadows addshadow keepalpha vertex:StandardScatterSurfaceVertex finalcolor:StandardScatterSurfaceFinal exclude_path:prepass
// Standard shader feature variants
#pragma shader_feature _NORMALMAP
#pragma shader_feature _ _ALPHATEST_ON
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _DETAIL_MULX2
// Standard, but unused in this project
//#pragma shader_feature _EMISSION
//#pragma shader_feature _PARALLAXMAP
// Volund additional variants
#pragma shader_feature SMOOTHNESS_IN_ALBEDO
#pragma multi_compile _ ATMOSPHERICS_DEBUG
// Unused in this project (always set to desired config)
// #pragma multi_compile _ ATMOSPHERICS_OCCLUSION
// #pragma multi_compile _ ATMOSPHERICS_OCCLUSION_EDGE_FIXUP
#pragma multi_compile _ ATMOSPHERICS FOG_EXP2
// Include scattering functions
#include "../Code/AtmosphericScattering.cginc"
struct ScatterInput
float4 texcoord;
half3 viewDir;
float vface : VFACE;
#if !defined(ATMOSPHERICS) && defined(FOG_EXP2)
#define fogCoord scatterCoords1.x
#define Input ScatterInput
// Include all the Standard shader surface helpers
#include "UnityStandardSurface.cginc"
void StandardScatterSurfaceVertex (inout appdata_full v, out Input o) {
StandardSurfaceVertex(v, o);
SURFACE_SCATTER_TRANSFER(mul(_Object2World, v.vertex).xyz, o);
#if !defined(ATMOSPHERICS) && defined(FOG_EXP2)
void StandardScatterSurfaceFinal(Input IN, SurfaceOutputStandard o, inout half4 color) {
StandardSurfaceFinal(IN, o, color);
#if !defined(ATMOSPHERICS) && defined(FOG_EXP2)
UNITY_APPLY_FOG(IN.fogCoord, color.rgb);
uniform float _CullMode;
uniform float _MetaAlbedoDesaturation;
uniform float3 _MetaAlbedoTint;
uniform float3 _MetaAlbedoAdd;
// Our main surface entry point
void Surf(Input IN, inout SurfaceOutputStandard o) {
StandardSurface(IN, o);
// Experimental normal flipping
if(_CullMode < 0.5f)
o.Normal.z *= IN.vface;
// Optionally sample smoothness from albedo texture alpha channel instead of sg texture
o.Smoothness = tex2D(_MainTex, IN.texcoord.xy).a;
// Apply additional color controls to meta pass albedo output.
o.Albedo = lerp(o.Albedo, Luminance(o.Albedo).rrr, _MetaAlbedoDesaturation) * _MetaAlbedoTint + _MetaAlbedoAdd;
SubShader {
LOD 400
// Use shader model 5.0 to get access to gather4 instruction (Unity has no 4.1 profile)
#pragma target 5.0
#pragma only_renderers d3d11
SubShader {
LOD 300
// Use shader model 3.0 to get nicer looking lighting (PBS toggles internally on shader model)
#pragma target 3.0
#pragma only_renderers d3d9 opengl
CustomEditor "VolundMultiStandardShaderGUI"
FallBack "Diffuse"

This comment has been minimized.

Copy link

@Paxilon Paxilon commented Jul 13, 2016

Hi Robert. I really love the whole Atmosphere Scattering Tool for Unity! Really well done! I am wondering if it is possible to make Transparency, Emission and Parallax working with this shader. When I try to admit it the shader gets really slow. It seems that reflections in deffered mode also dont work when I use transparent oder fade.

//#pragma shader_feature _EMISSION
//#pragma shader_feature _PARALLAXMAP

Is there a workaroud how to speed up the compilation process? Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.