type shit

This commit is contained in:
niko
2026-06-29 21:52:59 +02:00
parent 8d2eed9892
commit f93f5bfc3d
204 changed files with 16437 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 830f0fef9c0bc4828951030430caa8da
folderAsset: yes
DefaultImporter:
userData:
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e4426c6072e474be9a1e34a7f354e266
folderAsset: yes
timeCreated: 1427423794
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2a7e0de0f51e142fbbededd385182c49
folderAsset: yes
timeCreated: 1427690126
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,282 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/UVFree/Terrain/LegacyDiffuse-AddPass" {
Properties {
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_UVScale("Texture Scale %", Float) = 100.0
_BumpScale ("Normal multiplier", Range(-2.0,2.0)) = 1.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.2
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
// set by terrain engine
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
Tags {
"SplatCount" = "4"
"Queue" = "Geometry-99"
"IgnoreProjector"="True"
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf Lambert decal:add vertex:SplatmapVert finalcolor:SplatmapFinalColor exclude_path:prepass exclude_path:deferred fullforwardshadows
#define TERRAIN_SURFACE_OUTPUT SurfaceOutput
#pragma multi_compile_fog
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
#pragma multi_compile __ _UVFREE_RIM
#define TERRAIN_SPLAT_ADDPASS
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
sampler2D _Control;
float4 _Control_ST;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
#ifdef _TERRAIN_NORMAL_MAP
sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
#endif
half _TexPower;
half _BumpScale;
float _UVScale;
half _Shininess;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
struct Input
{
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
float2 tc_Control : TEXCOORD4; // Not prefixing '_Control' with 'uv' allows a tighter packing of interpolators, which is necessary to support directional lightmap.
UNITY_FOG_COORDS(5)
};
void SplatmapVert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
fixed3 powerNormal = pow(abs(worldNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, half3(1.0,1.0,1.0));
o.powerNormal = powerNormal;
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (powerNormal.x))
+ (-(worldNormal.y) * (powerNormal.y))
+ (-(worldNormal.z) * (powerNormal.z))
;
// Need to manually transform uv here,
// as we choose not to use 'uv' prefix for this texcoord.
o.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);
float4 pos = UnityObjectToClipPos (v.vertex);
UNITY_TRANSFER_FOG(o, pos);
}
void surf(Input IN, inout SurfaceOutput o)
{
// world space positions along the axis planes
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
float2 xUV = float2(powerSign.x, 1.0);
float2 zUV = float2(powerSign.z, 1.0);
float2 yUV = float2(1.0, powerSign.y);
#else
float2 xUV = float2(1.0, 1.0);
float2 zUV = xUV;
float2 yUV = xUV;
#endif
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
splat_control = tex2D(_Control, IN.tc_Control);
weight = dot(splat_control, half4(1.0,1.0,1.0,1.0));
#ifndef UNITY_PASS_DEFERRED
splat_control /= (weight + 1e-3f); // avoid NaNs in splat_control
#endif
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS)
clip(weight - 0.0039);
#endif
fixed4 texX0 = tex2D(_Splat0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale);
fixed4 texY0 = tex2D(_Splat0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale);
fixed4 texZ0 = tex2D(_Splat0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale);
fixed4 texX1 = tex2D(_Splat1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale);
fixed4 texY1 = tex2D(_Splat1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale);
fixed4 texZ1 = tex2D(_Splat1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale);
fixed4 texX2 = tex2D(_Splat2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale);
fixed4 texY2 = tex2D(_Splat2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale);
fixed4 texZ2 = tex2D(_Splat2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale);
fixed4 texX3 = tex2D(_Splat3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale);
fixed4 texY3 = tex2D(_Splat3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale);
fixed4 texZ3 = tex2D(_Splat3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale);
fixed4 tex0 =
+ texX0 * IN.powerNormal.x
+ texY0 * IN.powerNormal.y
+ texZ0 * IN.powerNormal.z;
fixed4 tex1 =
+ texX1 * IN.powerNormal.x
+ texY1 * IN.powerNormal.y
+ texZ1 * IN.powerNormal.z;
fixed4 tex2 =
+ texX2 * IN.powerNormal.x
+ texY2 * IN.powerNormal.y
+ texZ2 * IN.powerNormal.z;
fixed4 tex3 =
+ texX3 * IN.powerNormal.x
+ texY3 * IN.powerNormal.y
+ texZ3 * IN.powerNormal.z;
mixedDiffuse = 0.0f;
mixedDiffuse += splat_control.r * tex0;
mixedDiffuse += splat_control.g * tex1;
mixedDiffuse += splat_control.b * tex2;
mixedDiffuse += splat_control.a * tex3;
o.Albedo = max(fixed3(0.0, 0.0, 0.0),mixedDiffuse.rgb);
o.Alpha = weight;
#ifdef _TERRAIN_NORMAL_MAP
// NORMAL
//
fixed4 flatNormal = fixed4(0.5,0.5,1.0,0.5); // this is "flat normal" in both DXT5nm and xyz*2-1 cases
fixed4 bumpX0 = tex2D(_Normal0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY0 = tex2D(_Normal0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ0 = tex2D(_Normal0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX1 = tex2D(_Normal1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY1 = tex2D(_Normal1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ1 = tex2D(_Normal1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX2 = tex2D(_Normal2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY2 = tex2D(_Normal2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ2 = tex2D(_Normal2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX3 = tex2D(_Normal3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY3 = tex2D(_Normal3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ3 = tex2D(_Normal3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bump0 =
+ bumpX0 * IN.powerNormal.x
+ bumpY0 * IN.powerNormal.y
+ bumpZ0 * IN.powerNormal.z;
fixed4 bump1 =
+ bumpX1 * IN.powerNormal.x
+ bumpY1 * IN.powerNormal.y
+ bumpZ1 * IN.powerNormal.z;
fixed4 bump2 =
+ bumpX2 * IN.powerNormal.x
+ bumpY2 * IN.powerNormal.y
+ bumpZ2 * IN.powerNormal.z;
fixed4 bump3 =
+ bumpX3 * IN.powerNormal.x
+ bumpY3 * IN.powerNormal.y
+ bumpZ3 * IN.powerNormal.z;
fixed4 bump =
splat_control.r * bump0
+ splat_control.g * bump1
+ splat_control.b * bump2
+ splat_control.a * bump3;
bump *= _BumpScale;
bump += flatNormal;
o.Normal = UnpackNormal(bump);
#endif
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), normalize(o.Normal)));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
o.Specular = 0.0;
o.Gloss = 0.0;
}
void SplatmapFinalColor(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 color)
{
color *= o.Alpha;
#ifdef TERRAIN_SPLAT_ADDPASS
UNITY_APPLY_FOG_COLOR(IN.fogCoord, color, fixed4(0,0,0,0));
#else
UNITY_APPLY_FOG(IN.fogCoord, color);
#endif
}
ENDCG
}
Fallback "Nature/Terrain/Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: bf6ac9ce50348432fb3afc0491a6cfb1
timeCreated: 1427690208
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,279 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UVFree/Terrain/LegacyDiffuse" {
Properties {
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_UVScale("Texture Scale %", Float) = 100.0
_BumpScale ("Normal multiplier", Range(-2.0,2.0)) = 1.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.2
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
// set by terrain engine
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
Tags {
"SplatCount" = "4"
"Queue" = "Geometry-99"
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf Lambert vertex:SplatmapVert finalcolor:SplatmapFinalColor exclude_path:prepass exclude_path:deferred fullforwardshadows
#define TERRAIN_SURFACE_OUTPUT SurfaceOutput
#pragma multi_compile_fog
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
#pragma multi_compile __ _UVFREE_RIM
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
sampler2D _Control;
float4 _Control_ST;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
#ifdef _TERRAIN_NORMAL_MAP
sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
#endif
half _TexPower;
half _BumpScale;
float _UVScale;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
struct Input
{
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
float2 tc_Control : TEXCOORD4; // Not prefixing '_Control' with 'uv' allows a tighter packing of interpolators, which is necessary to support directional lightmap.
UNITY_FOG_COORDS(5)
};
void SplatmapVert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
fixed3 powerNormal = pow(abs(worldNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, half3(1.0,1.0,1.0));
o.powerNormal = powerNormal;
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (powerNormal.x))
+ (-(worldNormal.y) * (powerNormal.y))
+ (-(worldNormal.z) * (powerNormal.z))
;
// Need to manually transform uv here,
// as we choose not to use 'uv' prefix for this texcoord.
o.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);
float4 pos = UnityObjectToClipPos (v.vertex);
UNITY_TRANSFER_FOG(o, pos);
}
void surf(Input IN, inout SurfaceOutput o)
{
// world space positions along the axis planes
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
float2 xUV = float2(powerSign.x, 1.0);
float2 zUV = float2(powerSign.z, 1.0);
float2 yUV = float2(1.0, powerSign.y);
#else
float2 xUV = float2(1.0, 1.0);
float2 zUV = xUV;
float2 yUV = xUV;
#endif
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
splat_control = tex2D(_Control, IN.tc_Control);
weight = dot(splat_control, half4(1.0,1.0,1.0,1.0));
#ifndef UNITY_PASS_DEFERRED
splat_control /= (weight + 1e-3f); // avoid NaNs in splat_control
#endif
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS)
clip(weight - 0.0039);
#endif
fixed4 texX0 = tex2D(_Splat0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale);
fixed4 texY0 = tex2D(_Splat0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale);
fixed4 texZ0 = tex2D(_Splat0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale);
fixed4 texX1 = tex2D(_Splat1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale);
fixed4 texY1 = tex2D(_Splat1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale);
fixed4 texZ1 = tex2D(_Splat1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale);
fixed4 texX2 = tex2D(_Splat2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale);
fixed4 texY2 = tex2D(_Splat2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale);
fixed4 texZ2 = tex2D(_Splat2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale);
fixed4 texX3 = tex2D(_Splat3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale);
fixed4 texY3 = tex2D(_Splat3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale);
fixed4 texZ3 = tex2D(_Splat3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale);
fixed4 tex0 =
+ texX0 * IN.powerNormal.x
+ texY0 * IN.powerNormal.y
+ texZ0 * IN.powerNormal.z;
fixed4 tex1 =
+ texX1 * IN.powerNormal.x
+ texY1 * IN.powerNormal.y
+ texZ1 * IN.powerNormal.z;
fixed4 tex2 =
+ texX2 * IN.powerNormal.x
+ texY2 * IN.powerNormal.y
+ texZ2 * IN.powerNormal.z;
fixed4 tex3 =
+ texX3 * IN.powerNormal.x
+ texY3 * IN.powerNormal.y
+ texZ3 * IN.powerNormal.z;
mixedDiffuse = 0.0f;
mixedDiffuse += splat_control.r * tex0;
mixedDiffuse += splat_control.g * tex1;
mixedDiffuse += splat_control.b * tex2;
mixedDiffuse += splat_control.a * tex3;
o.Albedo = max(fixed3(0.0, 0.0, 0.0),mixedDiffuse.rgb);
o.Alpha = weight;
#ifdef _TERRAIN_NORMAL_MAP
// NORMAL
//
fixed4 flatNormal = fixed4(0.5,0.5,1.0,0.5); // this is "flat normal" in both DXT5nm and xyz*2-1 cases
fixed4 bumpX0 = tex2D(_Normal0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY0 = tex2D(_Normal0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ0 = tex2D(_Normal0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX1 = tex2D(_Normal1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY1 = tex2D(_Normal1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ1 = tex2D(_Normal1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX2 = tex2D(_Normal2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY2 = tex2D(_Normal2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ2 = tex2D(_Normal2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX3 = tex2D(_Normal3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY3 = tex2D(_Normal3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ3 = tex2D(_Normal3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bump0 =
+ bumpX0 * IN.powerNormal.x
+ bumpY0 * IN.powerNormal.y
+ bumpZ0 * IN.powerNormal.z;
fixed4 bump1 =
+ bumpX1 * IN.powerNormal.x
+ bumpY1 * IN.powerNormal.y
+ bumpZ1 * IN.powerNormal.z;
fixed4 bump2 =
+ bumpX2 * IN.powerNormal.x
+ bumpY2 * IN.powerNormal.y
+ bumpZ2 * IN.powerNormal.z;
fixed4 bump3 =
+ bumpX3 * IN.powerNormal.x
+ bumpY3 * IN.powerNormal.y
+ bumpZ3 * IN.powerNormal.z;
fixed4 bump =
splat_control.r * bump0
+ splat_control.g * bump1
+ splat_control.b * bump2
+ splat_control.a * bump3;
bump *= _BumpScale;
bump += flatNormal;
o.Normal = UnpackNormal(bump);
#endif
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), normalize(o.Normal)));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
o.Specular = 0.0;
o.Gloss = 0.0;
}
void SplatmapFinalColor(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 color)
{
color *= o.Alpha;
#ifdef TERRAIN_SPLAT_ADDPASS
UNITY_APPLY_FOG_COLOR(IN.fogCoord, color, fixed4(0,0,0,0));
#else
UNITY_APPLY_FOG(IN.fogCoord, color);
#endif
}
ENDCG
}
Dependency "AddPassShader" = "Hidden/UVFree/Terrain/LegacyDiffuse-AddPass"
Fallback "Nature/Terrain/Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 56432fa74ed7043e485d31f8dbb163ea
timeCreated: 1427690206
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fcd7eb091e66348e2a47c8ffa74aa202
folderAsset: yes
timeCreated: 1427487642
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,251 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
// Use the non-batching version of this shader if you are using
// local mode, and are seeing the textures move when you zoom in
// due to dynamic batching. (Dynamic batching converts local vertex
// data into world space, making local vertex position data unavailable
// to the shader.)
Shader "UVFree/Legacy/Diffuse" {
Properties {
[Toggle(_UVFREE_LOCAL)] _UVFreeLocal ("Use Local Space (instead of Global)", Float) = 0.0
[Toggle(_UVFREE_VERTEX_COLOR)] _UVFreeVertexColor ("Use Vertex Color", Float) = 0.0
[Toggle(_UVFREE_BUMPED)] _UVFreeBumped ("Use Normal Mapping", Float) = 1.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
[Toggle(_EMISSION)] _Emission ("Use Emission", Float) = 0.0
_TexPower("Texture Power", Range(0.0,20.0)) = 10.0
_Color ("Tint", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 0.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.0
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
_EmissionMultiplier("Emission Multiplier", Float) = 0.0
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
}
LOD 300
CGPROGRAM
#pragma target 3.0
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _UVFREE_BUMPED
#pragma shader_feature _UVFREE_RIM
#pragma shader_feature _UVFREE_VERTEX_COLOR
#pragma shader_feature _EMISSION
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
#pragma surface surf Lambert vertex:vert fullforwardshadows
#include "UnityCG.cginc"
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
sampler2D _MainTex;
float4 _MainTex_ST;
half _BumpScale;
sampler2D _BumpMap;
sampler2D _EmissionMap;
half _TexPower;
fixed _VertexColorStrength;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
half _EmissionMultiplier;
half4 _EmissionColor;
struct Input {
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = v.normal;
#endif
o.powerNormal = pow(abs(v.normal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (o.powerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (o.powerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (o.powerNormal.z)
;
v.tangent.w =
(-(v.normal.x) * (o.powerNormal.x))
+ (-(v.normal.y) * (o.powerNormal.y))
+ (-(v.normal.z) * (o.powerNormal.z))
;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
// biplanar, zero out y
worldNormal.y = 0.0001;
worldNormal = normalize(worldNormal);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
o.powerNormal = pow(abs(worldNormal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
fixed3 nPowerNormal = normalize(o.powerNormal);
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (nPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (nPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (nPowerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (nPowerNormal.x))
+ (-(worldNormal.y) * (nPowerNormal.y))
+ (-(worldNormal.z) * (nPowerNormal.z))
;
#endif
}
void surf (Input IN, inout SurfaceOutput o) {
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
#endif
// DIFFUSE
//
fixed4 texX = tex2D(_MainTex, xUV);
fixed4 texY = tex2D(_MainTex, yUV);
fixed4 texZ = tex2D(_MainTex, zUV);
fixed4 tex =
texX * IN.powerNormal.x
+ texY * IN.powerNormal.y
+ texZ * IN.powerNormal.z;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
o.Albedo = max(fixed3(0.001, 0.001, 0.001), tex.rgb * tint.rgb);
o.Alpha = 1.0;
// NORMAL
//
#ifdef _UVFREE_BUMPED
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bump =
bumpX * IN.powerNormal.x
+ bumpY * IN.powerNormal.y
+ bumpZ * IN.powerNormal.z
;
o.Normal = normalize(bump);
#else
o.Normal = fixed3(0.0,0.0,1.0);
#endif
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), o.Normal));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
// EMISSION
//
#ifdef _EMISSION
fixed3 emissionX = tex2D(_EmissionMap, xUV).rgb;
fixed3 emissionY = tex2D(_EmissionMap, yUV).rgb;
fixed3 emissionZ = tex2D(_EmissionMap, zUV).rgb;
o.Emission +=
(emissionX * IN.powerNormal.x + emissionY * IN.powerNormal.y + emissionZ * IN.powerNormal.z)
* _EmissionColor.rgb
* _EmissionMultiplier;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreeLegacyTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5894f1bc35e754b3bbeddf49d56c07b9
timeCreated: 1427437622
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,246 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
Shader "UVFree/Legacy/Diffuse Non-Batching" {
Properties {
[Toggle(_UVFREE_LOCAL)] _UVFreeLocal ("Use Local Space (instead of Global)", Float) = 0.0
[Toggle(_UVFREE_VERTEX_COLOR)] _UVFreeVertexColor ("Use Vertex Color", Float) = 0.0
[Toggle(_UVFREE_BUMPED)] _UVFreeBumped ("Use Normal Mapping", Float) = 1.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
[Toggle(_EMISSION)] _Emission ("Use Emission", Float) = 0.0
_TexPower("Texture Power", Range(0.0,20.0)) = 10.0
_Color ("Tint", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 0.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.0
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
_EmissionMultiplier("Emission Multiplier", Float) = 0.0
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
"DisableBatching"="True"
}
LOD 300
CGPROGRAM
#pragma target 3.0
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _UVFREE_BUMPED
#pragma shader_feature _UVFREE_RIM
#pragma shader_feature _UVFREE_VERTEX_COLOR
#pragma shader_feature _EMISSION
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
#pragma surface surf Lambert vertex:vert fullforwardshadows
#include "UnityCG.cginc"
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
sampler2D _MainTex;
float4 _MainTex_ST;
half _BumpScale;
sampler2D _BumpMap;
sampler2D _EmissionMap;
half _TexPower;
fixed _VertexColorStrength;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
half _EmissionMultiplier;
half4 _EmissionColor;
struct Input {
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = v.normal;
#endif
o.powerNormal = pow(abs(v.normal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (o.powerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (o.powerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (o.powerNormal.z)
;
v.tangent.w =
(-(v.normal.x) * (o.powerNormal.x))
+ (-(v.normal.y) * (o.powerNormal.y))
+ (-(v.normal.z) * (o.powerNormal.z))
;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
// biplanar, zero out y
worldNormal.y = 0.0001;
worldNormal = normalize(worldNormal);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
o.powerNormal = pow(abs(worldNormal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
fixed3 nPowerNormal = normalize(o.powerNormal);
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (nPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (nPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (nPowerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (nPowerNormal.x))
+ (-(worldNormal.y) * (nPowerNormal.y))
+ (-(worldNormal.z) * (nPowerNormal.z))
;
#endif
}
void surf (Input IN, inout SurfaceOutput o) {
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
#endif
// DIFFUSE
//
fixed4 texX = tex2D(_MainTex, xUV);
fixed4 texY = tex2D(_MainTex, yUV);
fixed4 texZ = tex2D(_MainTex, zUV);
fixed4 tex =
texX * IN.powerNormal.x
+ texY * IN.powerNormal.y
+ texZ * IN.powerNormal.z;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
o.Albedo = max(fixed3(0.001, 0.001, 0.001), tex.rgb * tint.rgb);
o.Alpha = 1.0;
// NORMAL
//
#ifdef _UVFREE_BUMPED
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bump =
bumpX * IN.powerNormal.x
+ bumpY * IN.powerNormal.y
+ bumpZ * IN.powerNormal.z
;
o.Normal = normalize(bump);
#else
o.Normal = fixed3(0.0,0.0,1.0);
#endif
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), o.Normal));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
// EMISSION
//
#ifdef _EMISSION
fixed3 emissionX = tex2D(_EmissionMap, xUV).rgb;
fixed3 emissionY = tex2D(_EmissionMap, yUV).rgb;
fixed3 emissionZ = tex2D(_EmissionMap, zUV).rgb;
o.Emission +=
(emissionX * IN.powerNormal.x + emissionY * IN.powerNormal.y + emissionZ * IN.powerNormal.z)
* _EmissionColor.rgb
* _EmissionMultiplier;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreeLegacyTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a4be1a756292d46af86d4106debdc11c
timeCreated: 1427437622
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,365 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
// Use the non-batching version of this shader if you are using
// local mode, and are seeing the textures move when you zoom in
// due to dynamic batching. (Dynamic batching converts local vertex
// data into world space, making local vertex position data unavailable
// to the shader.)
Shader "UVFree/Legacy/DiffuseTopBottom" {
Properties {
// Triplanar space, for UI
[Toggle(_UVFREE_LOCAL)] _UVFreeLocal ("Use Local Space (instead of Global)", Float) = 0.0
[Toggle(_UVFREE_VERTEX_COLOR)] _UVFreeVertexColor ("Use Vertex Color", Float) = 0.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
[Toggle(_UVFREE_BOTTOM)] _UVFreeBottom ("Use Bottom", Float) = 1.0
[Toggle(_EMISSION)] _Emission ("Use Emission", Float) = 0.0
_TexPower("Texture Power", Range(0.0,20.0)) = 10.0
_TopMultiplier ("Top Multiplier (+Y)", Range(0.0,8.0)) = 1.0
_BottomMultiplier ("Bottom Multiplier (-Y)", Range(0.0,8.0)) = 0.0
_Color ("Tint", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 0.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_EmissionMultiplier("Emission Multiplier", Float) = 0.0
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.0
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
_TopColor ("Tint", Color) = (1.0,1.0,1.0,1.0)
_TopMainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_TopBumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_TopBumpMap("Normal Map", 2D) = "bump" {}
_TopEmissionMultiplier("Emission Multiplier", Float) = 0.0
_TopEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_TopEmissionMap("Emission", 2D) = "white" {}
_BottomColor ("Tint", Color) = (1.0,1.0,1.0,1.0)
_BottomMainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_BottomBumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BottomBumpMap("Normal Map", 2D) = "bump" {}
_BottomEmissionMultiplier("Emission Multiplier", Float) = 0.0
_BottomEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_BottomEmissionMap("Emission", 2D) = "white" {}
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
}
LOD 300
CGPROGRAM
#pragma target 3.0
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _UVFREE_RIM
#pragma shader_feature _UVFREE_BOTTOM
#pragma shader_feature _UVFREE_VERTEX_COLOR
#pragma shader_feature _EMISSION
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
#pragma surface surf Lambert vertex:vert fullforwardshadows
#include "UnityCG.cginc"
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
//
// MAIN
half _TexPower;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
sampler2D _EmissionMap;
fixed _VertexColorStrength;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
half _EmissionMultiplier;
half4 _EmissionColor;
// TOP
sampler2D _TopMainTex;
sampler2D _TopBumpMap;
half _TopBumpScale;
sampler2D _TopEmissionMap;
fixed4 _TopColor;
half _TopMultiplier;
float4 _TopMainTex_ST;
half _TopEmissionMultiplier;
half4 _TopEmissionColor;
// BOTTOM
#ifdef _UVFREE_BOTTOM
sampler2D _BottomMainTex;
sampler2D _BottomBumpMap;
half _BottomBumpScale;
sampler2D _BottomEmissionMap;
half _BottomMultiplier;
float4 _BottomMainTex_ST;
fixed4 _BottomColor;
half _BottomEmissionMultiplier;
half4 _BottomEmissionColor;
#endif
struct Input {
fixed3 powerNormal;
fixed3 normal;
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
o.normal = v.normal;
fixed3 powerNormal = v.normal;
fixed3 weightedPowerNormal = v.normal;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
o.normal = worldNormal;
fixed3 powerNormal = worldNormal;
fixed3 weightedPowerNormal = worldNormal;
#endif
// texpower sets the sharpness
powerNormal = pow(abs(powerNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, 1.0);
o.powerNormal = powerNormal;
#ifdef _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed3 lerpedPowerNormal = lerp(powerNormal, weightedPowerNormal, weightedPowerNormal.y);
#ifdef _UVFREE_LOCAL
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (lerpedPowerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (lerpedPowerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (lerpedPowerNormal.z)
;
v.tangent.w = dot(-v.normal, lerpedPowerNormal);
#else
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (lerpedPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (lerpedPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (lerpedPowerNormal.z))
;
v.tangent.w = dot(-worldNormal, lerpedPowerNormal);
#endif
}
void surf (Input IN, inout SurfaceOutput o) {
fixed topLerp = smoothstep(0.0, 1.0, _TopMultiplier);
#ifdef _UVFREE_BOTTOM
fixed bottomLerp = smoothstep(0.0, 1.0, _BottomMultiplier);
#endif
fixed3 weightedPowerNormal = IN.normal;
#ifdef _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed topBottomLerp = sign(IN.normal.y)*0.5 + 0.5;
fixed yLerp = weightedPowerNormal.y;
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUVTop = posY * _TopMainTex_ST.xy + _TopMainTex_ST.zw;
#ifdef _UVFREE_BOTTOM
float2 yUVBottom = posY * _BottomMainTex_ST.xy + _BottomMainTex_ST.zw;
#endif
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
yUVTop.y *= powerSign.y;
#ifdef _UVFREE_BOTTOM
yUVBottom.y *= powerSign.y;
#endif
#endif
// DIFFUSE
//
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
fixed4 texX = tex2D(_MainTex, xUV) * tint;
fixed4 texY = tex2D(_MainTex, yUV) * tint;
fixed4 texZ = tex2D(_MainTex, zUV) * tint;
fixed4 texTop = tex2D(_TopMainTex, yUVTop) * _TopColor;
texTop = lerp(texY, texTop, topLerp);
#ifdef _UVFREE_BOTTOM
fixed4 texBottom = tex2D(_BottomMainTex, yUVBottom) * _BottomColor;
texBottom = lerp(texY, texBottom, bottomLerp);
texTop = lerp(texBottom, texTop, topBottomLerp);
#else
texTop = lerp(texY, texTop, topBottomLerp);
#endif
fixed4 tex =
lerp(texX * IN.powerNormal.x, texTop * weightedPowerNormal.x, yLerp)
+ lerp(texY * IN.powerNormal.y, texTop * weightedPowerNormal.y, yLerp)
+ lerp(texZ * IN.powerNormal.z, texTop * weightedPowerNormal.z, yLerp)
;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
o.Albedo = max(fixed3(0.001,0.001,0.001), tex.rgb);
o.Alpha = 1.0;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bumpTop = UnpackScaleNormal(tex2D(_TopBumpMap, yUVTop), _TopBumpScale);
bumpTop = lerp(bumpY, bumpTop, topLerp);
#ifdef _UVFREE_BOTTOM
fixed3 bumpBottom = UnpackScaleNormal(tex2D(_BottomBumpMap, yUVBottom), _BottomBumpScale);
bumpBottom = lerp(bumpY, bumpBottom, bottomLerp);
bumpTop = lerp(bumpBottom, bumpTop, topBottomLerp);
#else
bumpTop = lerp(bumpY, bumpTop, topBottomLerp);
#endif
fixed3 bump =
lerp(bumpX * IN.powerNormal.x, bumpTop * weightedPowerNormal.x, yLerp)
+ lerp(bumpY * IN.powerNormal.y, bumpTop * weightedPowerNormal.y, yLerp)
+ lerp(bumpZ * IN.powerNormal.z, bumpTop * weightedPowerNormal.z, yLerp)
;
o.Normal = normalize(bump);
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), o.Normal));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
// EMISSION
//
#ifdef _EMISSION
half3 emissionX = tex2D(_EmissionMap, xUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionY = tex2D(_EmissionMap, yUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionZ = tex2D(_EmissionMap, zUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionYTop = tex2D(_TopEmissionMap, yUVTop).rgb * _TopEmissionColor.rgb * _TopEmissionMultiplier;
emissionYTop = lerp(emissionY, emissionYTop, topLerp);
#ifdef _UVFREE_BOTTOM
half3 emissionYBottom = tex2D(_BottomEmissionMap, yUVBottom).rgb * _BottomEmissionColor.rgb * _BottomEmissionMultiplier;
emissionYBottom = lerp(emissionY, emissionYBottom, bottomLerp);
emissionYTop = lerp(emissionYBottom, emissionYTop, topBottomLerp);
#else
emissionYTop = lerp(emissionY, emissionYTop, topBottomLerp);
#endif
o.Emission +=
lerp(emissionX * IN.powerNormal.x, emissionYTop * weightedPowerNormal.x, yLerp)
+ lerp(emissionY * IN.powerNormal.y, emissionYTop * weightedPowerNormal.y, yLerp)
+ lerp(emissionZ * IN.powerNormal.z, emissionYTop * weightedPowerNormal.z, yLerp)
;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreeLegacyTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d1a3a95d0a73549319ac7e069d6a9920
timeCreated: 1427440876
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,360 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
Shader "UVFree/Legacy/DiffuseTopBottom Non-Batching" {
Properties {
// Triplanar space, for UI
[Toggle(_UVFREE_LOCAL)] _UVFreeLocal ("Use Local Space (instead of Global)", Float) = 0.0
[Toggle(_UVFREE_VERTEX_COLOR)] _UVFreeVertexColor ("Use Vertex Color", Float) = 0.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
[Toggle(_UVFREE_BOTTOM)] _UVFreeBottom ("Use Bottom", Float) = 1.0
[Toggle(_EMISSION)] _Emission ("Use Emission", Float) = 0.0
_TexPower("Texture Power", Range(0.0,20.0)) = 10.0
_TopMultiplier ("Top Multiplier (+Y)", Range(0.0,8.0)) = 1.0
_BottomMultiplier ("Bottom Multiplier (-Y)", Range(0.0,8.0)) = 0.0
_Color ("Tint", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 0.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_EmissionMultiplier("Emission Multiplier", Float) = 0.0
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.0
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
_TopColor ("Tint", Color) = (1.0,1.0,1.0,1.0)
_TopMainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_TopBumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_TopBumpMap("Normal Map", 2D) = "bump" {}
_TopEmissionMultiplier("Emission Multiplier", Float) = 0.0
_TopEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_TopEmissionMap("Emission", 2D) = "white" {}
_BottomColor ("Tint", Color) = (1.0,1.0,1.0,1.0)
_BottomMainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_BottomBumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BottomBumpMap("Normal Map", 2D) = "bump" {}
_BottomEmissionMultiplier("Emission Multiplier", Float) = 0.0
_BottomEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_BottomEmissionMap("Emission", 2D) = "white" {}
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
"DisableBatching"="True"
}
LOD 300
CGPROGRAM
#pragma target 3.0
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _UVFREE_RIM
#pragma shader_feature _UVFREE_BOTTOM
#pragma shader_feature _UVFREE_VERTEX_COLOR
#pragma shader_feature _EMISSION
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
#pragma surface surf Lambert vertex:vert fullforwardshadows
#include "UnityCG.cginc"
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
//
// MAIN
half _TexPower;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
sampler2D _EmissionMap;
fixed _VertexColorStrength;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
half _EmissionMultiplier;
half4 _EmissionColor;
// TOP
sampler2D _TopMainTex;
sampler2D _TopBumpMap;
half _TopBumpScale;
sampler2D _TopEmissionMap;
fixed4 _TopColor;
half _TopMultiplier;
float4 _TopMainTex_ST;
half _TopEmissionMultiplier;
half4 _TopEmissionColor;
// BOTTOM
#ifdef _UVFREE_BOTTOM
sampler2D _BottomMainTex;
sampler2D _BottomBumpMap;
half _BottomBumpScale;
sampler2D _BottomEmissionMap;
half _BottomMultiplier;
float4 _BottomMainTex_ST;
fixed4 _BottomColor;
half _BottomEmissionMultiplier;
half4 _BottomEmissionColor;
#endif
struct Input {
fixed3 powerNormal;
fixed3 normal;
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
o.normal = v.normal;
fixed3 powerNormal = v.normal;
fixed3 weightedPowerNormal = v.normal;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
o.normal = worldNormal;
fixed3 powerNormal = worldNormal;
fixed3 weightedPowerNormal = worldNormal;
#endif
// texpower sets the sharpness
powerNormal = pow(abs(powerNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, 1.0);
o.powerNormal = powerNormal;
#ifdef _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed3 lerpedPowerNormal = lerp(powerNormal, weightedPowerNormal, weightedPowerNormal.y);
#ifdef _UVFREE_LOCAL
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (lerpedPowerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (lerpedPowerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (lerpedPowerNormal.z)
;
v.tangent.w = dot(-v.normal, lerpedPowerNormal);
#else
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (lerpedPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (lerpedPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (lerpedPowerNormal.z))
;
v.tangent.w = dot(-worldNormal, lerpedPowerNormal);
#endif
}
void surf (Input IN, inout SurfaceOutput o) {
fixed topLerp = smoothstep(0.0, 1.0, _TopMultiplier);
#ifdef _UVFREE_BOTTOM
fixed bottomLerp = smoothstep(0.0, 1.0, _BottomMultiplier);
#endif
fixed3 weightedPowerNormal = IN.normal;
#ifdef _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed topBottomLerp = sign(IN.normal.y)*0.5 + 0.5;
fixed yLerp = weightedPowerNormal.y;
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUVTop = posY * _TopMainTex_ST.xy + _TopMainTex_ST.zw;
#ifdef _UVFREE_BOTTOM
float2 yUVBottom = posY * _BottomMainTex_ST.xy + _BottomMainTex_ST.zw;
#endif
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
yUVTop.y *= powerSign.y;
#ifdef _UVFREE_BOTTOM
yUVBottom.y *= powerSign.y;
#endif
#endif
// DIFFUSE
//
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
fixed4 texX = tex2D(_MainTex, xUV) * tint;
fixed4 texY = tex2D(_MainTex, yUV) * tint;
fixed4 texZ = tex2D(_MainTex, zUV) * tint;
fixed4 texTop = tex2D(_TopMainTex, yUVTop) * _TopColor;
texTop = lerp(texY, texTop, topLerp);
#ifdef _UVFREE_BOTTOM
fixed4 texBottom = tex2D(_BottomMainTex, yUVBottom) * _BottomColor;
texBottom = lerp(texY, texBottom, bottomLerp);
texTop = lerp(texBottom, texTop, topBottomLerp);
#else
texTop = lerp(texY, texTop, topBottomLerp);
#endif
fixed4 tex =
lerp(texX * IN.powerNormal.x, texTop * weightedPowerNormal.x, yLerp)
+ lerp(texY * IN.powerNormal.y, texTop * weightedPowerNormal.y, yLerp)
+ lerp(texZ * IN.powerNormal.z, texTop * weightedPowerNormal.z, yLerp)
;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
o.Albedo = max(fixed3(0.001,0.001,0.001), tex.rgb);
o.Alpha = 1.0;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bumpTop = UnpackScaleNormal(tex2D(_TopBumpMap, yUVTop), _TopBumpScale);
bumpTop = lerp(bumpY, bumpTop, topLerp);
#ifdef _UVFREE_BOTTOM
fixed3 bumpBottom = UnpackScaleNormal(tex2D(_BottomBumpMap, yUVBottom), _BottomBumpScale);
bumpBottom = lerp(bumpY, bumpBottom, bottomLerp);
bumpTop = lerp(bumpBottom, bumpTop, topBottomLerp);
#else
bumpTop = lerp(bumpY, bumpTop, topBottomLerp);
#endif
fixed3 bump =
lerp(bumpX * IN.powerNormal.x, bumpTop * weightedPowerNormal.x, yLerp)
+ lerp(bumpY * IN.powerNormal.y, bumpTop * weightedPowerNormal.y, yLerp)
+ lerp(bumpZ * IN.powerNormal.z, bumpTop * weightedPowerNormal.z, yLerp)
;
o.Normal = normalize(bump);
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), o.Normal));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
// EMISSION
//
#ifdef _EMISSION
half3 emissionX = tex2D(_EmissionMap, xUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionY = tex2D(_EmissionMap, yUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionZ = tex2D(_EmissionMap, zUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionYTop = tex2D(_TopEmissionMap, yUVTop).rgb * _TopEmissionColor.rgb * _TopEmissionMultiplier;
emissionYTop = lerp(emissionY, emissionYTop, topLerp);
#ifdef _UVFREE_BOTTOM
half3 emissionYBottom = tex2D(_BottomEmissionMap, yUVBottom).rgb * _BottomEmissionColor.rgb * _BottomEmissionMultiplier;
emissionYBottom = lerp(emissionY, emissionYBottom, bottomLerp);
emissionYTop = lerp(emissionYBottom, emissionYTop, topBottomLerp);
#else
emissionYTop = lerp(emissionY, emissionYTop, topBottomLerp);
#endif
o.Emission +=
lerp(emissionX * IN.powerNormal.x, emissionYTop * weightedPowerNormal.x, yLerp)
+ lerp(emissionY * IN.powerNormal.y, emissionYTop * weightedPowerNormal.y, yLerp)
+ lerp(emissionZ * IN.powerNormal.z, emissionYTop * weightedPowerNormal.z, yLerp)
;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreeLegacyTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 10525174022874bcb92d307f06405733
timeCreated: 1427440876
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8a1fe37556a2d43f7ad021aafd019334
folderAsset: yes
timeCreated: 1427487622
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,535 @@
using System;
using UnityEngine;
namespace UnityEditor
{
internal class UVFreeLegacyTopBottomGUI : ShaderGUI
{
private enum WorkflowMode
{
Lambert,
BlinnPhong
}
private static class Styles
{
public static GUIStyle optionsButton = "PaneOptions";
public static string emptyTootip = "";
public static GUIContent triplanarSpace = new GUIContent("Triplanar Space", "Whether the triplanar projection should be in local or global space");
public static GUIContent texturePowerText = new GUIContent("Texture Power", "How strong textures on different axes are differentiated. 1 for smooth blending, 10+ for sharper contrasts");
public static GUIContent topMultiplierText = new GUIContent("Top Strength", "How much of the mesh should be considered the top. Set to 0 to disable.");
public static GUIContent bottomMultiplierText = new GUIContent("Bottom Strength", "How much of the mesh should be considered the bottom. Set to 0 to disable.");
public static GUIContent vertexColorStrengthText = new GUIContent("Vertex Color Strength", "0 for no vertex color (off), 1 for full vertex color tinting");
public static GUIContent baseColorLabel = new GUIContent("Diffuse", "Base Color (RGB) Gloss(A)");
public static GUIContent baseColorText = new GUIContent("Diffuse (RGB) Gloss (A)", "Base Color (RGB) Gloss (A)");
public static GUIContent baseColorTextMain = new GUIContent("Main", "Base Color (RGB) Gloss (A)");
public static GUIContent baseColorTextTop = new GUIContent("Top (+Y)", "Base Color (RGB) Gloss (A)");
public static GUIContent baseColorTextBottom = new GUIContent("Bottom (-Y)", "Base Color (RGB) Gloss (A)");
public static GUIContent normalLabel = new GUIContent("Normal", "Normal Map");
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map");
public static GUIContent normalMapMain = new GUIContent("Main", "Normal Map");
public static GUIContent normalMapTextTop = new GUIContent("Top (+Y)", "Normal Map");
public static GUIContent normalMapTextBottom = new GUIContent("Bottom (-Y)", "Normal Map");
public static GUIContent specLabel = new GUIContent("Specular", "Specular");
public static GUIContent specColorText = new GUIContent("Specular Color", "Specular Color");
public static GUIContent shininessText = new GUIContent("Shininess", "Shininess");
public static GUIContent shininessTextMain = new GUIContent("Main", "Shininess");
public static GUIContent shininessTextTop = new GUIContent("Top (+Y)", "Shininess");
public static GUIContent shininessTextBottom = new GUIContent("Bottom (-Y)", "Shininess");
public static GUIContent rimLabel = new GUIContent("Rim Lighting", "Rim Lighting");
public static GUIContent rimText = new GUIContent("Rim", "");
public static GUIContent rimColor = new GUIContent("Color", "");
public static GUIContent rimPower = new GUIContent("Power", "");
public static GUIContent rimMultiplier = new GUIContent("Strength", "");
public static GUIContent emissionLabel = new GUIContent("Emission", "Emission (RGB)");
public static GUIContent emissionText = new GUIContent("Main", "Emission (RGB)");
public static GUIContent emissionTextTop = new GUIContent("Top (+Y)", "Emission (RGB)");
public static GUIContent emissionTextBottom = new GUIContent("Bottom (-Y)", "Emission (RGB)");
public static string textureScaleOffset = "Main Texture Scale/Offset";
public static string textureScaleOffsetTop = "Top (+Y) Texture Scale/Offset";
public static string textureScaleOffsetBottom = "Bottom (-Y) Texture Scale/Offset";
public static string whiteSpaceString = " ";
public static readonly string[] spaceNames = Enum.GetNames (typeof(Space));
public static string advancedText = "Advanced Options";
}
private const float MIN_VALUE = 0.0f;
MaterialProperty uvFreeLocal = null;
// FRONT
MaterialProperty texPower = null;
MaterialProperty topMultiplier = null;
MaterialProperty bottomMultiplier = null;
MaterialProperty vertexColorStrength = null;
// MAIN
MaterialProperty color = null;
MaterialProperty mainTex = null;
MaterialProperty bumpMap = null;
MaterialProperty bumpScale = null;
MaterialProperty specColor = null;
MaterialProperty shininess = null;
MaterialProperty rimColor = null;
MaterialProperty rimPower = null;
MaterialProperty rimMultiplier = null;
// TOP
MaterialProperty topColor = null;
MaterialProperty topMainTex = null;
MaterialProperty topBumpMap = null;
MaterialProperty topBumpScale = null;
MaterialProperty topShininess = null;
// BOTTOM
MaterialProperty bottomColor = null;
MaterialProperty bottomMainTex = null;
MaterialProperty bottomBumpMap = null;
MaterialProperty bottomBumpScale = null;
MaterialProperty bottomShininess = null;
MaterialProperty emissionMap = null;
MaterialProperty emissionColor = null;
MaterialProperty emissionMultiplier = null;
MaterialProperty topEmissionMap = null;
MaterialProperty topEmissionColor = null;
MaterialProperty topEmissionMultiplier = null;
MaterialProperty bottomEmissionMap = null;
MaterialProperty bottomEmissionColor = null;
MaterialProperty bottomEmissionMultiplier = null;
MaterialEditor m_MaterialEditor;
WorkflowMode m_WorkflowMode = WorkflowMode.BlinnPhong;
bool m_FirstTimeApply = true;
public void FindProperties (MaterialProperty[] props)
{
texPower = FindProperty("_TexPower", props, false);
topMultiplier = FindProperty("_TopMultiplier", props, false);
bottomMultiplier = FindProperty("_BottomMultiplier", props, false);
uvFreeLocal = FindProperty("_UVFreeLocal", props, false);
vertexColorStrength = FindProperty("_VertexColorStrength", props, false);
// MAIN
color = FindProperty("_Color", props, false);
mainTex = FindProperty("_MainTex", props, false);
bumpMap = FindProperty("_BumpMap", props, false);
bumpScale = FindProperty("_BumpScale", props, false);
specColor = FindProperty("_SpecColor", props, false);
shininess = FindProperty("_Shininess", props, false);
m_WorkflowMode = shininess == null ? WorkflowMode.Lambert : WorkflowMode.BlinnPhong;
rimColor = FindProperty("_RimColor", props, false);
rimPower = FindProperty("_RimPower", props, false);
rimMultiplier = FindProperty("_RimMultiplier", props, false);
emissionColor = FindProperty("_EmissionColor", props, false);
emissionMap = FindProperty("_EmissionMap", props, false);
emissionMultiplier = FindProperty("_EmissionMultiplier", props, false);
// TOP
topColor = FindProperty("_TopColor", props, false);
topMainTex = FindProperty("_TopMainTex", props, false);
topBumpMap = FindProperty("_TopBumpMap", props, false);
topBumpScale = FindProperty("_TopBumpScale", props, false);
topShininess = FindProperty("_TopShininess", props, false);
topEmissionColor = FindProperty("_TopEmissionColor", props, false);
topEmissionMap = FindProperty("_TopEmissionMap", props, false);
topEmissionMultiplier = FindProperty("_TopEmissionMultiplier", props, false);
// BOTTOM
bottomColor = FindProperty("_BottomColor", props, false);
bottomMainTex = FindProperty("_BottomMainTex", props, false);
bottomBumpMap = FindProperty("_BottomBumpMap", props, false);
bottomBumpScale = FindProperty("_BottomBumpScale", props, false);
bottomShininess = FindProperty("_BottomShininess", props, false);
bottomEmissionColor = FindProperty("_BottomEmissionColor", props, false);
bottomEmissionMap = FindProperty("_BottomEmissionMap", props, false);
bottomEmissionMultiplier = FindProperty("_BottomEmissionMultiplier", props, false);
}
public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] props)
{
FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor;
Material material = materialEditor.target as Material;
ShaderPropertiesGUI (material);
// Make sure that needed keywords are set up if we're switching some existing
// material to a standard shader.
if (m_FirstTimeApply)
{
SetMaterialKeywords (material, m_WorkflowMode);
m_FirstTimeApply = false;
}
}
public void ShaderPropertiesGUI (Material material)
{
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
// Detect any changes to the material
EditorGUI.BeginChangeCheck();
{
TriplanarSpacePopup();
m_MaterialEditor.RangeProperty (texPower, Styles.texturePowerText.text);
if (bottomMultiplier != null)
{
m_MaterialEditor.RangeProperty (topMultiplier, Styles.topMultiplierText.text);
m_MaterialEditor.RangeProperty (bottomMultiplier, Styles.bottomMultiplierText.text);
}
if (vertexColorStrength != null)
{
m_MaterialEditor.RangeProperty (vertexColorStrength, Styles.vertexColorStrengthText.text);
}
DoAlbedoArea(material);
EditorGUILayout.Space();
DoSpecularArea(material);
EditorGUILayout.Space();
DoBumpArea(material);
EditorGUILayout.Space();
DoEmissionArea(material);
EditorGUILayout.Space ();
DoTextureScaleArea (material);
EditorGUILayout.Space();
DoRimArea(material);
}
if (EditorGUI.EndChangeCheck())
{
MaterialChanged(material, m_WorkflowMode);
}
EditorGUILayout.Space();
GUILayout.Label(Styles.advancedText, EditorStyles.boldLabel);
m_MaterialEditor.RenderQueueField();
m_MaterialEditor.EnableInstancingField();
m_MaterialEditor.DoubleSidedGIField();
}
void DoEmissionArea(Material material)
{
GUILayout.Label(Styles.emissionLabel, EditorStyles.boldLabel);
bool showEmissionColorAndGIControls = emissionMultiplier.floatValue > 0f;
bool showEmissionColorAndGIControlsTop = topEmissionMultiplier != null && topEmissionMultiplier.floatValue > 0f;
bool showEmissionColorAndGIControlsBottom = bottomEmissionMultiplier != null && bottomEmissionMultiplier.floatValue > 0f;
// Do controls
m_MaterialEditor.TexturePropertySingleLine(Styles.emissionText, emissionMap, showEmissionColorAndGIControls ? emissionColor : null, emissionMultiplier);
if (topMultiplier != null && topMultiplier.floatValue > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.emissionTextTop, topEmissionMap, showEmissionColorAndGIControlsTop ? topEmissionColor : null, topEmissionMultiplier);
}
if (bottomMultiplier != null && bottomMultiplier.floatValue > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.emissionTextBottom, bottomEmissionMap, showEmissionColorAndGIControlsBottom ? bottomEmissionColor : null, bottomEmissionMultiplier);
}
// Dynamic Lightmapping mode
if (showEmissionColorAndGIControls)
{
bool shouldEmissionBeEnabled = showEmissionColorAndGIControls
|| showEmissionColorAndGIControlsTop
|| showEmissionColorAndGIControlsBottom;
EditorGUI.BeginDisabledGroup(!shouldEmissionBeEnabled);
m_MaterialEditor.LightmapEmissionProperty (MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1);
EditorGUI.EndDisabledGroup();
}
}
void DoRimArea(Material material)
{
GUILayout.Label (Styles.rimLabel, EditorStyles.boldLabel);
m_MaterialEditor.RangeProperty (rimMultiplier, Styles.rimMultiplier.text);
if (rimMultiplier.floatValue > MIN_VALUE)
{
m_MaterialEditor.ColorProperty (rimColor, Styles.rimColor.text);
m_MaterialEditor.RangeProperty (rimPower, Styles.rimPower.text);
}
}
void DoTextureScaleArea(Material material)
{
GUILayout.Label (Styles.textureScaleOffset, EditorStyles.boldLabel);
m_MaterialEditor.TextureScaleOffsetProperty (mainTex);
if (bottomMultiplier != null) {
// TOP
if (topMultiplier.floatValue > MIN_VALUE) {
EditorGUILayout.Space ();
GUILayout.Label (Styles.textureScaleOffsetTop, EditorStyles.boldLabel);
m_MaterialEditor.TextureScaleOffsetProperty (topMainTex);
}
// BOTTOM
if (bottomMultiplier.floatValue > MIN_VALUE) {
EditorGUILayout.Space ();
GUILayout.Label (Styles.textureScaleOffsetBottom, EditorStyles.boldLabel);
m_MaterialEditor.TextureScaleOffsetProperty (bottomMainTex);
}
}
}
void DoBumpArea(Material material)
{
// bump
GUILayout.Label (Styles.normalLabel, EditorStyles.boldLabel);
if ((bottomMultiplier != null)) {
m_MaterialEditor.TexturePropertySingleLine (Styles.normalMapMain, bumpMap, bumpMap.textureValue != null ? bumpScale : null);
if (topMultiplier.floatValue > MIN_VALUE) {
m_MaterialEditor.TexturePropertySingleLine (Styles.normalMapTextTop, topBumpMap, topBumpMap.textureValue != null ? topBumpScale : null);
}
if (bottomMultiplier.floatValue > MIN_VALUE) {
m_MaterialEditor.TexturePropertySingleLine (Styles.normalMapTextBottom, bottomBumpMap, bottomBumpMap.textureValue != null ? bottomBumpScale : null);
}
}
else
{
m_MaterialEditor.TexturePropertySingleLine (Styles.normalMapText, bumpMap, bumpMap.textureValue != null ? bumpScale : null);
}
}
public override void AssignNewShaderToMaterial (Material material, Shader oldShader, Shader newShader)
{
base.AssignNewShaderToMaterial(material, oldShader, newShader);
}
void TriplanarSpacePopup()
{
EditorGUI.showMixedValue = uvFreeLocal.hasMixedValue;
int space = (uvFreeLocal.floatValue == 0.0f) ? ((int) Space.World) : ((int) Space.Self);
EditorGUI.BeginChangeCheck();
space = EditorGUILayout.Popup(Styles.triplanarSpace.text, space, Styles.spaceNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Triplanar Space");
uvFreeLocal.floatValue = (space == ((int) Space.World)) ? 0.0f : 1.0f;
}
EditorGUI.showMixedValue = false;
}
void DoAlbedoArea(Material material)
{
GUILayout.Label(Styles.baseColorLabel, EditorStyles.boldLabel);
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorTextMain, mainTex, color);
// top bottom
if (bottomMultiplier != null)
{
if (topMultiplier.floatValue > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorTextTop, topMainTex, topColor);
}
if (bottomMultiplier.floatValue > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorTextBottom, bottomMainTex, bottomColor);
}
}
}
void DoSpecularArea(Material material)
{
if (m_WorkflowMode == WorkflowMode.BlinnPhong)
{
GUILayout.Label(Styles.specLabel, EditorStyles.boldLabel);
m_MaterialEditor.ColorProperty (specColor, Styles.specColorText.text);
// top and bottom
if (bottomMultiplier != null)
{
EditorGUILayout.LabelField (Styles.shininessText.text);
EditorGUI.indentLevel++;
m_MaterialEditor.RangeProperty (shininess, Styles.shininessTextMain.text);
if (topMultiplier.floatValue > MIN_VALUE)
{
m_MaterialEditor.RangeProperty (topShininess, Styles.shininessTextTop.text);
}
if (bottomMultiplier.floatValue > MIN_VALUE)
{
m_MaterialEditor.RangeProperty (bottomShininess, Styles.shininessTextBottom.text);
}
EditorGUI.indentLevel--;
}
else // single tex
{
m_MaterialEditor.RangeProperty (shininess, Styles.shininessText.text);
}
}
}
static void SetMaterialKeywords(Material material, WorkflowMode workflowMode)
{
// Triplanar texture space
SetKeyword(material, "_UVFREE_LOCAL", material.GetFloat ("_UVFreeLocal") == (float) Space.Self);
if (material.HasProperty("_BottomMultiplier"))
{
// whether the bottom is enabled
bool bottomEnabled = material.GetFloat ("_BottomMultiplier") > MIN_VALUE;
SetKeyword(material, "_UVFREE_BOTTOM", bottomEnabled);
}
// vertex color
SetKeyword(material, "_UVFREE_VERTEX_COLOR", material.GetFloat ("_VertexColorStrength") > MIN_VALUE);
// Rim
SetKeyword(material, "_UVFREE_RIM", material.GetFloat ("_RimMultiplier") > MIN_VALUE);
// Bump
bool includeBump = Mathf.Abs (material.GetFloat ("_BumpScale")) > MIN_VALUE;
if (material.HasProperty ("_BottomMultiplier"))
{
if (material.GetFloat ("_TopMultiplier") > MIN_VALUE)
{
includeBump = includeBump || (material.HasProperty ("_TopBumpScale") && Mathf.Abs (material.GetFloat ("_TopBumpScale")) > MIN_VALUE);
}
if (material.GetFloat ("_BottomMultiplier") > MIN_VALUE)
{
includeBump = includeBump || (material.HasProperty ("_BottomBumpScale") && Mathf.Abs (material.GetFloat ("_BottomBumpScale")) > MIN_VALUE);
}
}
SetKeyword(material, "_UVFREE_BUMPED", includeBump);
// emission
if (material.HasProperty ("_EmissionMultiplier"))
{
bool includeEmission = material.HasProperty ("_EmissionMultiplier") && material.GetFloat("_EmissionMultiplier") > MIN_VALUE;
if (material.HasProperty("_TopMultiplier")
&& material.GetFloat("_TopMultiplier") > MIN_VALUE)
{
includeEmission = includeEmission || (material.HasProperty ("_TopEmissionMultiplier") && material.GetFloat("_TopEmissionMultiplier") > MIN_VALUE);
}
if (material.HasProperty("_BottomMultiplier")
&& material.GetFloat("_BottomMultiplier") > MIN_VALUE)
{
includeEmission = includeEmission || (material.HasProperty ("_BottomEmissionMultiplier") && material.GetFloat("_BottomEmissionMultiplier") > MIN_VALUE);
}
SetKeyword(material, "_EMISSION", includeEmission);
}
}
static void MaterialChanged(Material material, WorkflowMode workflowMode)
{
// clamp texture power
float tTexPower = material.GetFloat("_TexPower");
if (tTexPower < 0.0f || tTexPower > 20.0f)
{
material.SetFloat ("_TexPower", Mathf.Clamp (tTexPower, 0.0f, 20.0f));
}
if (material.HasProperty ("_BottomMultiplier"))
{
// clamp top multiplier
float tTopMultiplier = material.GetFloat ("_TopMultiplier");
if (tTopMultiplier < 0.0f || tTopMultiplier > 8.0f)
{
material.SetFloat ("_TopMultiplier", Mathf.Clamp (tTopMultiplier, 0.0f, 8.0f));
}
// clamp bottom multiplier
float tBottomMultiplier = material.GetFloat ("_BottomMultiplier");
if (tBottomMultiplier < 0.0f || tBottomMultiplier > 8.0f)
{
material.SetFloat ("_BottomMultiplier", Mathf.Clamp (tBottomMultiplier, 0.0f, 8.0f));
}
}
SetMaterialKeywords(material, workflowMode);
}
static void SetKeyword(Material m, string keyword, bool state)
{
if (state)
m.EnableKeyword (keyword);
else
m.DisableKeyword (keyword);
//Debug.Log ("Keyword: " + keyword + ": " + state);
}
}
} // namespace UnityEditor
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 23b0be141d85c41d1984a4ecc7c4bc73
timeCreated: 1427487587
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: bc94b295348984a8fad0624cb7f3ca5f
folderAsset: yes
timeCreated: 1427690133
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,284 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/UVFree/Terrain/LegacySpecular-AddPass" {
Properties {
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_UVScale("Texture Scale %", Float) = 100.0
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1.0)
_Shininess ("Shininess", Range (0.03, 1.0)) = 0.078125
_BumpScale ("Normal multiplier", Range(-2.0,2.0)) = 1.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.2
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
// set by terrain engine
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
Tags {
"SplatCount" = "4"
"Queue" = "Geometry-99"
"IgnoreProjector"="True"
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf BlinnPhong decal:add vertex:SplatmapVert finalcolor:SplatmapFinalColor exclude_path:prepass exclude_path:deferred fullforwardshadows
#define TERRAIN_SURFACE_OUTPUT SurfaceOutput
#pragma multi_compile_fog
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
#pragma multi_compile __ _UVFREE_RIM
#define TERRAIN_SPLAT_ADDPASS
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
sampler2D _Control;
float4 _Control_ST;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
#ifdef _TERRAIN_NORMAL_MAP
sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
#endif
half _TexPower;
half _BumpScale;
float _UVScale;
half _Shininess;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
struct Input
{
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
float2 tc_Control : TEXCOORD4; // Not prefixing '_Control' with 'uv' allows a tighter packing of interpolators, which is necessary to support directional lightmap.
UNITY_FOG_COORDS(5)
};
void SplatmapVert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
fixed3 powerNormal = pow(abs(worldNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, half3(1.0,1.0,1.0));
o.powerNormal = powerNormal;
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (powerNormal.x))
+ (-(worldNormal.y) * (powerNormal.y))
+ (-(worldNormal.z) * (powerNormal.z))
;
// Need to manually transform uv here,
// as we choose not to use 'uv' prefix for this texcoord.
o.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);
float4 pos = UnityObjectToClipPos (v.vertex);
UNITY_TRANSFER_FOG(o, pos);
}
void surf(Input IN, inout SurfaceOutput o)
{
// world space positions along the axis planes
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
float2 xUV = float2(powerSign.x, 1.0);
float2 zUV = float2(powerSign.z, 1.0);
float2 yUV = float2(1.0, powerSign.y);
#else
float2 xUV = float2(1.0, 1.0);
float2 zUV = xUV;
float2 yUV = xUV;
#endif
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
splat_control = tex2D(_Control, IN.tc_Control);
weight = dot(splat_control, half4(1.0,1.0,1.0,1.0));
#ifndef UNITY_PASS_DEFERRED
splat_control /= (weight + 1e-3f); // avoid NaNs in splat_control
#endif
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS)
clip(weight - 0.0039);
#endif
fixed4 texX0 = tex2D(_Splat0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale);
fixed4 texY0 = tex2D(_Splat0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale);
fixed4 texZ0 = tex2D(_Splat0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale);
fixed4 texX1 = tex2D(_Splat1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale);
fixed4 texY1 = tex2D(_Splat1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale);
fixed4 texZ1 = tex2D(_Splat1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale);
fixed4 texX2 = tex2D(_Splat2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale);
fixed4 texY2 = tex2D(_Splat2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale);
fixed4 texZ2 = tex2D(_Splat2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale);
fixed4 texX3 = tex2D(_Splat3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale);
fixed4 texY3 = tex2D(_Splat3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale);
fixed4 texZ3 = tex2D(_Splat3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale);
fixed4 tex0 =
+ texX0 * IN.powerNormal.x
+ texY0 * IN.powerNormal.y
+ texZ0 * IN.powerNormal.z;
fixed4 tex1 =
+ texX1 * IN.powerNormal.x
+ texY1 * IN.powerNormal.y
+ texZ1 * IN.powerNormal.z;
fixed4 tex2 =
+ texX2 * IN.powerNormal.x
+ texY2 * IN.powerNormal.y
+ texZ2 * IN.powerNormal.z;
fixed4 tex3 =
+ texX3 * IN.powerNormal.x
+ texY3 * IN.powerNormal.y
+ texZ3 * IN.powerNormal.z;
mixedDiffuse = 0.0f;
mixedDiffuse += splat_control.r * tex0;
mixedDiffuse += splat_control.g * tex1;
mixedDiffuse += splat_control.b * tex2;
mixedDiffuse += splat_control.a * tex3;
o.Albedo = max(fixed3(0.0, 0.0, 0.0),mixedDiffuse.rgb);
o.Alpha = weight;
#ifdef _TERRAIN_NORMAL_MAP
// NORMAL
//
fixed4 flatNormal = fixed4(0.5,0.5,1.0,0.5); // this is "flat normal" in both DXT5nm and xyz*2-1 cases
fixed4 bumpX0 = tex2D(_Normal0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY0 = tex2D(_Normal0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ0 = tex2D(_Normal0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX1 = tex2D(_Normal1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY1 = tex2D(_Normal1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ1 = tex2D(_Normal1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX2 = tex2D(_Normal2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY2 = tex2D(_Normal2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ2 = tex2D(_Normal2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX3 = tex2D(_Normal3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY3 = tex2D(_Normal3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ3 = tex2D(_Normal3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bump0 =
+ bumpX0 * IN.powerNormal.x
+ bumpY0 * IN.powerNormal.y
+ bumpZ0 * IN.powerNormal.z;
fixed4 bump1 =
+ bumpX1 * IN.powerNormal.x
+ bumpY1 * IN.powerNormal.y
+ bumpZ1 * IN.powerNormal.z;
fixed4 bump2 =
+ bumpX2 * IN.powerNormal.x
+ bumpY2 * IN.powerNormal.y
+ bumpZ2 * IN.powerNormal.z;
fixed4 bump3 =
+ bumpX3 * IN.powerNormal.x
+ bumpY3 * IN.powerNormal.y
+ bumpZ3 * IN.powerNormal.z;
fixed4 bump =
splat_control.r * bump0
+ splat_control.g * bump1
+ splat_control.b * bump2
+ splat_control.a * bump3;
bump *= _BumpScale;
bump += flatNormal;
o.Normal = UnpackNormal(bump);
#endif
o.Gloss = mixedDiffuse.a;
o.Specular = _Shininess;
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), normalize(o.Normal)));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
}
void SplatmapFinalColor(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 color)
{
color *= o.Alpha;
#ifdef TERRAIN_SPLAT_ADDPASS
UNITY_APPLY_FOG_COLOR(IN.fogCoord, color, fixed4(0,0,0,0));
#else
UNITY_APPLY_FOG(IN.fogCoord, color);
#endif
}
ENDCG
}
Fallback "Nature/Terrain/Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2c97bcac03ae048a295cae3d2b30e7ee
timeCreated: 1427690219
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,58 @@
Shader "Hidden/UVFree/Terrain/LegacySpecular-Base" {
Properties {
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1.0)
_Shininess ("Shininess", Range (0.03, 1.0)) = 0.078125
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
// used in fallback on old cards
_Color ("Main Color", Color) = (1.0,1.0,1.0,1.0)
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.2
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
}
SubShader {
Tags {
"RenderType" = "Opaque"
"Queue" = "Geometry-100"
}
LOD 200
CGPROGRAM
#pragma surface surf BlinnPhong fullforwardshadows
#pragma multi_compile __ _UVFREE_RIM
sampler2D _MainTex;
half _Shininess;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
struct Input {
float2 uv_MainTex;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb;
o.Gloss = tex.a;
o.Alpha = 1.0f;
o.Specular = _Shininess;
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), normalize(o.Normal)));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
}
ENDCG
}
FallBack "Legacy Shaders/Specular"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a17ee4ff68d40434ca058ea4837e9f7f
timeCreated: 1427690220
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,285 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UVFree/Terrain/LegacySpecular" {
Properties {
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_UVScale("Texture Scale %", Float) = 100.0
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1.0)
_Shininess ("Shininess", Range (0.03, 1)) = 0.078125
_BumpScale ("Normal multiplier", Range(-2,2)) = 1
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0
_RimMultiplier ("Rim Multiplier", Range(0,8)) = 0.2
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1,1,1,1)
_RimPower ("Rim Power", Range(0,16)) = 5.0
// set by terrain engine
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
}
SubShader {
Tags {
"SplatCount" = "4"
"Queue" = "Geometry-100"
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf BlinnPhong vertex:SplatmapVert finalcolor:SplatmapFinalColor exclude_path:prepass exclude_path:deferred fullforwardshadows
#define TERRAIN_SURFACE_OUTPUT SurfaceOutput
#pragma multi_compile_fog
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
#pragma multi_compile __ _UVFREE_RIM
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
sampler2D _Control;
float4 _Control_ST;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
#ifdef _TERRAIN_NORMAL_MAP
sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
#endif
half _TexPower;
half _BumpScale;
float _UVScale;
half _Shininess;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
struct Input
{
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
float2 tc_Control : TEXCOORD4; // Not prefixing '_Control' with 'uv' allows a tighter packing of interpolators, which is necessary to support directional lightmap.
UNITY_FOG_COORDS(5)
};
void SplatmapVert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
fixed3 powerNormal = pow(abs(worldNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, half3(1.0,1.0,1.0));
o.powerNormal = powerNormal;
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (powerNormal.x))
+ (-(worldNormal.y) * (powerNormal.y))
+ (-(worldNormal.z) * (powerNormal.z))
;
// Need to manually transform uv here,
// as we choose not to use 'uv' prefix for this texcoord.
o.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);
float4 pos = UnityObjectToClipPos (v.vertex);
UNITY_TRANSFER_FOG(o, pos);
}
void surf(Input IN, inout SurfaceOutput o)
{
// world space positions along the axis planes
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
float2 xUV = float2(powerSign.x, 1.0);
float2 zUV = float2(powerSign.z, 1.0);
float2 yUV = float2(1.0, powerSign.y);
#else
float2 xUV = float2(1.0, 1.0);
float2 zUV = xUV;
float2 yUV = xUV;
#endif
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
splat_control = tex2D(_Control, IN.tc_Control);
weight = dot(splat_control, half4(1.0,1.0,1.0,1.0));
#ifndef UNITY_PASS_DEFERRED
splat_control /= (weight + 1e-3f); // avoid NaNs in splat_control
#endif
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS)
clip(weight - 0.0039);
#endif
fixed4 texX0 = tex2D(_Splat0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale);
fixed4 texY0 = tex2D(_Splat0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale);
fixed4 texZ0 = tex2D(_Splat0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale);
fixed4 texX1 = tex2D(_Splat1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale);
fixed4 texY1 = tex2D(_Splat1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale);
fixed4 texZ1 = tex2D(_Splat1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale);
fixed4 texX2 = tex2D(_Splat2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale);
fixed4 texY2 = tex2D(_Splat2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale);
fixed4 texZ2 = tex2D(_Splat2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale);
fixed4 texX3 = tex2D(_Splat3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale);
fixed4 texY3 = tex2D(_Splat3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale);
fixed4 texZ3 = tex2D(_Splat3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale);
fixed4 tex0 =
+ texX0 * IN.powerNormal.x
+ texY0 * IN.powerNormal.y
+ texZ0 * IN.powerNormal.z;
fixed4 tex1 =
+ texX1 * IN.powerNormal.x
+ texY1 * IN.powerNormal.y
+ texZ1 * IN.powerNormal.z;
fixed4 tex2 =
+ texX2 * IN.powerNormal.x
+ texY2 * IN.powerNormal.y
+ texZ2 * IN.powerNormal.z;
fixed4 tex3 =
+ texX3 * IN.powerNormal.x
+ texY3 * IN.powerNormal.y
+ texZ3 * IN.powerNormal.z;
mixedDiffuse = 0.0f;
mixedDiffuse += splat_control.r * tex0;
mixedDiffuse += splat_control.g * tex1;
mixedDiffuse += splat_control.b * tex2;
mixedDiffuse += splat_control.a * tex3;
o.Albedo = max(fixed3(0.0, 0.0, 0.0),mixedDiffuse.rgb);
o.Alpha = weight;
#ifdef _TERRAIN_NORMAL_MAP
// NORMAL
//
fixed4 flatNormal = fixed4(0.5,0.5,1.0,0.5); // this is "flat normal" in both DXT5nm and xyz*2-1 cases
fixed4 bumpX0 = tex2D(_Normal0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY0 = tex2D(_Normal0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ0 = tex2D(_Normal0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX1 = tex2D(_Normal1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY1 = tex2D(_Normal1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ1 = tex2D(_Normal1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX2 = tex2D(_Normal2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY2 = tex2D(_Normal2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ2 = tex2D(_Normal2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX3 = tex2D(_Normal3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY3 = tex2D(_Normal3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ3 = tex2D(_Normal3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bump0 =
+ bumpX0 * IN.powerNormal.x
+ bumpY0 * IN.powerNormal.y
+ bumpZ0 * IN.powerNormal.z;
fixed4 bump1 =
+ bumpX1 * IN.powerNormal.x
+ bumpY1 * IN.powerNormal.y
+ bumpZ1 * IN.powerNormal.z;
fixed4 bump2 =
+ bumpX2 * IN.powerNormal.x
+ bumpY2 * IN.powerNormal.y
+ bumpZ2 * IN.powerNormal.z;
fixed4 bump3 =
+ bumpX3 * IN.powerNormal.x
+ bumpY3 * IN.powerNormal.y
+ bumpZ3 * IN.powerNormal.z;
fixed4 bump =
splat_control.r * bump0
+ splat_control.g * bump1
+ splat_control.b * bump2
+ splat_control.a * bump3;
bump *= _BumpScale;
bump += flatNormal;
o.Normal = UnpackNormal(bump);
#endif
o.Gloss = mixedDiffuse.a;
o.Specular = _Shininess;
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), normalize(o.Normal)));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
}
void SplatmapFinalColor(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 color)
{
color *= o.Alpha;
#ifdef TERRAIN_SPLAT_ADDPASS
UNITY_APPLY_FOG_COLOR(IN.fogCoord, color, fixed4(0,0,0,0));
#else
UNITY_APPLY_FOG(IN.fogCoord, color);
#endif
}
ENDCG
}
Dependency "AddPassShader" = "Hidden/UVFree/Terrain/LegacySpecular-AddPass"
Dependency "BaseMapShader" = "Hidden/UVFree/Terrain/LegacySpecular-BasePass"
Fallback "Nature/Terrain/Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f12406e1126a444b79fee18cce430514
timeCreated: 1427690221
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fd8b0a5b73cb64781a2f795acf0704c4
folderAsset: yes
timeCreated: 1427487636
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,251 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
// Use the non-batching version of this shader if you are using
// local mode, and are seeing the textures move when you zoom in
// due to dynamic batching. (Dynamic batching converts local vertex
// data into world space, making local vertex position data unavailable
// to the shader.)
Shader "UVFree/Legacy/Specular" {
Properties {
// Triplanar space, for UI
[Toggle(_UVFREE_LOCAL)] _UVFreeLocal ("Use Local Space (instead of Global)", Float) = 0.0
[Toggle(_UVFREE_VERTEX_COLOR)] _UVFreeVertexColor ("Use Vertex Color", Float) = 0.0
[Toggle(_UVFREE_BUMPED)] _UVFreeBumped ("Use Normal Mapping", Float) = 1.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
[Toggle(_EMISSION)] _Emission ("Use Emission", Float) = 0.0
_TexPower("Texture Power", Range(0.0,20.0)) = 10.0
_Color ("Tint", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 0.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_Shininess("Shininess", Range(0.01, 1.0)) = 0.078125
_SpecColor("Specular", Color) = (0.5,0.5,0.5,1.0)
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.0
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
_EmissionMultiplier("Emission Multiplier", Float) = 0.0
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
}
LOD 300
CGPROGRAM
#pragma target 3.0
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _UVFREE_BUMPED
#pragma shader_feature _UVFREE_RIM
#pragma shader_feature _UVFREE_VERTEX_COLOR
#pragma shader_feature _EMISSION
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
#pragma surface surf BlinnPhong vertex:vert fullforwardshadows
#include "UnityCG.cginc"
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
half _TexPower;
fixed _VertexColorStrength;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
sampler2D _EmissionMap;
half _EmissionMultiplier;
half4 _EmissionColor;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
float _Shininess;
struct Input {
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = v.normal;
#endif
o.powerNormal = pow(abs(v.normal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (o.powerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (o.powerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (o.powerNormal.z)
;
v.tangent.w =
(-(v.normal.x) * (o.powerNormal.x))
+ (-(v.normal.y) * (o.powerNormal.y))
+ (-(v.normal.z) * (o.powerNormal.z))
;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
o.powerNormal = pow(abs(worldNormal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (o.powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (o.powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (o.powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (o.powerNormal.x))
+ (-(worldNormal.y) * (o.powerNormal.y))
+ (-(worldNormal.z) * (o.powerNormal.z))
;
#endif
}
void surf (Input IN, inout SurfaceOutput o) {
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
#endif
// DIFFUSE
//
fixed4 texX = tex2D(_MainTex, xUV);
fixed4 texY = tex2D(_MainTex, yUV);
fixed4 texZ = tex2D(_MainTex, zUV);
fixed4 tex =
texX * IN.powerNormal.x
+ texY * IN.powerNormal.y
+ texZ * IN.powerNormal.z;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
o.Albedo = max(fixed3(0.001,0.001,0.001), tex.rgb * tint.rgb);
o.Alpha = 1.0;
// NORMAL
//
#ifdef _UVFREE_BUMPED
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bump =
bumpX * IN.powerNormal.x
+ bumpY * IN.powerNormal.y
+ bumpZ * IN.powerNormal.z
;
o.Normal = normalize(bump);
#else
o.Normal = fixed3(0.0,0.0,1.0);
#endif
// SPECULAR/GLOSS
//
o.Gloss = tex.a * _SpecColor.a;
o.Specular = _Shininess;
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), o.Normal));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
// EMISSION
//
#ifdef _EMISSION
fixed3 emissionX = tex2D(_EmissionMap, xUV).rgb;
fixed3 emissionY = tex2D(_EmissionMap, yUV).rgb;
fixed3 emissionZ = tex2D(_EmissionMap, zUV).rgb;
o.Emission +=
(emissionX * IN.powerNormal.x + emissionY * IN.powerNormal.y + emissionZ * IN.powerNormal.z)
* _EmissionColor.rgb
* _EmissionMultiplier;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreeLegacyTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: ab53f541c10484ef2b031dc958e26032
timeCreated: 1427423850
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,252 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
// Use the non-batching version of this shader if you are using
// local mode, and are seeing the textures move when you zoom in
// due to dynamic batching. (Dynamic batching converts local vertex
// data into world space, making local vertex position data unavailable
// to the shader.)
Shader "UVFree/Legacy/Specular Non-Batching" {
Properties {
// Triplanar space, for UI
[Toggle(_UVFREE_LOCAL)] _UVFreeLocal ("Use Local Space (instead of Global)", Float) = 0.0
[Toggle(_UVFREE_VERTEX_COLOR)] _UVFreeVertexColor ("Use Vertex Color", Float) = 0.0
[Toggle(_UVFREE_BUMPED)] _UVFreeBumped ("Use Normal Mapping", Float) = 1.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
[Toggle(_EMISSION)] _Emission ("Use Emission", Float) = 0.0
_TexPower("Texture Power", Range(0.0,20.0)) = 10.0
_Color ("Tint", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 0.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_Shininess("Shininess", Range(0.01, 1.0)) = 0.078125
_SpecColor("Specular", Color) = (0.5,0.5,0.5,1.0)
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.0
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0,16.0)) = 5.0
_EmissionMultiplier("Emission Multiplier", Float) = 0.0
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
"DisableBatching"="True"
}
LOD 300
CGPROGRAM
#pragma target 3.0
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _UVFREE_BUMPED
#pragma shader_feature _UVFREE_RIM
#pragma shader_feature _UVFREE_VERTEX_COLOR
#pragma shader_feature _EMISSION
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
#pragma surface surf BlinnPhong vertex:vert fullforwardshadows
#include "UnityCG.cginc"
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
half _TexPower;
fixed _VertexColorStrength;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
sampler2D _EmissionMap;
half _EmissionMultiplier;
half4 _EmissionColor;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
float _Shininess;
struct Input {
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = v.normal;
#endif
o.powerNormal = pow(abs(v.normal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (o.powerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (o.powerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (o.powerNormal.z)
;
v.tangent.w =
(-(v.normal.x) * (o.powerNormal.x))
+ (-(v.normal.y) * (o.powerNormal.y))
+ (-(v.normal.z) * (o.powerNormal.z))
;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
o.powerNormal = pow(abs(worldNormal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (o.powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (o.powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (o.powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (o.powerNormal.x))
+ (-(worldNormal.y) * (o.powerNormal.y))
+ (-(worldNormal.z) * (o.powerNormal.z))
;
#endif
}
void surf (Input IN, inout SurfaceOutput o) {
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
#endif
// DIFFUSE
//
fixed4 texX = tex2D(_MainTex, xUV);
fixed4 texY = tex2D(_MainTex, yUV);
fixed4 texZ = tex2D(_MainTex, zUV);
fixed4 tex =
texX * IN.powerNormal.x
+ texY * IN.powerNormal.y
+ texZ * IN.powerNormal.z;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
o.Albedo = max(fixed3(0.001,0.001,0.001), tex.rgb * tint.rgb);
o.Alpha = 1.0;
// NORMAL
//
#ifdef _UVFREE_BUMPED
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bump =
bumpX * IN.powerNormal.x
+ bumpY * IN.powerNormal.y
+ bumpZ * IN.powerNormal.z
;
o.Normal = normalize(bump);
#else
o.Normal = fixed3(0.0,0.0,1.0);
#endif
// SPECULAR/GLOSS
//
o.Gloss = tex.a * _SpecColor.a;
o.Specular = _Shininess;
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), o.Normal));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
// EMISSION
//
#ifdef _EMISSION
fixed3 emissionX = tex2D(_EmissionMap, xUV).rgb;
fixed3 emissionY = tex2D(_EmissionMap, yUV).rgb;
fixed3 emissionZ = tex2D(_EmissionMap, zUV).rgb;
o.Emission +=
(emissionX * IN.powerNormal.x + emissionY * IN.powerNormal.y + emissionZ * IN.powerNormal.z)
* _EmissionColor.rgb
* _EmissionMultiplier;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreeLegacyTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6be38e856357c4f12b953c2addabeddb
timeCreated: 1427423850
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,402 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
// Use the non-batching version of this shader if you are using
// local mode, and are seeing the textures move when you zoom in
// due to dynamic batching. (Dynamic batching converts local vertex
// data into world space, making local vertex position data unavailable
// to the shader.)
Shader "UVFree/Legacy/SpecularTopBottom" {
Properties {
// Triplanar space, for UI
[Toggle(_UVFREE_LOCAL)] _UVFreeLocal ("Use Local Space (instead of Global)", Float) = 0.0
[Toggle(_UVFREE_VERTEX_COLOR)] _UVFreeVertexColor ("Use Vertex Color", Float) = 0.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
[Toggle(_UVFREE_BOTTOM)] _UVFreeBottom ("Use Bottom", Float) = 1.0
[Toggle(_EMISSION)] _Emission ("Use Emission", Float) = 0.0
_TexPower("Texture Power", Range(0.0,20.0)) = 10.0
_TopMultiplier ("Top Multiplier (+Y)", Range(0.0,8.0)) = 1.0
_BottomMultiplier ("Bottom Multiplier (-Y)", Range(0.0,8.0)) = 0.0
_Color ("Tint", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 0.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_Shininess("Shininess", Range(0.01, 1.0)) = 0.078125
_SpecColor("Specular", Color) = (0.5,0.5,0.5,1.0)
_EmissionMultiplier("Emission Multiplier", Float) = 0.0
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.0
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0, 16.0)) = 5.0
_TopColor ("Tint", Color) = (1.0,1.0,1.0,1.0)
_TopMainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_TopBumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_TopBumpMap("Normal Map", 2D) = "bump" {}
_TopShininess("Shininess", Range(0.01, 1.0)) = 0.078125
_TopEmissionMultiplier("Emission Multiplier", Float) = 0.0
_TopEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_TopEmissionMap("Emission", 2D) = "white" {}
_BottomColor ("Tint", Color) = (1.0,1.0,1.0,1.0)
_BottomMainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_BottomBumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BottomBumpMap("Normal Map", 2D) = "bump" {}
_BottomEmissionMultiplier("Emission Multiplier", Float) = 0
_BottomEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_BottomEmissionMap("Emission", 2D) = "white" {}
_BottomShininess("Shininess", Range(0.01, 1.0)) = 0.078125
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
}
LOD 300
CGPROGRAM
#pragma target 3.0
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _UVFREE_RIM
#pragma shader_feature _UVFREE_BOTTOM
#pragma shader_feature _UVFREE_VERTEX_COLOR
#pragma shader_feature _EMISSION
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
#pragma surface surf BlinnPhong vertex:vert fullforwardshadows
#include "UnityCG.cginc"
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
//
half _TexPower;
// MAIN
fixed _VertexColorStrength;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
sampler2D _EmissionMap;
half _EmissionMultiplier;
half4 _EmissionColor;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
float _Shininess;
// TOP
half _TopMultiplier;
fixed4 _TopColor;
sampler2D _TopMainTex;
float4 _TopMainTex_ST;
sampler2D _TopBumpMap;
half _TopBumpScale;
sampler2D _TopEmissionMap;
half _TopEmissionMultiplier;
half4 _TopEmissionColor;
float _TopShininess;
// BOTTOM
#ifdef _UVFREE_BOTTOM
half _BottomMultiplier;
fixed4 _BottomColor;
sampler2D _BottomMainTex;
float4 _BottomMainTex_ST;
sampler2D _BottomBumpMap;
half _BottomBumpScale;
sampler2D _BottomEmissionMap;
half _BottomEmissionMultiplier;
half4 _BottomEmissionColor;
float _BottomShininess;
#endif
struct Input {
fixed3 powerNormal;
fixed3 normal;
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
o.normal = v.normal;
fixed3 powerNormal = v.normal;
fixed3 weightedPowerNormal = v.normal;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
o.normal = worldNormal;
fixed3 powerNormal = worldNormal;
fixed3 weightedPowerNormal = worldNormal;
#endif
// texpower sets the sharpness
powerNormal = pow(abs(powerNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, 1.0);
o.powerNormal = powerNormal;
#ifdef _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed3 lerpedPowerNormal = lerp(powerNormal, weightedPowerNormal, weightedPowerNormal.y);
#ifdef _UVFREE_LOCAL
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (lerpedPowerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (lerpedPowerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (lerpedPowerNormal.z)
;
v.tangent.w = dot(-v.normal, lerpedPowerNormal);
#else
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (lerpedPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (lerpedPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (lerpedPowerNormal.z))
;
v.tangent.w = dot(-worldNormal, lerpedPowerNormal);
#endif
}
void surf (Input IN, inout SurfaceOutput o) {
fixed topLerp = smoothstep(0.0, 1.0, _TopMultiplier);
#ifdef _UVFREE_BOTTOM
fixed bottomLerp = smoothstep(0.0, 1.0, _BottomMultiplier);
#endif
fixed3 weightedPowerNormal = IN.normal;
#ifdef _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed topBottomLerp = sign(IN.normal.y)*0.5 + 0.5;
fixed yLerp = weightedPowerNormal.y;
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUVTop = posY * _TopMainTex_ST.xy + _TopMainTex_ST.zw;
#ifdef _UVFREE_BOTTOM
float2 yUVBottom = posY * _BottomMainTex_ST.xy + _BottomMainTex_ST.zw;
#endif
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
yUVTop.y *= powerSign.y;
#ifdef _UVFREE_BOTTOM
yUVBottom.y *= powerSign.y;
#endif
#endif
// DIFFUSE
//
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
fixed4 texX = tex2D(_MainTex, xUV) * tint;
fixed4 texY = tex2D(_MainTex, yUV) * tint;
fixed4 texZ = tex2D(_MainTex, zUV) * tint;
fixed4 texTop = tex2D(_TopMainTex, yUVTop) * _TopColor;
texTop = lerp(texY, texTop, topLerp);
#ifdef _UVFREE_BOTTOM
fixed4 texBottom = tex2D(_BottomMainTex, yUVBottom) * _BottomColor;
texBottom = lerp(texY, texBottom, bottomLerp);
texTop = lerp(texBottom, texTop, topBottomLerp);
#else
texTop = lerp(texY, texTop, topBottomLerp);
#endif
fixed4 tex =
lerp(texX * IN.powerNormal.x, texTop * weightedPowerNormal.x, yLerp)
+ lerp(texY * IN.powerNormal.y, texTop * weightedPowerNormal.y, yLerp)
+ lerp(texZ * IN.powerNormal.z, texTop * weightedPowerNormal.z, yLerp)
;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
o.Albedo = max(fixed3(0.001,0.001,0.001), tex.rgb);
o.Alpha = 1.0;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bumpTop = UnpackScaleNormal(tex2D(_TopBumpMap, yUVTop), _TopBumpScale);
bumpTop = lerp(bumpY, bumpTop, topLerp);
#ifdef _UVFREE_BOTTOM
fixed3 bumpBottom = UnpackScaleNormal(tex2D(_BottomBumpMap, yUVBottom), _BottomBumpScale);
bumpBottom = lerp(bumpY, bumpBottom, bottomLerp);
bumpTop = lerp(bumpBottom, bumpTop, topBottomLerp);
#else
bumpTop = lerp(bumpY, bumpTop, topBottomLerp);
#endif
fixed3 bump =
lerp(bumpX * IN.powerNormal.x, bumpTop * weightedPowerNormal.x, yLerp)
+ lerp(bumpY * IN.powerNormal.y, bumpTop * weightedPowerNormal.y, yLerp)
+ lerp(bumpZ * IN.powerNormal.z, bumpTop * weightedPowerNormal.z, yLerp)
;
o.Normal = normalize(bump);
// SHININESS/GLOSS
//
o.Gloss = tex.a;
float sgY = _Shininess;
float sgTop = _TopShininess;
#ifdef _UVFREE_BOTTOM
float sgBottom = _BottomShininess;
#endif
sgTop = lerp(sgY, sgTop, topLerp);
#ifdef _UVFREE_BOTTOM
sgBottom = lerp(sgY, sgBottom, bottomLerp);
sgTop = lerp(sgBottom, sgTop, topBottomLerp);
#else
sgTop = lerp(sgY, sgTop, topBottomLerp);
#endif
float sg =
lerp(sgY * IN.powerNormal.x, sgTop * weightedPowerNormal.x, yLerp)
+ lerp(sgY * IN.powerNormal.y, sgTop * weightedPowerNormal.y, yLerp)
+ lerp(sgY * IN.powerNormal.z, sgTop * weightedPowerNormal.z, yLerp)
;
o.Gloss = tex.a * _SpecColor.a;
o.Specular = sg;
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), o.Normal));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
// EMISSION
//
#ifdef _EMISSION
half3 emissionX = tex2D(_EmissionMap, xUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionY = tex2D(_EmissionMap, yUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionZ = tex2D(_EmissionMap, zUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionYTop = tex2D(_TopEmissionMap, yUVTop).rgb * _TopEmissionColor.rgb * _TopEmissionMultiplier;
emissionYTop = lerp(emissionY, emissionYTop, topLerp);
#ifdef _UVFREE_BOTTOM
half3 emissionYBottom = tex2D(_BottomEmissionMap, yUVBottom).rgb * _BottomEmissionColor.rgb * _BottomEmissionMultiplier;
emissionYBottom = lerp(emissionY, emissionYBottom, bottomLerp);
emissionYTop = lerp(emissionYBottom, emissionYTop, topBottomLerp);
#else
emissionYTop = lerp(emissionY, emissionYTop, topBottomLerp);
#endif
o.Emission +=
lerp(emissionX * IN.powerNormal.x, emissionYTop * weightedPowerNormal.x, yLerp)
+ lerp(emissionY * IN.powerNormal.y, emissionYTop * weightedPowerNormal.y, yLerp)
+ lerp(emissionZ * IN.powerNormal.z, emissionYTop * weightedPowerNormal.z, yLerp)
;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreeLegacyTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 68f7771eeeaa54d69b83a18f2b59ba8d
timeCreated: 1427440874
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,397 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
Shader "UVFree/Legacy/SpecularTopBottom Non-Batching" {
Properties {
// Triplanar space, for UI
[Toggle(_UVFREE_LOCAL)] _UVFreeLocal ("Use Local Space (instead of Global)", Float) = 0.0
[Toggle(_UVFREE_VERTEX_COLOR)] _UVFreeVertexColor ("Use Vertex Color", Float) = 0.0
[Toggle(_UVFREE_RIM)] _UVFreeRim ("Use Rim Lighting", Float) = 0.0
[Toggle(_UVFREE_BOTTOM)] _UVFreeBottom ("Use Bottom", Float) = 1.0
[Toggle(_EMISSION)] _Emission ("Use Emission", Float) = 0.0
_TexPower("Texture Power", Range(0.0,20.0)) = 10.0
_TopMultiplier ("Top Multiplier (+Y)", Range(0.0,8.0)) = 1.0
_BottomMultiplier ("Bottom Multiplier (-Y)", Range(0.0,8.0)) = 0.0
_Color ("Tint", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 0.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_Shininess("Shininess", Range(0.01, 1.0)) = 0.078125
_SpecColor("Specular", Color) = (0.5,0.5,0.5,1.0)
_EmissionMultiplier("Emission Multiplier", Float) = 0.0
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
_RimMultiplier ("Rim Multiplier", Range(0.0,8.0)) = 0.0
_RimColor ("Rim Color (RGB) Strength (A)", Color) = (1.0,1.0,1.0,1.0)
_RimPower ("Rim Power", Range(0.0, 16.0)) = 5.0
_TopColor ("Tint", Color) = (1.0,1.0,1.0,1.0)
_TopMainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_TopBumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_TopBumpMap("Normal Map", 2D) = "bump" {}
_TopShininess("Shininess", Range(0.01, 1.0)) = 0.078125
_TopEmissionMultiplier("Emission Multiplier", Float) = 0.0
_TopEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_TopEmissionMap("Emission", 2D) = "white" {}
_BottomColor ("Tint", Color) = (1.0,1.0,1.0,1.0)
_BottomMainTex ("Base Color (RGB) Gloss (A)", 2D) = "white" {}
_BottomBumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_BottomBumpMap("Normal Map", 2D) = "bump" {}
_BottomEmissionMultiplier("Emission Multiplier", Float) = 0
_BottomEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_BottomEmissionMap("Emission", 2D) = "white" {}
_BottomShininess("Shininess", Range(0.01, 1.0)) = 0.078125
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
"DisableBatching"="True"
}
LOD 300
CGPROGRAM
#pragma target 3.0
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _UVFREE_RIM
#pragma shader_feature _UVFREE_BOTTOM
#pragma shader_feature _UVFREE_VERTEX_COLOR
#pragma shader_feature _EMISSION
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
#pragma surface surf BlinnPhong vertex:vert fullforwardshadows
#include "UnityCG.cginc"
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
//
half _TexPower;
// MAIN
fixed _VertexColorStrength;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
sampler2D _EmissionMap;
half _EmissionMultiplier;
half4 _EmissionColor;
fixed4 _RimColor;
half _RimPower;
half _RimMultiplier;
float _Shininess;
// TOP
half _TopMultiplier;
fixed4 _TopColor;
sampler2D _TopMainTex;
float4 _TopMainTex_ST;
sampler2D _TopBumpMap;
half _TopBumpScale;
sampler2D _TopEmissionMap;
half _TopEmissionMultiplier;
half4 _TopEmissionColor;
float _TopShininess;
// BOTTOM
#ifdef _UVFREE_BOTTOM
half _BottomMultiplier;
fixed4 _BottomColor;
sampler2D _BottomMainTex;
float4 _BottomMainTex_ST;
sampler2D _BottomBumpMap;
half _BottomBumpScale;
sampler2D _BottomEmissionMap;
half _BottomEmissionMultiplier;
half4 _BottomEmissionColor;
float _BottomShininess;
#endif
struct Input {
fixed3 powerNormal;
fixed3 normal;
float3 worldPos;
#ifdef _UVFREE_RIM
fixed3 viewDir;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
o.normal = v.normal;
fixed3 powerNormal = v.normal;
fixed3 weightedPowerNormal = v.normal;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
o.normal = worldNormal;
fixed3 powerNormal = worldNormal;
fixed3 weightedPowerNormal = worldNormal;
#endif
// texpower sets the sharpness
powerNormal = pow(abs(powerNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, 1.0);
o.powerNormal = powerNormal;
#ifdef _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed3 lerpedPowerNormal = lerp(powerNormal, weightedPowerNormal, weightedPowerNormal.y);
#ifdef _UVFREE_LOCAL
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (lerpedPowerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (lerpedPowerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (lerpedPowerNormal.z)
;
v.tangent.w = dot(-v.normal, lerpedPowerNormal);
#else
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (lerpedPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (lerpedPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (lerpedPowerNormal.z))
;
v.tangent.w = dot(-worldNormal, lerpedPowerNormal);
#endif
}
void surf (Input IN, inout SurfaceOutput o) {
fixed topLerp = smoothstep(0.0, 1.0, _TopMultiplier);
#ifdef _UVFREE_BOTTOM
fixed bottomLerp = smoothstep(0.0, 1.0, _BottomMultiplier);
#endif
fixed3 weightedPowerNormal = IN.normal;
#ifdef _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed topBottomLerp = sign(IN.normal.y)*0.5 + 0.5;
fixed yLerp = weightedPowerNormal.y;
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUVTop = posY * _TopMainTex_ST.xy + _TopMainTex_ST.zw;
#ifdef _UVFREE_BOTTOM
float2 yUVBottom = posY * _BottomMainTex_ST.xy + _BottomMainTex_ST.zw;
#endif
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
yUVTop.y *= powerSign.y;
#ifdef _UVFREE_BOTTOM
yUVBottom.y *= powerSign.y;
#endif
#endif
// DIFFUSE
//
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
fixed4 texX = tex2D(_MainTex, xUV) * tint;
fixed4 texY = tex2D(_MainTex, yUV) * tint;
fixed4 texZ = tex2D(_MainTex, zUV) * tint;
fixed4 texTop = tex2D(_TopMainTex, yUVTop) * _TopColor;
texTop = lerp(texY, texTop, topLerp);
#ifdef _UVFREE_BOTTOM
fixed4 texBottom = tex2D(_BottomMainTex, yUVBottom) * _BottomColor;
texBottom = lerp(texY, texBottom, bottomLerp);
texTop = lerp(texBottom, texTop, topBottomLerp);
#else
texTop = lerp(texY, texTop, topBottomLerp);
#endif
fixed4 tex =
lerp(texX * IN.powerNormal.x, texTop * weightedPowerNormal.x, yLerp)
+ lerp(texY * IN.powerNormal.y, texTop * weightedPowerNormal.y, yLerp)
+ lerp(texZ * IN.powerNormal.z, texTop * weightedPowerNormal.z, yLerp)
;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
o.Albedo = max(fixed3(0.001,0.001,0.001), tex.rgb);
o.Alpha = 1.0;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bumpTop = UnpackScaleNormal(tex2D(_TopBumpMap, yUVTop), _TopBumpScale);
bumpTop = lerp(bumpY, bumpTop, topLerp);
#ifdef _UVFREE_BOTTOM
fixed3 bumpBottom = UnpackScaleNormal(tex2D(_BottomBumpMap, yUVBottom), _BottomBumpScale);
bumpBottom = lerp(bumpY, bumpBottom, bottomLerp);
bumpTop = lerp(bumpBottom, bumpTop, topBottomLerp);
#else
bumpTop = lerp(bumpY, bumpTop, topBottomLerp);
#endif
fixed3 bump =
lerp(bumpX * IN.powerNormal.x, bumpTop * weightedPowerNormal.x, yLerp)
+ lerp(bumpY * IN.powerNormal.y, bumpTop * weightedPowerNormal.y, yLerp)
+ lerp(bumpZ * IN.powerNormal.z, bumpTop * weightedPowerNormal.z, yLerp)
;
o.Normal = normalize(bump);
// SHININESS/GLOSS
//
o.Gloss = tex.a;
float sgY = _Shininess;
float sgTop = _TopShininess;
#ifdef _UVFREE_BOTTOM
float sgBottom = _BottomShininess;
#endif
sgTop = lerp(sgY, sgTop, topLerp);
#ifdef _UVFREE_BOTTOM
sgBottom = lerp(sgY, sgBottom, bottomLerp);
sgTop = lerp(sgBottom, sgTop, topBottomLerp);
#else
sgTop = lerp(sgY, sgTop, topBottomLerp);
#endif
float sg =
lerp(sgY * IN.powerNormal.x, sgTop * weightedPowerNormal.x, yLerp)
+ lerp(sgY * IN.powerNormal.y, sgTop * weightedPowerNormal.y, yLerp)
+ lerp(sgY * IN.powerNormal.z, sgTop * weightedPowerNormal.z, yLerp)
;
o.Gloss = tex.a * _SpecColor.a;
o.Specular = sg;
// RIM
//
#ifdef _UVFREE_RIM
half rimStrength = 1.0 - max(0.0, dot(normalize(IN.viewDir), o.Normal));
o.Emission = _RimMultiplier * _RimColor.rgb * pow(rimStrength, _RimPower) * _RimColor.a;
#endif
// EMISSION
//
#ifdef _EMISSION
half3 emissionX = tex2D(_EmissionMap, xUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionY = tex2D(_EmissionMap, yUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionZ = tex2D(_EmissionMap, zUV).rgb * _EmissionColor.rgb * _EmissionMultiplier;
half3 emissionYTop = tex2D(_TopEmissionMap, yUVTop).rgb * _TopEmissionColor.rgb * _TopEmissionMultiplier;
emissionYTop = lerp(emissionY, emissionYTop, topLerp);
#ifdef _UVFREE_BOTTOM
half3 emissionYBottom = tex2D(_BottomEmissionMap, yUVBottom).rgb * _BottomEmissionColor.rgb * _BottomEmissionMultiplier;
emissionYBottom = lerp(emissionY, emissionYBottom, bottomLerp);
emissionYTop = lerp(emissionYBottom, emissionYTop, topBottomLerp);
#else
emissionYTop = lerp(emissionY, emissionYTop, topBottomLerp);
#endif
o.Emission +=
lerp(emissionX * IN.powerNormal.x, emissionYTop * weightedPowerNormal.x, yLerp)
+ lerp(emissionY * IN.powerNormal.y, emissionYTop * weightedPowerNormal.y, yLerp)
+ lerp(emissionZ * IN.powerNormal.z, emissionYTop * weightedPowerNormal.z, yLerp)
;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreeLegacyTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 935d64de9b72849c9aa20b71c7163804
timeCreated: 1427440874
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8861925d8cda348cba47e6a219c7c13e
folderAsset: yes
timeCreated: 1426651302
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3f4ff884353af49f3ac1596796b3a9d7
folderAsset: yes
timeCreated: 1426710566
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,355 @@
using System;
using UnityEngine;
namespace UnityEditor
{
internal class UVFreePBRShaderGUI : ShaderGUI
{
private enum WorkflowMode
{
Specular,
Metallic,
Dielectric
}
private static class Styles
{
public static GUIStyle optionsButton = "PaneOptions";
public static string emptyTootip = "";
public static GUIContent triplanarSpace = new GUIContent("Triplanar Space", "Whether the triplanar projection should be in local or global space");
public static GUIContent texturePowerText = new GUIContent("Texture Power", "How strong textures on different axes are differentiated. 1 for smooth blending, 10+ for sharper contrasts");
public static GUIContent vertexColorStrengthText = new GUIContent("Vertex Color Strength", "0 for no vertex color (off), 1 for full vertex color tinting");
public static GUIContent albedoText = new GUIContent("Albedo", "Albedo (RGB) and Transparency (A)");
public static GUIContent alphaCutoffText = new GUIContent("Alpha Cutoff", "Threshold for alpha cutoff");
public static GUIContent specularMapText = new GUIContent("Specular", "Specular (RGB) and Smoothness (A)");
public static GUIContent metallicMapText = new GUIContent("Metallic", "Metallic (R) and Smoothness (A)");
public static GUIContent smoothnessText = new GUIContent("Smoothness", "");
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map");
public static GUIContent heightMapText = new GUIContent("Height Map", "Height Map (G)");
public static GUIContent occlusionText = new GUIContent("Occlusion", "Occlusion (G)");
public static GUIContent emissionText = new GUIContent("Emission", "Emission (RGB)");
public static GUIContent detailMaskText = new GUIContent("Detail Mask", "Mask for Secondary Maps (A)");
public static GUIContent detailAlbedoText = new GUIContent("Detail Albedo x2", "Albedo (RGB) multiplied by 2");
public static GUIContent detailNormalMapText = new GUIContent("Normal Map", "Normal Map");
public static string whiteSpaceString = " ";
public static string primaryMapsText = "Main Maps";
public static string secondaryMapsText = "Secondary Maps";
public static GUIContent emissiveWarning = new GUIContent ("Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive.");
public static GUIContent emissiveColorWarning = new GUIContent ("Ensure emissive color is non-black for emission to have effect.");
public static readonly string[] spaceNames = Enum.GetNames (typeof(Space));
public static string advancedText = "Advanced Options";
}
MaterialProperty vertexColorStrength = null;
MaterialProperty albedoMap = null;
MaterialProperty albedoColor = null;
MaterialProperty specularMap = null;
MaterialProperty specularColor = null;
MaterialProperty metallicMap = null;
MaterialProperty metallic = null;
MaterialProperty smoothness = null;
MaterialProperty bumpScale = null;
MaterialProperty bumpMap = null;
MaterialProperty occlusionStrength = null;
MaterialProperty occlusionMap = null;
MaterialProperty heigtMapScale = null;
MaterialProperty heightMap = null;
MaterialProperty emissionScaleUI = null;
MaterialProperty emissionColorUI = null;
MaterialProperty emissionColorForRendering = null;
MaterialProperty emissionMap = null;
MaterialProperty detailMask = null;
MaterialProperty detailAlbedoMap = null;
MaterialProperty detailNormalMapScale = null;
MaterialProperty detailNormalMap = null;
MaterialProperty texturePower = null;
MaterialProperty triplanarSpace = null;
MaterialEditor m_MaterialEditor;
WorkflowMode m_WorkflowMode = WorkflowMode.Specular;
bool m_FirstTimeApply = true;
public void FindProperties (MaterialProperty[] props)
{
triplanarSpace = FindProperty("_TriplanarSpace", props, false);
texturePower = FindProperty("_TexPower", props, false);
vertexColorStrength = FindProperty("_VertexColorStrength", props, false);
albedoMap = FindProperty ("_MainTex", props);
albedoColor = FindProperty ("_Color", props);
specularMap = FindProperty ("_SpecGlossMap", props, false);
specularColor = FindProperty ("_SpecColor", props, false);
metallicMap = FindProperty ("_MetallicGlossMap", props, false);
metallic = FindProperty ("_Metallic", props, false);
if (specularMap != null && specularColor != null)
m_WorkflowMode = WorkflowMode.Specular;
else if (metallicMap != null && metallic != null)
m_WorkflowMode = WorkflowMode.Metallic;
else
m_WorkflowMode = WorkflowMode.Dielectric;
smoothness = FindProperty ("_Glossiness", props);
bumpScale = FindProperty ("_BumpScale", props);
bumpMap = FindProperty ("_BumpMap", props);
heigtMapScale = FindProperty ("_Parallax", props);
heightMap = FindProperty("_ParallaxMap", props);
occlusionStrength = FindProperty ("_OcclusionStrength", props);
occlusionMap = FindProperty ("_OcclusionMap", props);
emissionScaleUI = FindProperty ("_EmissionScaleUI", props);
emissionColorUI = FindProperty ("_EmissionColorUI", props);
emissionColorForRendering = FindProperty ("_EmissionColor", props);
emissionMap = FindProperty ("_EmissionMap", props);
detailMask = FindProperty ("_DetailMask", props);
detailAlbedoMap = FindProperty ("_DetailAlbedoMap", props);
detailNormalMapScale = FindProperty ("_DetailNormalMapScale", props);
detailNormalMap = FindProperty ("_DetailNormalMap", props);
}
public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] props)
{
FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor;
Material material = materialEditor.target as Material;
ShaderPropertiesGUI (material);
// Make sure that needed keywords are set up if we're switching some existing
// material to a standard shader.
if (m_FirstTimeApply)
{
SetMaterialKeywords (material, m_WorkflowMode);
m_FirstTimeApply = false;
}
}
public void ShaderPropertiesGUI (Material material)
{
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
// Detect any changes to the material
EditorGUI.BeginChangeCheck();
{
TriplanarSpacePopup();
m_MaterialEditor.RangeProperty (texturePower, "Texture Power");
if (vertexColorStrength != null)
{
m_MaterialEditor.RangeProperty (vertexColorStrength, Styles.vertexColorStrengthText.text);
}
// Primary properties
GUILayout.Label (Styles.primaryMapsText, EditorStyles.boldLabel);
DoAlbedoArea(material);
DoSpecularMetallicArea();
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap, bumpMap.textureValue != null ? bumpScale : null);
m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap, heightMap.textureValue != null ? heigtMapScale : null);
m_MaterialEditor.TexturePropertySingleLine(Styles.occlusionText, occlusionMap, occlusionMap.textureValue != null ? occlusionStrength : null);
DoEmissionArea(material);
m_MaterialEditor.TexturePropertySingleLine(Styles.detailMaskText, detailMask);
EditorGUI.BeginChangeCheck();
m_MaterialEditor.TextureScaleOffsetProperty(albedoMap);
if (EditorGUI.EndChangeCheck())
emissionMap.textureScaleAndOffset = albedoMap.textureScaleAndOffset; // Apply the main texture scale and offset to the emission texture as well, for Enlighten's sake
EditorGUILayout.Space();
// Secondary properties
GUILayout.Label(Styles.secondaryMapsText, EditorStyles.boldLabel);
m_MaterialEditor.TexturePropertySingleLine(Styles.detailAlbedoText, detailAlbedoMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.detailNormalMapText, detailNormalMap, detailNormalMapScale);
m_MaterialEditor.TextureScaleOffsetProperty(detailAlbedoMap);
}
if (EditorGUI.EndChangeCheck())
{
MaterialChanged(material, m_WorkflowMode);
}
EditorGUILayout.Space();
GUILayout.Label(Styles.advancedText, EditorStyles.boldLabel);
m_MaterialEditor.RenderQueueField();
m_MaterialEditor.EnableInstancingField();
m_MaterialEditor.DoubleSidedGIField();
}
//internal
void DetermineWorkflow(MaterialProperty[] props)
{
if (FindProperty("_SpecGlossMap", props, false) != null && FindProperty("_SpecColor", props, false) != null)
m_WorkflowMode = WorkflowMode.Specular;
else if (FindProperty("_MetallicGlossMap", props, false) != null && FindProperty("_Metallic", props, false) != null)
m_WorkflowMode = WorkflowMode.Metallic;
else
m_WorkflowMode = WorkflowMode.Dielectric;
}
public override void AssignNewShaderToMaterial (Material material, Shader oldShader, Shader newShader)
{
base.AssignNewShaderToMaterial(material, oldShader, newShader);
return;
}
void TriplanarSpacePopup()
{
EditorGUI.showMixedValue = triplanarSpace.hasMixedValue;
var space = (Space)triplanarSpace.floatValue;
EditorGUI.BeginChangeCheck();
space = (Space)EditorGUILayout.Popup(Styles.triplanarSpace.text, (int)space, Styles.spaceNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Triplanar Space");
triplanarSpace.floatValue = (float)space;
}
EditorGUI.showMixedValue = false;
}
void DoAlbedoArea(Material material)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoText, albedoMap, albedoColor);
}
void DoEmissionArea(Material material)
{
bool showEmissionColorAndGIControls = emissionScaleUI.floatValue > 0f;
bool hadEmissionTexture = emissionMap.textureValue != null;
// Do controls
m_MaterialEditor.TexturePropertySingleLine(Styles.emissionText, emissionMap, showEmissionColorAndGIControls ? emissionColorUI : null, emissionScaleUI);
// Set default emissionScaleUI if texture was assigned
if (emissionMap.textureValue != null && !hadEmissionTexture && emissionScaleUI.floatValue <= 0f)
emissionScaleUI.floatValue = 1.0f;
// Dynamic Lightmapping mode
if (showEmissionColorAndGIControls)
{
bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled(EvalFinalEmissionColor(material));
EditorGUI.BeginDisabledGroup(!shouldEmissionBeEnabled);
m_MaterialEditor.LightmapEmissionProperty (MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1);
EditorGUI.EndDisabledGroup();
}
if (!HasValidEmissiveKeyword(material))
{
EditorGUILayout.HelpBox(Styles.emissiveWarning.text, MessageType.Warning);
}
}
void DoSpecularMetallicArea()
{
if (m_WorkflowMode == WorkflowMode.Specular)
{
if (specularMap.textureValue == null)
m_MaterialEditor.TexturePropertyTwoLines(Styles.specularMapText, specularMap, specularColor, Styles.smoothnessText, smoothness);
else
m_MaterialEditor.TexturePropertySingleLine(Styles.specularMapText, specularMap);
}
else if (m_WorkflowMode == WorkflowMode.Metallic)
{
if (metallicMap.textureValue == null)
m_MaterialEditor.TexturePropertyTwoLines(Styles.metallicMapText, metallicMap, metallic, Styles.smoothnessText, smoothness);
else
m_MaterialEditor.TexturePropertySingleLine(Styles.metallicMapText, metallicMap);
}
}
// Calculate final HDR _EmissionColor (gamma space) from _EmissionColorUI (LDR, gamma) & _EmissionScaleUI (gamma)
static Color EvalFinalEmissionColor(Material material)
{
return material.GetColor("_EmissionColorUI") * material.GetFloat("_EmissionScaleUI");
}
static bool ShouldEmissionBeEnabled (Color color)
{
return color.grayscale > (0.1f / 255.0f);
}
static void SetMaterialKeywords(Material material, WorkflowMode workflowMode)
{
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
// (MaterialProperty value might come from renderer material property block)
if (workflowMode == WorkflowMode.Specular)
SetKeyword (material, "_SPECGLOSSMAP", material.GetTexture ("_SpecGlossMap"));
else if (workflowMode == WorkflowMode.Metallic)
SetKeyword (material, "_METALLICGLOSSMAP", material.GetTexture ("_MetallicGlossMap"));
SetKeyword (material, "_PARALLAXMAP", material.GetTexture ("_ParallaxMap"));
SetKeyword (material, "_DETAIL", material.GetTexture ("_DetailAlbedoMap") || material.GetTexture ("_DetailNormalMap"));
SetKeyword (material, "_OCCLUSION", material.GetTexture ("_OcclusionMap"));
bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled (material.GetColor("_EmissionColor"));
SetKeyword (material, "_EMISSION", shouldEmissionBeEnabled);
// Triplanar texture space"
SetKeyword(material, "_UVFREE_LOCAL", material.GetFloat ("_TriplanarSpace") == (float) Space.Self);
// Setup lightmap emissive flags
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
{
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
if (!shouldEmissionBeEnabled)
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
material.globalIlluminationFlags = flags;
}
}
bool HasValidEmissiveKeyword (Material material)
{
// Material animation might be out of sync with the material keyword.
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
bool hasEmissionKeyword = material.IsKeywordEnabled ("_EMISSION");
if (!hasEmissionKeyword && ShouldEmissionBeEnabled (emissionColorForRendering.colorValue))
return false;
else
return true;
}
static void MaterialChanged(Material material, WorkflowMode workflowMode)
{
// Clamp EmissionScale to always positive
if (material.GetFloat("_EmissionScaleUI") < 0.0f)
material.SetFloat("_EmissionScaleUI", 0.0f);
// Apply combined emission value
Color emissionColorOut = EvalFinalEmissionColor (material);
material.SetColor("_EmissionColor", emissionColorOut);
if (workflowMode == WorkflowMode.Metallic)
{
material.SetFloat ("_UsingMetallicGlossMap", (material.GetTexture ("_MetallicGlossMap") == null) ? 0.0f : 1.0f);
}
else if (workflowMode == WorkflowMode.Specular)
{
material.SetFloat ("_UsingSpecGlossMap", (material.GetTexture ("_SpecGlossMap") == null) ? 0.0f : 1.0f);
}
SetMaterialKeywords(material, workflowMode);
}
static void SetKeyword(Material m, string keyword, bool state)
{
//Debug.Log(keyword + ": " + state);
if (state)
m.EnableKeyword (keyword);
else
m.DisableKeyword (keyword);
}
}
} // namespace UnityEditor
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 485031e932da44c3dbcf72498f29c253
timeCreated: 1426710593
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,620 @@
using System;
using UnityEngine;
namespace UnityEditor
{
internal class UVFreePBRShaderTopBottomGUI : ShaderGUI
{
private enum WorkflowMode
{
Specular,
Metallic,
Dielectric
}
private static class Styles
{
public static GUIStyle optionsButton = "PaneOptions";
public static string emptyTootip = "";
public static GUIContent triplanarSpace = new GUIContent("Triplanar Space", "Whether the triplanar projection should be in local or global space");
public static GUIContent texturePowerText = new GUIContent("Texture Power", "How strong textures on different axes are differentiated. 1 for smooth blending, 10+ for sharper contrasts");
public static GUIContent topMultiplierText = new GUIContent("Top Strength", "How much of the mesh should be considered the top. Set to 0 to disable.");
public static GUIContent bottomMultiplierText = new GUIContent("Bottom Strength", "How much of the mesh should be considered the bottom. Set to 0 to disable.");
public static GUIContent vertexColorStrengthText = new GUIContent("Vertex Color Strength", "0 for no vertex color (off), 1 for full vertex color tinting");
public static GUIContent albedoLabel = new GUIContent("Albedo", "Albedo (RGB) and Transparency (A)");
public static GUIContent albedoText = new GUIContent("Main", "Albedo (RGB) and Transparency (A)");
public static GUIContent albedoTextTop = new GUIContent("Top (+Y)", "Albedo (RGB) and Transparency (A)");
public static GUIContent albedoTextBottom = new GUIContent("Bottom (-Y)", "Albedo (RGB) and Transparency (A)");
public static GUIContent specularLabel = new GUIContent("Specular", "Specular (RGB) and Smoothness (A)");
public static GUIContent specularMapText = new GUIContent("Main", "Specular (RGB) and Smoothness (A)");
public static GUIContent specularMapTextTop = new GUIContent("Top (+Y)", "Specular (RGB) and Smoothness (A)");
public static GUIContent specularMapTextBottom = new GUIContent("Bottom (-Y)", "Specular (RGB) and Smoothness (A)");
public static GUIContent metallicLabel = new GUIContent("Metallic", "Metallic (R) and Smoothness (A)");
public static GUIContent metallicMapText = new GUIContent("Main", "Metallic (R) and Smoothness (A)");
public static GUIContent metallicMapTextTop = new GUIContent("Top (+Y)", "Metallic (R) and Smoothness (A)");
public static GUIContent metallicMapTextBottom = new GUIContent("Bottom (-Y)", "Metallic (R) and Smoothness (A)");
public static GUIContent smoothnessText = new GUIContent("Smoothness", "");
public static GUIContent smoothnessTextTop = new GUIContent("Smoothness", "");
public static GUIContent smoothnessTextBottom = new GUIContent("Smoothness", "");
public static GUIContent normalLabel = new GUIContent("Normal", "Normal Map");
public static GUIContent normalMapText = new GUIContent("Main", "Normal Map");
public static GUIContent normalMapTextTop = new GUIContent("Top (+Y)", "Normal Map");
public static GUIContent normalMapTextBottom = new GUIContent("Bottom (-Y)", "Normal Map");
public static GUIContent emissionLabel = new GUIContent("Emission", "Emission (RGB)");
public static GUIContent emissionText = new GUIContent("Main", "Emission (RGB)");
public static GUIContent emissionTextTop = new GUIContent("Top (+Y)", "Emission (RGB)");
public static GUIContent emissionTextBottom = new GUIContent("Bottom (-Y)", "Emission (RGB)");
public static string textureScaleOffset = "Main Texture Scale/Offset";
public static string textureScaleOffsetTop = "Top (+Y) Texture Scale/Offset";
public static string textureScaleOffsetBottom = "Bottom (-Y) Texture Scale/Offset";
public static string whiteSpaceString = " ";
public static GUIContent emissiveWarning = new GUIContent ("Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive.");
public static GUIContent emissiveColorWarning = new GUIContent ("Ensure emissive color is non-black for emission to have effect.");
public static readonly string[] spaceNames = Enum.GetNames (typeof(Space));
public static string advancedText = "Advanced Options";
}
private const float MIN_VALUE = 0.0f;
// FRONT
MaterialProperty vertexColorStrength = null;
MaterialProperty albedoMap = null;
MaterialProperty albedoColor = null;
MaterialProperty specularMap = null;
MaterialProperty specularColor = null;
MaterialProperty metallicMap = null;
MaterialProperty metallic = null;
MaterialProperty smoothness = null;
MaterialProperty bumpScale = null;
MaterialProperty bumpMap = null;
MaterialProperty emissionScaleUI = null;
MaterialProperty emissionColorUI = null;
MaterialProperty emissionColorForRendering = null;
MaterialProperty emissionMap = null;
// TOP
MaterialProperty albedoMapTop = null;
MaterialProperty albedoColorTop = null;
MaterialProperty specularMapTop = null;
MaterialProperty specularColorTop = null;
MaterialProperty metallicMapTop = null;
MaterialProperty metallicTop = null;
MaterialProperty smoothnessTop = null;
MaterialProperty bumpScaleTop = null;
MaterialProperty bumpMapTop = null;
MaterialProperty emissionScaleUITop = null;
MaterialProperty emissionColorUITop = null;
MaterialProperty emissionMapTop = null;
// BOTTOM
MaterialProperty albedoMapBottom = null;
MaterialProperty albedoColorBottom = null;
MaterialProperty specularMapBottom = null;
MaterialProperty specularColorBottom = null;
MaterialProperty metallicMapBottom = null;
MaterialProperty metallicBottom = null;
MaterialProperty smoothnessBottom = null;
MaterialProperty bumpScaleBottom = null;
MaterialProperty bumpMapBottom = null;
MaterialProperty emissionScaleUIBottom = null;
MaterialProperty emissionColorUIBottom = null;
MaterialProperty emissionMapBottom = null;
MaterialProperty texturePower = null;
MaterialProperty triplanarSpace = null;
MaterialProperty topMultiplier = null;
MaterialProperty bottomMultiplier = null;
MaterialEditor m_MaterialEditor;
WorkflowMode m_WorkflowMode = WorkflowMode.Specular;
bool m_FirstTimeApply = true;
public void FindProperties (MaterialProperty[] props)
{
triplanarSpace = FindProperty("_TriplanarSpace", props, false);
texturePower = FindProperty("_TexPower", props, false);
topMultiplier = FindProperty("_TopMultiplier", props, false);
bottomMultiplier = FindProperty("_BottomMultiplier", props, false);
vertexColorStrength = FindProperty("_VertexColorStrength", props, false);
albedoMap = FindProperty ("_MainTex", props);
albedoColor = FindProperty ("_Color", props);
specularMap = FindProperty ("_SpecGlossMap", props, false);
specularColor = FindProperty ("_SpecColor", props, false);
metallicMap = FindProperty ("_MetallicGlossMap", props, false);
metallic = FindProperty ("_Metallic", props, false);
if (specularMap != null && specularColor != null)
{
m_WorkflowMode = WorkflowMode.Specular;
}
else if (metallicMap != null && metallic != null)
{
m_WorkflowMode = WorkflowMode.Metallic;
}
else
{
m_WorkflowMode = WorkflowMode.Dielectric;
}
smoothness = FindProperty ("_Glossiness", props);
bumpScale = FindProperty ("_BumpScale", props);
bumpMap = FindProperty ("_BumpMap", props);
emissionMap = FindProperty("_EmissionMap", props);
emissionScaleUI = FindProperty ("_EmissionScaleUI", props);
emissionColorUI = FindProperty ("_EmissionColorUI", props);
emissionColorForRendering = FindProperty ("_EmissionColor", props);
// TOP
albedoMapTop = FindProperty ("_TopMainTex", props, false);
albedoColorTop = FindProperty ("_TopColor", props, false);
specularMapTop = FindProperty ("_TopSpecGlossMap", props, false);
specularColorTop = FindProperty ("_TopSpecColor", props, false);
metallicMapTop = FindProperty ("_TopMetallicGlossMap", props, false);
metallicTop = FindProperty ("_TopMetallic", props, false);
smoothnessTop = FindProperty ("_TopGlossiness", props, false);
bumpScaleTop = FindProperty ("_TopBumpScale", props, false);
bumpMapTop = FindProperty ("_TopBumpMap", props, false);
emissionMapTop = FindProperty("_TopEmissionMap", props);
emissionScaleUITop = FindProperty ("_TopEmissionScaleUI", props);
emissionColorUITop = FindProperty ("_TopEmissionColorUI", props);
// BOTTOM
albedoMapBottom = FindProperty ("_BottomMainTex", props, false);
albedoColorBottom = FindProperty ("_BottomColor", props, false);
specularMapBottom = FindProperty ("_BottomSpecGlossMap", props, false);
specularColorBottom = FindProperty ("_BottomSpecColor", props, false);
metallicMapBottom = FindProperty ("_BottomMetallicGlossMap", props, false);
metallicBottom = FindProperty ("_BottomMetallic", props, false);
smoothnessBottom = FindProperty ("_BottomGlossiness", props, false);
bumpScaleBottom = FindProperty ("_BottomBumpScale", props, false);
bumpMapBottom = FindProperty ("_BottomBumpMap", props, false);
emissionMapBottom = FindProperty("_BottomEmissionMap", props, false);
emissionScaleUIBottom = FindProperty ("_BottomEmissionScaleUI", props, false);
emissionColorUIBottom = FindProperty ("_BottomEmissionColorUI", props, false);
}
public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] props)
{
FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor;
Material material = materialEditor.target as Material;
ShaderPropertiesGUI (material);
// Make sure that needed keywords are set up if we're switching some existing
// material to a standard shader.
if (m_FirstTimeApply)
{
SetMaterialKeywords (material, m_WorkflowMode);
m_FirstTimeApply = false;
}
}
public void ShaderPropertiesGUI (Material material)
{
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
// Detect any changes to the material
EditorGUI.BeginChangeCheck();
{
TriplanarSpacePopup();
m_MaterialEditor.RangeProperty (texturePower, "Texture Power");
m_MaterialEditor.RangeProperty (topMultiplier, "Top Multiplier");
m_MaterialEditor.RangeProperty (bottomMultiplier, "Bottom Multiplier");
if (vertexColorStrength != null)
{
m_MaterialEditor.RangeProperty (vertexColorStrength, Styles.vertexColorStrengthText.text);
}
DoAlbedoArea(material);
DoSpecularMetallicArea(material);
// bump
GUILayout.Label(Styles.normalLabel, EditorStyles.boldLabel);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap, bumpMap.textureValue != null ? bumpScale : null);
if (topMultiplier.floatValue > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapTextTop, bumpMapTop, bumpMapTop.textureValue != null ? bumpScaleTop : null);
}
if (bottomMultiplier.floatValue > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapTextBottom, bumpMapBottom, bumpMapBottom.textureValue != null ? bumpScaleBottom : null);
}
DoEmissionArea(material);
// MAIN
EditorGUILayout.Space();
GUILayout.Label(Styles.textureScaleOffset, EditorStyles.boldLabel);
m_MaterialEditor.TextureScaleOffsetProperty(albedoMap);
// TOP
if (topMultiplier.floatValue > MIN_VALUE)
{
EditorGUILayout.Space();
GUILayout.Label(Styles.textureScaleOffsetTop, EditorStyles.boldLabel);
m_MaterialEditor.TextureScaleOffsetProperty(albedoMapTop);
}
// BOTTOM
if (bottomMultiplier.floatValue > MIN_VALUE)
{
EditorGUILayout.Space();
GUILayout.Label(Styles.textureScaleOffsetBottom, EditorStyles.boldLabel);
m_MaterialEditor.TextureScaleOffsetProperty(albedoMapBottom);
}
}
if (EditorGUI.EndChangeCheck())
{
MaterialChanged(material, m_WorkflowMode);
}
EditorGUILayout.Space();
GUILayout.Label(Styles.advancedText, EditorStyles.boldLabel);
m_MaterialEditor.RenderQueueField();
m_MaterialEditor.EnableInstancingField();
m_MaterialEditor.DoubleSidedGIField();
}
//internal
void DetermineWorkflow(MaterialProperty[] props)
{
if (FindProperty("_SpecGlossMap", props, false) != null && FindProperty("_SpecColor", props, false) != null)
m_WorkflowMode = WorkflowMode.Specular;
else if (FindProperty("_MetallicGlossMap", props, false) != null && FindProperty("_Metallic", props, false) != null)
m_WorkflowMode = WorkflowMode.Metallic;
else
m_WorkflowMode = WorkflowMode.Dielectric;
}
public override void AssignNewShaderToMaterial (Material material, Shader oldShader, Shader newShader)
{
base.AssignNewShaderToMaterial(material, oldShader, newShader);
}
void TriplanarSpacePopup()
{
EditorGUI.showMixedValue = triplanarSpace.hasMixedValue;
var space = (Space)triplanarSpace.floatValue;
EditorGUI.BeginChangeCheck();
space = (Space)EditorGUILayout.Popup(Styles.triplanarSpace.text, (int)space, Styles.spaceNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Triplanar Space");
triplanarSpace.floatValue = (float)space;
}
EditorGUI.showMixedValue = false;
}
void DoAlbedoArea(Material material)
{
GUILayout.Label(Styles.albedoLabel, EditorStyles.boldLabel);
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoText, albedoMap, albedoColor);
if (material.GetFloat ("_TopMultiplier") > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoTextTop, albedoMapTop, albedoColorTop);
}
if (material.GetFloat ("_BottomMultiplier") > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoTextBottom, albedoMapBottom, albedoColorBottom);
}
}
void DoEmissionArea(Material material)
{
GUILayout.Label(Styles.emissionLabel, EditorStyles.boldLabel);
bool showEmissionColorAndGIControls = emissionScaleUI.floatValue > 0f;
bool showEmissionColorAndGIControlsTop = emissionScaleUITop.floatValue > 0f;
bool showEmissionColorAndGIControlsBottom = emissionScaleUIBottom.floatValue > 0f;
// Do controls
m_MaterialEditor.TexturePropertySingleLine(Styles.emissionText, emissionMap, showEmissionColorAndGIControls ? emissionColorUI : null, emissionScaleUI);
if (material.GetFloat ("_TopMultiplier") > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.emissionTextTop, emissionMapTop, showEmissionColorAndGIControlsTop ? emissionColorUITop : null, emissionScaleUITop);
}
if (material.GetFloat("_BottomMultiplier") > MIN_VALUE)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.emissionTextBottom, emissionMapBottom, showEmissionColorAndGIControlsBottom ? emissionColorUIBottom : null, emissionScaleUIBottom);
}
// Dynamic Lightmapping mode
if (showEmissionColorAndGIControls)
{
bool shouldEmissionBeEnabled = ShouldEmissionBeEnabled(EvalFinalEmissionColor(material));
EditorGUI.BeginDisabledGroup(!shouldEmissionBeEnabled);
m_MaterialEditor.LightmapEmissionProperty (MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1);
EditorGUI.EndDisabledGroup();
}
}
void DoSpecularMetallicArea(Material material)
{
if (m_WorkflowMode == WorkflowMode.Specular)
{
GUILayout.Label(Styles.specularLabel, EditorStyles.boldLabel);
// MAIN
if (specularMap.textureValue == null)
{
m_MaterialEditor.TexturePropertyTwoLines(Styles.specularMapText, specularMap, specularColor, Styles.smoothnessText, smoothness);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.specularMapText, specularMap);
}
// TOP
if (topMultiplier.floatValue > MIN_VALUE)
{
if (specularMapTop.textureValue == null)
{
m_MaterialEditor.TexturePropertyTwoLines(Styles.specularMapTextTop, specularMapTop, specularColorTop, Styles.smoothnessTextTop, smoothnessTop);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.specularMapTextTop, specularMapTop);
}
}
// BOTTOM
if (bottomMultiplier.floatValue > MIN_VALUE)
{
if (specularMapBottom.textureValue == null)
{
m_MaterialEditor.TexturePropertyTwoLines(Styles.specularMapTextBottom, specularMapBottom, specularColorBottom, Styles.smoothnessTextBottom, smoothnessBottom);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.specularMapTextBottom, specularMapBottom);
}
}
}
else if (m_WorkflowMode == WorkflowMode.Metallic)
{
GUILayout.Label(Styles.metallicLabel, EditorStyles.boldLabel);
// MAIN
if (metallicMap.textureValue == null)
{
m_MaterialEditor.TexturePropertyTwoLines(Styles.metallicMapText, metallicMap, metallic, Styles.smoothnessText, smoothness);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.metallicMapText, metallicMap);
}
// TOP
if (topMultiplier.floatValue > MIN_VALUE)
{
if (metallicMapTop.textureValue == null)
{
m_MaterialEditor.TexturePropertyTwoLines(Styles.metallicMapTextTop, metallicMapTop, metallicTop, Styles.smoothnessTextTop, smoothnessTop);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.metallicMapTextTop, metallicMapTop);
}
}
// BOTTOM
if (bottomMultiplier.floatValue > MIN_VALUE)
{
if (metallicMapBottom.textureValue == null)
{
m_MaterialEditor.TexturePropertyTwoLines(Styles.metallicMapTextBottom, metallicMapBottom, metallicBottom, Styles.smoothnessTextBottom, smoothnessBottom);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.metallicMapTextBottom, metallicMapBottom);
}
}
}
}
// Calculate final HDR _EmissionColor (gamma space) from _EmissionColorUI (LDR, gamma) & _EmissionScaleUI (gamma)
static Color EvalFinalEmissionColor(Material material)
{
return material.GetColor("_EmissionColorUI") * material.GetFloat("_EmissionScaleUI");
}
static Color EvalFinalEmissionColorTop(Material material)
{
return material.GetColor("_TopEmissionColorUI") * material.GetFloat("_TopEmissionScaleUI");
}
static Color EvalFinalEmissionColorBottom(Material material)
{
return material.GetColor("_BottomEmissionColorUI") * material.GetFloat("_BottomEmissionScaleUI");
}
static bool ShouldEmissionBeEnabled (Color color)
{
return color.grayscale > (0.1f / 255.0f);
}
static void SetMaterialKeywords(Material material, WorkflowMode workflowMode)
{
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
// (MaterialProperty value might come from renderer material property block)
if (workflowMode == WorkflowMode.Specular)
{
SetKeyword (material, "_SPECGLOSSMAP",
material.GetTexture ("_SpecGlossMap") ||
material.GetTexture ("_TopSpecGlossMap") ||
material.GetTexture ("_BottomSpecGlossMap")
);
}
else if (workflowMode == WorkflowMode.Metallic)
{
SetKeyword (material, "_METALLICGLOSSMAP",
material.GetTexture ("_MetallicGlossMap") ||
material.GetTexture ("_TopMetallicGlossMap") ||
material.GetTexture ("_BottomMetallicGlossMap")
);
}
bool shouldEmissionBeEnabled =
ShouldEmissionBeEnabled (material.GetColor("_EmissionColor"))
|| (material.HasProperty ("_TopMultiplier") && material.GetFloat ("_TopMultiplier") > MIN_VALUE && ShouldEmissionBeEnabled (material.GetColor("_TopEmissionColor")))
|| (material.HasProperty ("_BottomMultiplier") && material.GetFloat ("_BottomMultiplier") > MIN_VALUE && ShouldEmissionBeEnabled (material.GetColor("_BottomEmissionColor")));
SetKeyword (material, "_EMISSION", shouldEmissionBeEnabled);
// Triplanar texture space
SetKeyword(material, "_UVFREE_LOCAL", material.GetFloat ("_TriplanarSpace") == (float) Space.Self);
// whether the bottom is enabled
SetKeyword(material, "_UVFREE_BOTTOM", material.GetFloat ("_BottomMultiplier") > (0.1f / 255.0f));
// Setup lightmap emissive flags
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
{
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
if (!shouldEmissionBeEnabled)
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
material.globalIlluminationFlags = flags;
}
}
bool HasValidEmissiveKeyword (Material material)
{
// Material animation might be out of sync with the material keyword.
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
bool hasEmissionKeyword = material.IsKeywordEnabled ("_EMISSION");
if (!hasEmissionKeyword && ShouldEmissionBeEnabled (emissionColorForRendering.colorValue))
return false;
else
return true;
}
static void MaterialChanged(Material material, WorkflowMode workflowMode)
{
// clamp texture power
float tTexPower = material.GetFloat("_TexPower");
if (tTexPower < 0.0f || tTexPower > 20.0f)
{
material.SetFloat ("_TexPower", Mathf.Clamp (tTexPower, 0.0f, 20.0f));
}
// clamp top multiplier
float tTopMultiplier = material.GetFloat ("_TopMultiplier");
if (tTopMultiplier < 0.0f || tTopMultiplier > 8.0f)
{
material.SetFloat ("_TopMultiplier", Mathf.Clamp (tTopMultiplier, 0.0f, 8.0f));
}
// clamp bottom multiplier
float tBottomMultiplier = material.GetFloat ("_BottomMultiplier");
if (tBottomMultiplier < 0.0f || tBottomMultiplier > 8.0f)
{
material.SetFloat ("_BottomMultiplier", Mathf.Clamp (tBottomMultiplier, 0.0f, 8.0f));
}
// Clamp EmissionScale to always positive
if (material.GetFloat("_EmissionScaleUI") < 0.0f)
material.SetFloat("_EmissionScaleUI", 0.0f);
// Apply combined emission value
Color emissionColorOut = EvalFinalEmissionColor (material);
material.SetColor("_EmissionColor", emissionColorOut);
// TOP
if (material.GetFloat("_TopEmissionScaleUI") < 0.0f)
material.SetFloat("_TopEmissionScaleUI", 0.0f);
Color emissionColorOutTop = EvalFinalEmissionColorTop (material);
material.SetColor("_TopEmissionColor", emissionColorOutTop);
// BOTTOM
if (material.GetFloat("_BottomEmissionScaleUI") < 0.0f)
material.SetFloat("_BottomEmissionScaleUI", 0.0f);
Color emissionColorOutBottom = EvalFinalEmissionColorBottom (material);
material.SetColor("_BottomEmissionColor", emissionColorOutBottom);
if (workflowMode == WorkflowMode.Metallic)
{
material.SetFloat ("_UsingMetallicGlossMap", (material.GetTexture ("_MetallicGlossMap") == null) ? 0.0f : 1.0f);
material.SetFloat ("_TopUsingMetallicGlossMap", (material.GetTexture ("_TopMetallicGlossMap") == null) ? 0.0f : 1.0f);
material.SetFloat ("_BottomUsingMetallicGlossMap", (material.GetTexture ("_BottomMetallicGlossMap") == null) ? 0.0f : 1.0f);
}
else if (workflowMode == WorkflowMode.Specular)
{
material.SetFloat ("_UsingSpecGlossMap", (material.GetTexture ("_SpecGlossMap") == null) ? 0.0f : 1.0f);
material.SetFloat ("_TopUsingSpecGlossMap", (material.GetTexture ("_TopSpecGlossMap") == null) ? 0.0f : 1.0f);
material.SetFloat ("_BottomUsingSpecGlossMap", (material.GetTexture ("_BottomSpecGlossMap") == null) ? 0.0f : 1.0f);
}
SetMaterialKeywords(material, workflowMode);
}
static void SetKeyword(Material m, string keyword, bool state)
{
//Debug.Log(keyword + ": " + state);
if (state)
m.EnableKeyword (keyword);
else
m.DisableKeyword (keyword);
}
}
} // namespace UnityEditor
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e75eae9587d2c4f48a9afb816677fcaf
timeCreated: 1426888738
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8c6bfcef2393f4ec6a3488b8d23570a4
folderAsset: yes
timeCreated: 1427422582
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,270 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/UVFree/Terrain/StandardMetallic-AddPass" {
Properties {
_TexPower("Texture Power", Range (0.0, 20.0)) = 10.0
_UVScale("Texture Scale %", Float) = 100.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
// set by terrain engine
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
[HideInInspector] [Gamma] _Metallic0 ("Metallic 0", Range(0.0, 1.0)) = 0.0
[HideInInspector] [Gamma] _Metallic1 ("Metallic 1", Range(0.0, 1.0)) = 0.0
[HideInInspector] [Gamma] _Metallic2 ("Metallic 2", Range(0.0, 1.0)) = 0.0
[HideInInspector] [Gamma] _Metallic3 ("Metallic 3", Range(0.0, 1.0)) = 0.0
[HideInInspector] _Smoothness0 ("Smoothness 0", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness1 ("Smoothness 1", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness2 ("Smoothness 2", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness3 ("Smoothness 3", Range(0.0, 1.0)) = 1.0
}
SubShader {
Tags {
"SplatCount" = "4"
"Queue" = "Geometry-99"
"IgnoreProjector"="True"
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf Standard decal:add vertex:SplatmapVert finalcolor:SplatmapFinalColor fullforwardshadows
#define TERRAIN_SURFACE_OUTPUT SurfaceOutputStandard
#pragma multi_compile_fog
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
#include "UnityPBSLighting.cginc"
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
#define TERRAIN_SPLAT_ADDPASS
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
sampler2D _Control;
float4 _Control_ST;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
#ifdef _TERRAIN_NORMAL_MAP
sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
#endif
fixed _Metallic0, _Metallic1, _Metallic2, _Metallic3;
fixed _Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3;
half _TexPower;
half _BumpScale;
float _UVScale;
struct Input
{
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
float2 tc_Control : TEXCOORD4; // Not prefixing '_Control' with 'uv' allows a tighter packing of interpolators, which is necessary to support directional lightmap.
UNITY_FOG_COORDS(5)
};
void SplatmapVert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
fixed3 powerNormal = pow(abs(worldNormal), clamp(_TexPower,0.0, 20.0));
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, half3(1.0,1.0,1.0));
o.powerNormal = powerNormal;
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (powerNormal.x))
+ (-(worldNormal.y) * (powerNormal.y))
+ (-(worldNormal.z) * (powerNormal.z))
;
// Need to manually transform uv here,
// as we choose not to use 'uv' prefix for this texcoord.
o.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);
float4 pos = UnityObjectToClipPos (v.vertex);
UNITY_TRANSFER_FOG(o, pos);
}
void surf (Input IN, inout SurfaceOutputStandard o) {
// world space positions along the axis planes
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
float2 xUV = float2(powerSign.x, 1.0);
float2 zUV = float2(powerSign.z, 1.0);
float2 yUV = float2(1.0, powerSign.y);
#else
float2 xUV = float2(1.0, 1.0);
float2 zUV = xUV;
float2 yUV = xUV;
#endif
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
splat_control = tex2D(_Control, IN.tc_Control);
weight = dot(splat_control, half4(1.0,1.0,1.0,1.0));
#ifndef UNITY_PASS_DEFERRED
splat_control /= (weight + 1e-3f); // avoid NaNs in splat_control
#endif
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS)
clip(weight - 0.0039);
#endif
fixed4 texX0 = tex2D(_Splat0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale);
fixed4 texY0 = tex2D(_Splat0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale);
fixed4 texZ0 = tex2D(_Splat0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale);
fixed4 texX1 = tex2D(_Splat1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale);
fixed4 texY1 = tex2D(_Splat1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale);
fixed4 texZ1 = tex2D(_Splat1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale);
fixed4 texX2 = tex2D(_Splat2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale);
fixed4 texY2 = tex2D(_Splat2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale);
fixed4 texZ2 = tex2D(_Splat2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale);
fixed4 texX3 = tex2D(_Splat3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale);
fixed4 texY3 = tex2D(_Splat3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale);
fixed4 texZ3 = tex2D(_Splat3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale);
fixed4 tex0 =
+ texX0 * IN.powerNormal.x
+ texY0 * IN.powerNormal.y
+ texZ0 * IN.powerNormal.z;
fixed4 tex1 =
+ texX1 * IN.powerNormal.x
+ texY1 * IN.powerNormal.y
+ texZ1 * IN.powerNormal.z;
fixed4 tex2 =
+ texX2 * IN.powerNormal.x
+ texY2 * IN.powerNormal.y
+ texZ2 * IN.powerNormal.z;
fixed4 tex3 =
+ texX3 * IN.powerNormal.x
+ texY3 * IN.powerNormal.y
+ texZ3 * IN.powerNormal.z;
mixedDiffuse = 0.0f;
mixedDiffuse += splat_control.r * tex0 * fixed4(1.0, 1.0, 1.0, _Smoothness0);
mixedDiffuse += splat_control.g * tex1 * fixed4(1.0, 1.0, 1.0, _Smoothness1);
mixedDiffuse += splat_control.b * tex2 * fixed4(1.0, 1.0, 1.0, _Smoothness2);
mixedDiffuse += splat_control.a * tex3 * fixed4(1.0, 1.0, 1.0, _Smoothness3);
#ifdef _TERRAIN_NORMAL_MAP
// NORMAL
//
fixed4 flatNormal = fixed4(0.5,0.5,1.0,0.5); // this is "flat normal" in both DXT5nm and xyz*2-1 cases
fixed4 bumpX0 = tex2D(_Normal0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY0 = tex2D(_Normal0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ0 = tex2D(_Normal0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX1 = tex2D(_Normal1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY1 = tex2D(_Normal1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ1 = tex2D(_Normal1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX2 = tex2D(_Normal2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY2 = tex2D(_Normal2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ2 = tex2D(_Normal2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX3 = tex2D(_Normal3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY3 = tex2D(_Normal3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ3 = tex2D(_Normal3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bump0 =
+ bumpX0 * IN.powerNormal.x
+ bumpY0 * IN.powerNormal.y
+ bumpZ0 * IN.powerNormal.z;
fixed4 bump1 =
+ bumpX1 * IN.powerNormal.x
+ bumpY1 * IN.powerNormal.y
+ bumpZ1 * IN.powerNormal.z;
fixed4 bump2 =
+ bumpX2 * IN.powerNormal.x
+ bumpY2 * IN.powerNormal.y
+ bumpZ2 * IN.powerNormal.z;
fixed4 bump3 =
+ bumpX3 * IN.powerNormal.x
+ bumpY3 * IN.powerNormal.y
+ bumpZ3 * IN.powerNormal.z;
fixed4 bump =
splat_control.r * bump0
+ splat_control.g * bump1
+ splat_control.b * bump2
+ splat_control.a * bump3;
bump *= _BumpScale;
bump += flatNormal;
o.Normal = UnpackNormal(bump);
#endif
o.Albedo = max(fixed3(0.0, 0.0, 0.0), mixedDiffuse.rgb);
o.Alpha = weight;
o.Smoothness = mixedDiffuse.a;
o.Metallic = dot(splat_control, fixed4(_Metallic0, _Metallic1, _Metallic2, _Metallic3));
}
void SplatmapFinalColor(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 color)
{
color *= o.Alpha;
#ifdef TERRAIN_SPLAT_ADDPASS
UNITY_APPLY_FOG_COLOR(IN.fogCoord, color, fixed4(0,0,0,0));
#else
UNITY_APPLY_FOG(IN.fogCoord, color);
#endif
}
ENDCG
}
Fallback "Hidden/TerrainEngine/Splatmap/Diffuse-AddPass"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6dc7a16b4568245d7a2e347fc55d6bda
timeCreated: 1427271118
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,44 @@
Shader "Hidden/UVFree/Terrain/StandardMetallic-Base" {
Properties {
_MainTex ("Base (RGB) Smoothness (A)", 2D) = "white" {}
_SpecularMetallicTex ("Specular (RGB) Metallic (A)", 2D) = "white" {}
// used in fallback on old cards
_Color ("Main Color", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
Tags {
"RenderType" = "Opaque"
"Queue" = "Geometry-100"
}
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
#include "UnityPBSLighting.cginc"
sampler2D _MainTex;
sampler2D _SpecularMetallicTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutputStandard o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = max(fixed3(0.001, 0.001, 0.001), c.rgb);
o.Alpha = 1.0;
o.Smoothness = c.a;
o.Metallic = tex2D (_SpecularMetallicTex, IN.uv_MainTex).a;
}
ENDCG
}
FallBack "Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b724fb8949ace4d76ad2f6462bcac5f6
timeCreated: 1427271122
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,274 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UVFree/Terrain/StandardMetallic" {
Properties {
_TexPower("Texture Power", Range (0.0, 20.0)) = 10.0
_UVScale("Texture Scale %", Float) = 100.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
// set by terrain engine
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
[HideInInspector] [Gamma] _Metallic0 ("Metallic 0", Range(0.0, 1.0)) = 0.0
[HideInInspector] [Gamma] _Metallic1 ("Metallic 1", Range(0.0, 1.0)) = 0.0
[HideInInspector] [Gamma] _Metallic2 ("Metallic 2", Range(0.0, 1.0)) = 0.0
[HideInInspector] [Gamma] _Metallic3 ("Metallic 3", Range(0.0, 1.0)) = 0.0
[HideInInspector] _Smoothness0 ("Smoothness 0", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness1 ("Smoothness 1", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness2 ("Smoothness 2", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness3 ("Smoothness 3", Range(0.0, 1.0)) = 1.0
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
Tags {
"SplatCount" = "4"
"Queue" = "Geometry-100"
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf Standard vertex:SplatmapVert finalcolor:SplatmapFinalColor fullforwardshadows
#define TERRAIN_SURFACE_OUTPUT SurfaceOutputStandard
#pragma multi_compile_fog
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
#include "UnityPBSLighting.cginc"
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
sampler2D _Control;
float4 _Control_ST;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
#ifdef _TERRAIN_NORMAL_MAP
sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
#endif
fixed _Metallic0, _Metallic1, _Metallic2, _Metallic3;
fixed _Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3;
half _TexPower;
half _BumpScale;
float _UVScale;
struct Input
{
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
float2 tc_Control : TEXCOORD4; // Not prefixing '_Control' with 'uv' allows a tighter packing of interpolators, which is necessary to support directional lightmap.
UNITY_FOG_COORDS(5)
};
void SplatmapVert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
fixed3 powerNormal = pow(abs(worldNormal), clamp(_TexPower,0.0, 20.0));
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, half3(1.0,1.0,1.0));
o.powerNormal = powerNormal;
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (powerNormal.x))
+ (-(worldNormal.y) * (powerNormal.y))
+ (-(worldNormal.z) * (powerNormal.z))
;
// Need to manually transform uv here,
// as we choose not to use 'uv' prefix for this texcoord.
o.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);
float4 pos = UnityObjectToClipPos (v.vertex);
UNITY_TRANSFER_FOG(o, pos);
}
void surf (Input IN, inout SurfaceOutputStandard o) {
// world space positions along the axis planes
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
float2 xUV = float2(powerSign.x, 1.0);
float2 zUV = float2(powerSign.z, 1.0);
float2 yUV = float2(1.0, powerSign.y);
#else
float2 xUV = float2(1.0, 1.0);
float2 zUV = xUV;
float2 yUV = xUV;
#endif
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
splat_control = tex2D(_Control, IN.tc_Control);
weight = dot(splat_control, half4(1.0,1.0,1.0,1.0));
#ifndef UNITY_PASS_DEFERRED
splat_control /= (weight + 1e-3f); // avoid NaNs in splat_control
#endif
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS)
clip(weight - 0.0039);
#endif
fixed4 texX0 = tex2D(_Splat0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale);
fixed4 texY0 = tex2D(_Splat0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale);
fixed4 texZ0 = tex2D(_Splat0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale);
fixed4 texX1 = tex2D(_Splat1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale);
fixed4 texY1 = tex2D(_Splat1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale);
fixed4 texZ1 = tex2D(_Splat1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale);
fixed4 texX2 = tex2D(_Splat2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale);
fixed4 texY2 = tex2D(_Splat2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale);
fixed4 texZ2 = tex2D(_Splat2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale);
fixed4 texX3 = tex2D(_Splat3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale);
fixed4 texY3 = tex2D(_Splat3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale);
fixed4 texZ3 = tex2D(_Splat3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale);
fixed4 tex0 =
+ texX0 * IN.powerNormal.x
+ texY0 * IN.powerNormal.y
+ texZ0 * IN.powerNormal.z;
fixed4 tex1 =
+ texX1 * IN.powerNormal.x
+ texY1 * IN.powerNormal.y
+ texZ1 * IN.powerNormal.z;
fixed4 tex2 =
+ texX2 * IN.powerNormal.x
+ texY2 * IN.powerNormal.y
+ texZ2 * IN.powerNormal.z;
fixed4 tex3 =
+ texX3 * IN.powerNormal.x
+ texY3 * IN.powerNormal.y
+ texZ3 * IN.powerNormal.z;
mixedDiffuse = 0.0f;
mixedDiffuse += splat_control.r * tex0 * fixed4(1.0, 1.0, 1.0, _Smoothness0);
mixedDiffuse += splat_control.g * tex1 * fixed4(1.0, 1.0, 1.0, _Smoothness1);
mixedDiffuse += splat_control.b * tex2 * fixed4(1.0, 1.0, 1.0, _Smoothness2);
mixedDiffuse += splat_control.a * tex3 * fixed4(1.0, 1.0, 1.0, _Smoothness3);
#ifdef _TERRAIN_NORMAL_MAP
// NORMAL
//
fixed4 flatNormal = fixed4(0.5,0.5,1.0,0.5); // this is "flat normal" in both DXT5nm and xyz*2-1 cases
fixed4 bumpX0 = tex2D(_Normal0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY0 = tex2D(_Normal0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ0 = tex2D(_Normal0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX1 = tex2D(_Normal1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY1 = tex2D(_Normal1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ1 = tex2D(_Normal1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX2 = tex2D(_Normal2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY2 = tex2D(_Normal2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ2 = tex2D(_Normal2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX3 = tex2D(_Normal3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY3 = tex2D(_Normal3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ3 = tex2D(_Normal3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bump0 =
+ bumpX0 * IN.powerNormal.x
+ bumpY0 * IN.powerNormal.y
+ bumpZ0 * IN.powerNormal.z;
fixed4 bump1 =
+ bumpX1 * IN.powerNormal.x
+ bumpY1 * IN.powerNormal.y
+ bumpZ1 * IN.powerNormal.z;
fixed4 bump2 =
+ bumpX2 * IN.powerNormal.x
+ bumpY2 * IN.powerNormal.y
+ bumpZ2 * IN.powerNormal.z;
fixed4 bump3 =
+ bumpX3 * IN.powerNormal.x
+ bumpY3 * IN.powerNormal.y
+ bumpZ3 * IN.powerNormal.z;
fixed4 bump =
splat_control.r * bump0
+ splat_control.g * bump1
+ splat_control.b * bump2
+ splat_control.a * bump3;
bump *= _BumpScale;
bump += flatNormal;
o.Normal = UnpackNormal(bump);
#endif
o.Albedo = max(fixed3(0.0, 0.0, 0.0), mixedDiffuse.rgb);
o.Alpha = weight;
o.Smoothness = mixedDiffuse.a;
o.Metallic = dot(splat_control, fixed4(_Metallic0, _Metallic1, _Metallic2, _Metallic3));
}
void SplatmapFinalColor(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 color)
{
color *= o.Alpha;
#ifdef TERRAIN_SPLAT_ADDPASS
UNITY_APPLY_FOG_COLOR(IN.fogCoord, color, fixed4(0,0,0,0));
#else
UNITY_APPLY_FOG(IN.fogCoord, color);
#endif
}
ENDCG
}
Dependency "AddPassShader" = "Hidden/UVFree/Terrain/StandardMetallic-AddPass"
Dependency "BaseMapShader" = "Hidden/UVFree/Terrain/StandardMetallic-Base"
Fallback "Nature/Terrain/Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9d90a5ae4faf244fd9a8b99d09f9fb66
timeCreated: 1427271121
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 201510bf05cc74dfe81ed20049849908
folderAsset: yes
timeCreated: 1426831325
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,414 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
// Use the non-batching version of this shader if you are using
// local mode, and are seeing the textures move when you zoom in
// due to dynamic batching. (Dynamic batching converts local vertex
// data into world space, making local vertex position data unavailable
// to the shader.)
Shader "UVFree/StandardMetallic/Single-Texture" {
Properties {
// Triplanar space, for UI
[HideInInspector] _TriplanarSpace("Triplanar Space", Float) = 0.0
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_Color ("Color", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 1.0
_Glossiness ("Smoothness", Range(0.0,1.0)) = 0.5
[Gamma] _Metallic ("Metallic", Range(0.0,1.0)) = 0.0
_MetallicGlossMap("Metallic", 2D) = "black" {}
_UsingMetallicGlossMap("Using Metallic Gloss Map", float) = 0.0
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
_BumpScale("Bump 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("Occlusion Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
_EmissionColor("Emission Color", Color) = (0.0,0.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" {}
// UI-only data
[HideInInspector] _EmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _EmissionColorUI("Color", Color) = (1.0,1.0,1.0)
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
}
LOD 300
CGPROGRAM
#pragma target 3.0
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard vertex:vert fullforwardshadows nodynlightmap
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _DETAIL
#pragma shader_feature _OCCLUSION
#pragma shader_feature _PARALLAXMAP
#pragma shader_feature _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature _GLOSSYREFLECTIONS_OFF
#include "UnityCG.cginc"
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
// Comment out following line to omit vertex colors
#define _UVFREE_VERTEX_COLOR
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
half _TexPower;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
fixed _Metallic;
fixed _Glossiness;
#ifdef _DETAIL
sampler2D _DetailAlbedoMap;
float4 _DetailAlbedoMap_ST;
sampler2D _DetailMask;
sampler2D _DetailNormalMap;
half _DetailNormalMapScale;
#endif
#ifdef _METALLICGLOSSMAP
sampler2D _MetallicGlossMap;
fixed _UsingMetallicGlossMap;
#endif
#ifdef _OCCLUSION
sampler2D _OcclusionMap;
fixed _OcclusionStrength;
#endif
#ifdef _PARALLAXMAP
sampler2D _ParallaxMap;
half _Parallax;
#endif
#ifdef _EMISSION
sampler2D _EmissionMap;
half4 _EmissionColor;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed _VertexColorStrength;
#endif
struct Input {
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
fixed3 viewDirForParallax;
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = v.normal;
#endif
o.powerNormal = pow(abs(v.normal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (o.powerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (o.powerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (o.powerNormal.z)
;
v.tangent.w =
(-(v.normal.x) * (o.powerNormal.x))
+ (-(v.normal.y) * (o.powerNormal.y))
+ (-(v.normal.z) * (o.powerNormal.z))
;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
o.powerNormal = pow(abs(worldNormal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (o.powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (o.powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (o.powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (o.powerNormal.x))
+ (-(worldNormal.y) * (o.powerNormal.y))
+ (-(worldNormal.z) * (o.powerNormal.z))
;
#endif
#ifdef _PARALLAXMAP
TANGENT_SPACE_ROTATION;
o.viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex));
#endif
}
void surf (Input IN, inout SurfaceOutputStandard o) {
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float3 pos = IN.worldPos;
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
#endif
// PARALLAX
//
#ifdef _PARALLAXMAP
half parallaxX = tex2D (_ParallaxMap, xUV).r;
half parallaxY = tex2D (_ParallaxMap, yUV).g;
half parallaxZ = tex2D (_ParallaxMap, zUV).b;
half parallax =
parallaxX * IN.powerNormal.x
+ parallaxY * IN.powerNormal.y
+ parallaxZ * IN.powerNormal.z
;
float2 parallaxOffset = ParallaxOffset (parallax, _Parallax, IN.viewDirForParallax);
xUV += parallaxOffset;
yUV += parallaxOffset;
zUV += parallaxOffset;
#endif
// DIFFUSE
//
fixed4 texX = tex2D(_MainTex, xUV);
fixed4 texY = tex2D(_MainTex, yUV);
fixed4 texZ = tex2D(_MainTex, zUV);
fixed4 tex =
texX * IN.powerNormal.x
+ texY * IN.powerNormal.y
+ texZ * IN.powerNormal.z;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
fixed3 albedo = max(fixed3(0.0, 0.0, 0.0), tex.rgb * tint.rgb);
// DIFFUSE DETAIL
//
#ifdef _DETAIL
fixed detailMaskX = tex2D(_DetailMask, xUV).a;
fixed detailMaskY = tex2D(_DetailMask, yUV).a;
fixed detailMaskZ = tex2D(_DetailMask, zUV).a;
fixed detailMask =
detailMaskX * IN.powerNormal.x
+ detailMaskY * IN.powerNormal.y
+ detailMaskZ * IN.powerNormal.z;
float2 xUVDetail = pos.zy * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
float2 yUVDetail = pos.xz * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
float2 zUVDetail = float2(-pos.x, pos.y) * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
xUVDetail.x *= powerSign.x;
zUVDetail.x *= powerSign.z;
yUVDetail.y *= powerSign.y;
#endif
#ifdef _PARALLAXMAP
xUVDetail += parallaxOffset;
yUVDetail += parallaxOffset;
zUVDetail += parallaxOffset;
#endif
fixed3 detailAlbedoX = tex2D (_DetailAlbedoMap, xUVDetail).rgb;
fixed3 detailAlbedoY = tex2D (_DetailAlbedoMap, yUVDetail).rgb;
fixed3 detailAlbedoZ = tex2D (_DetailAlbedoMap, zUVDetail).rgb;
fixed3 detailAlbedo =
detailAlbedoX * IN.powerNormal.x
+ detailAlbedoY * IN.powerNormal.y
+ detailAlbedoZ * IN.powerNormal.z;
albedo *= LerpWhiteTo (detailAlbedo * unity_ColorSpaceDouble.rgb, detailMask);
#endif
o.Albedo = albedo;
o.Alpha = tex.a * tint.a;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bump =
bumpX * IN.powerNormal.x
+ bumpY * IN.powerNormal.y
+ bumpZ * IN.powerNormal.z
;
// NORMAL DETAIL
//
#ifdef _DETAIL
fixed3 detailNormalTangentX = UnpackScaleNormal(tex2D (_DetailNormalMap, xUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangentY = UnpackScaleNormal(tex2D (_DetailNormalMap, yUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangentZ = UnpackScaleNormal(tex2D (_DetailNormalMap, zUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangent =
detailNormalTangentX * IN.powerNormal.x
+ detailNormalTangentY * IN.powerNormal.y
+ detailNormalTangentZ * IN.powerNormal.z;
bump = lerp(
bump,
BlendNormals(bump, detailNormalTangent),
detailMask);
#endif
o.Normal = normalize(bump);
// METALLIC/GLOSS
//
fixed2 mg = fixed2(
_Metallic,
_Glossiness
);
#ifdef _METALLICGLOSSMAP
fixed2 mgX = lerp(mg, tex2D(_MetallicGlossMap, xUV).ra, _UsingMetallicGlossMap);
fixed2 mgY = lerp(mg, tex2D(_MetallicGlossMap, yUV).ra, _UsingMetallicGlossMap);
fixed2 mgZ = lerp(mg, tex2D(_MetallicGlossMap, zUV).ra, _UsingMetallicGlossMap);
mg =
mgX * IN.powerNormal.x
+ mgY * IN.powerNormal.y
+ mgZ * IN.powerNormal.z;
#endif
o.Metallic = mg.x;
o.Smoothness = mg.y;
// EMISSION
//
#ifndef _EMISSION
o.Emission = 0.0;
#else
fixed3 emissionX = tex2D(_EmissionMap, xUV).rgb;
fixed3 emissionY = tex2D(_EmissionMap, yUV).rgb;
fixed3 emissionZ = tex2D(_EmissionMap, zUV).rgb;
o.Emission = (emissionX * IN.powerNormal.x + emissionY * IN.powerNormal.y + emissionZ * IN.powerNormal.z)
* _EmissionColor.rgb;
#endif
// OCCLUSION
//
#ifdef _OCCLUSION
fixed occX = tex2D(_OcclusionMap, xUV).g;
fixed occY = tex2D(_OcclusionMap, yUV).g;
fixed occZ = tex2D(_OcclusionMap, zUV).g;
o.Occlusion = LerpOneTo(
(occX * IN.powerNormal.x + occY * IN.powerNormal.y + occZ * IN.powerNormal.z),
_OcclusionStrength);
#else
o.Occlusion = 1.0;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreePBRShaderGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b3ac26fce65714bddabaf5a2562d109a
timeCreated: 1426794833
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,409 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
Shader "UVFree/StandardMetallic/Single-Texture Non-Batched" {
Properties {
// Triplanar space, for UI
[HideInInspector] _TriplanarSpace("Triplanar Space", Float) = 0.0
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_Color ("Color", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 1.0
_Glossiness ("Smoothness", Range(0.0,1.0)) = 0.5
[Gamma] _Metallic ("Metallic", Range(0.0,1.0)) = 0.0
_MetallicGlossMap("Metallic", 2D) = "black" {}
_UsingMetallicGlossMap("Using Metallic Gloss Map", float) = 0.0
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
_BumpScale("Bump 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("Occlusion Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
_EmissionColor("Emission Color", Color) = (0.0,0.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" {}
// UI-only data
[HideInInspector] _EmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _EmissionColorUI("Color", Color) = (1.0,1.0,1.0)
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
"DisableBatching"="True"
}
LOD 300
CGPROGRAM
#pragma target 3.0
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard vertex:vert fullforwardshadows nodynlightmap
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _DETAIL
#pragma shader_feature _OCCLUSION
#pragma shader_feature _PARALLAXMAP
#pragma shader_feature _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature _GLOSSYREFLECTIONS_OFF
#include "UnityCG.cginc"
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
// Comment out following line to omit vertex colors
#define _UVFREE_VERTEX_COLOR
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
half _TexPower;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
fixed _Metallic;
fixed _Glossiness;
#ifdef _DETAIL
sampler2D _DetailAlbedoMap;
float4 _DetailAlbedoMap_ST;
sampler2D _DetailMask;
sampler2D _DetailNormalMap;
half _DetailNormalMapScale;
#endif
#ifdef _METALLICGLOSSMAP
sampler2D _MetallicGlossMap;
fixed _UsingMetallicGlossMap;
#endif
#ifdef _OCCLUSION
sampler2D _OcclusionMap;
fixed _OcclusionStrength;
#endif
#ifdef _PARALLAXMAP
sampler2D _ParallaxMap;
half _Parallax;
#endif
#ifdef _EMISSION
sampler2D _EmissionMap;
half4 _EmissionColor;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed _VertexColorStrength;
#endif
struct Input {
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
fixed3 viewDirForParallax;
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = v.normal;
#endif
o.powerNormal = pow(abs(v.normal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (o.powerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (o.powerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (o.powerNormal.z)
;
v.tangent.w =
(-(v.normal.x) * (o.powerNormal.x))
+ (-(v.normal.y) * (o.powerNormal.y))
+ (-(v.normal.z) * (o.powerNormal.z))
;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
o.powerNormal = pow(abs(worldNormal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (o.powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (o.powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (o.powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (o.powerNormal.x))
+ (-(worldNormal.y) * (o.powerNormal.y))
+ (-(worldNormal.z) * (o.powerNormal.z))
;
#endif
#ifdef _PARALLAXMAP
TANGENT_SPACE_ROTATION;
o.viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex));
#endif
}
void surf (Input IN, inout SurfaceOutputStandard o) {
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float3 pos = IN.worldPos;
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
#endif
// PARALLAX
//
#ifdef _PARALLAXMAP
half parallaxX = tex2D (_ParallaxMap, xUV).r;
half parallaxY = tex2D (_ParallaxMap, yUV).g;
half parallaxZ = tex2D (_ParallaxMap, zUV).b;
half parallax =
parallaxX * IN.powerNormal.x
+ parallaxY * IN.powerNormal.y
+ parallaxZ * IN.powerNormal.z
;
float2 parallaxOffset = ParallaxOffset (parallax, _Parallax, IN.viewDirForParallax);
xUV += parallaxOffset;
yUV += parallaxOffset;
zUV += parallaxOffset;
#endif
// DIFFUSE
//
fixed4 texX = tex2D(_MainTex, xUV);
fixed4 texY = tex2D(_MainTex, yUV);
fixed4 texZ = tex2D(_MainTex, zUV);
fixed4 tex =
texX * IN.powerNormal.x
+ texY * IN.powerNormal.y
+ texZ * IN.powerNormal.z;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
fixed3 albedo = max(fixed3(0.0, 0.0, 0.0), tex.rgb * tint.rgb);
// DIFFUSE DETAIL
//
#ifdef _DETAIL
fixed detailMaskX = tex2D(_DetailMask, xUV).a;
fixed detailMaskY = tex2D(_DetailMask, yUV).a;
fixed detailMaskZ = tex2D(_DetailMask, zUV).a;
fixed detailMask =
detailMaskX * IN.powerNormal.x
+ detailMaskY * IN.powerNormal.y
+ detailMaskZ * IN.powerNormal.z;
float2 xUVDetail = pos.zy * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
float2 yUVDetail = pos.xz * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
float2 zUVDetail = float2(-pos.x, pos.y) * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
xUVDetail.x *= powerSign.x;
zUVDetail.x *= powerSign.z;
yUVDetail.y *= powerSign.y;
#endif
#ifdef _PARALLAXMAP
xUVDetail += parallaxOffset;
yUVDetail += parallaxOffset;
zUVDetail += parallaxOffset;
#endif
fixed3 detailAlbedoX = tex2D (_DetailAlbedoMap, xUVDetail).rgb;
fixed3 detailAlbedoY = tex2D (_DetailAlbedoMap, yUVDetail).rgb;
fixed3 detailAlbedoZ = tex2D (_DetailAlbedoMap, zUVDetail).rgb;
fixed3 detailAlbedo =
detailAlbedoX * IN.powerNormal.x
+ detailAlbedoY * IN.powerNormal.y
+ detailAlbedoZ * IN.powerNormal.z;
albedo *= LerpWhiteTo (detailAlbedo * unity_ColorSpaceDouble.rgb, detailMask);
#endif
o.Albedo = albedo;
o.Alpha = tex.a * tint.a;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bump =
bumpX * IN.powerNormal.x
+ bumpY * IN.powerNormal.y
+ bumpZ * IN.powerNormal.z
;
// NORMAL DETAIL
//
#ifdef _DETAIL
fixed3 detailNormalTangentX = UnpackScaleNormal(tex2D (_DetailNormalMap, xUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangentY = UnpackScaleNormal(tex2D (_DetailNormalMap, yUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangentZ = UnpackScaleNormal(tex2D (_DetailNormalMap, zUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangent =
detailNormalTangentX * IN.powerNormal.x
+ detailNormalTangentY * IN.powerNormal.y
+ detailNormalTangentZ * IN.powerNormal.z;
bump = lerp(
bump,
BlendNormals(bump, detailNormalTangent),
detailMask);
#endif
o.Normal = normalize(bump);
// METALLIC/GLOSS
//
fixed2 mg = fixed2(
_Metallic,
_Glossiness
);
#ifdef _METALLICGLOSSMAP
fixed2 mgX = lerp(mg, tex2D(_MetallicGlossMap, xUV).ra, _UsingMetallicGlossMap);
fixed2 mgY = lerp(mg, tex2D(_MetallicGlossMap, yUV).ra, _UsingMetallicGlossMap);
fixed2 mgZ = lerp(mg, tex2D(_MetallicGlossMap, zUV).ra, _UsingMetallicGlossMap);
mg =
mgX * IN.powerNormal.x
+ mgY * IN.powerNormal.y
+ mgZ * IN.powerNormal.z;
#endif
o.Metallic = mg.x;
o.Smoothness = mg.y;
// EMISSION
//
#ifndef _EMISSION
o.Emission = 0.0;
#else
fixed3 emissionX = tex2D(_EmissionMap, xUV).rgb;
fixed3 emissionY = tex2D(_EmissionMap, yUV).rgb;
fixed3 emissionZ = tex2D(_EmissionMap, zUV).rgb;
o.Emission = (emissionX * IN.powerNormal.x + emissionY * IN.powerNormal.y + emissionZ * IN.powerNormal.z)
* _EmissionColor.rgb;
#endif
// OCCLUSION
//
#ifdef _OCCLUSION
fixed occX = tex2D(_OcclusionMap, xUV).g;
fixed occY = tex2D(_OcclusionMap, yUV).g;
fixed occZ = tex2D(_OcclusionMap, zUV).g;
o.Occlusion = LerpOneTo(
(occX * IN.powerNormal.x + occY * IN.powerNormal.y + occZ * IN.powerNormal.z),
_OcclusionStrength);
#else
o.Occlusion = 1.0;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreePBRShaderGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4b4a183588f7044b9bb2f086b44f7621
timeCreated: 1426794833
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,437 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
// Use the non-batching version of this shader if you are using
// local mode, and are seeing the textures move when you zoom in
// due to dynamic batching. (Dynamic batching converts local vertex
// data into world space, making local vertex position data unavailable
// to the shader.)
Shader "UVFree/StandardMetallic/Top-Bottom-Texture" {
Properties {
// Triplanar space, for UI
[HideInInspector] _TriplanarSpace("Triplanar Space", Float) = 0.0
_TexPower("Texture Power", Range(0, 20)) = 10.0
_TopMultiplier ("Top Multiplier", Range(0,8)) = 1.0
_BottomMultiplier ("Bottom Multiplier", Range(0,8)) = 0.0
_VertexColorStrength("Vertex Color Strength", Range(0,1)) = 1.0
// FRONT
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.0
[Gamma] _Metallic ("Metallic", Range(0,1)) = 0.0
_MetallicGlossMap("Metallic", 2D) = "black" {}
_UsingMetallicGlossMap("Using Metallic Gloss Map", float) = 0.0
_BumpScale("Bump Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_EmissionColor("Emission Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _EmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _EmissionColorUI("Color", Color) = (1,1,1)
// TOP
_TopColor ("Color", Color) = (1,1,1,1)
_TopMainTex ("Albedo (RGB)", 2D) = "white" {}
_TopGlossiness ("Smoothness", Range(0,1)) = 0.0
[Gamma] _TopMetallic ("Metallic", Range(0,1)) = 0.0
_TopMetallicGlossMap("Metallic", 2D) = "black" {}
_TopUsingMetallicGlossMap("Using Metallic Gloss Map", float) = 0.0
_TopBumpScale("Bump Scale", Float) = 1.0
_TopBumpMap("Normal Map", 2D) = "bump" {}
_TopEmissionColor("Emission Color", Color) = (0,0,0)
_TopEmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _TopEmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _TopEmissionColorUI("Color", Color) = (1,1,1)
// BOTTOM
// bottom is ignored unless _UVFREE_BOTTOM shader feature is turned on
_BottomColor ("Color", Color) = (1,1,1,1)
_BottomMainTex ("Albedo (RGB)", 2D) = "white" {}
_BottomGlossiness ("Smoothness", Range(0,1)) = 0.5
[Gamma] _BottomMetallic ("Metallic", Range(0,1)) = 0.0
_BottomMetallicGlossMap("Metallic", 2D) = "black" {}
_BottomUsingMetallicGlossMap("Using Metallic Gloss Map", float) = 0.0
_BottomBumpScale("Bump Scale", Float) = 1.0
_BottomBumpMap("Normal Map", 2D) = "bump" {}
_BottomEmissionColor("Emission Color", Color) = (0,0,0)
_BottomEmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _BottomEmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _BottomEmissionColorUI("Color", Color) = (1,1,1)
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
}
LOD 300
CGPROGRAM
#pragma target 3.0
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard vertex:vert fullforwardshadows
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _UVFREE_BOTTOM
#include "UnityCG.cginc"
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
// Comment out following line to omit vertex colors
#define _UVFREE_VERTEX_COLOR
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
half _TexPower;
// FRONT
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
fixed _Metallic;
fixed _Glossiness;
fixed _UsingMetallicGlossMap;
#ifdef _METALLICGLOSSMAP
sampler2D _MetallicGlossMap;
#endif
#ifdef _EMISSION
sampler2D _EmissionMap;
sampler2D _TopEmissionMap;
half4 _EmissionColor;
half4 _TopEmissionColor;
#endif
// TOP
half _TopMultiplier;
fixed4 _TopColor;
sampler2D _TopMainTex;
float4 _TopMainTex_ST;
sampler2D _TopBumpMap;
half _TopBumpScale;
fixed _TopMetallic;
fixed _TopGlossiness;
#ifdef _METALLICGLOSSMAP
sampler2D _TopMetallicGlossMap;
fixed _TopUsingMetallicGlossMap;
#endif
// BOTTOM
#ifdef _UVFREE_BOTTOM
half _BottomMultiplier;
fixed4 _BottomColor;
sampler2D _BottomMainTex;
float4 _BottomMainTex_ST;
sampler2D _BottomBumpMap;
half _BottomBumpScale;
fixed _BottomUsingMetallicGlossMap;
#ifdef _METALLICGLOSSMAP
sampler2D _BottomMetallicGlossMap;
#endif
fixed _BottomMetallic;
fixed _BottomGlossiness;
#ifdef _EMISSION
sampler2D _BottomEmissionMap;
half4 _BottomEmissionColor;
#endif
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed _VertexColorStrength;
#endif
struct Input {
fixed3 powerNormal;
fixed3 normal;
float3 worldPos;
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
o.normal = v.normal;
fixed3 powerNormal = v.normal;
fixed3 weightedPowerNormal = v.normal;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0)).xyz);
o.normal = worldNormal;
fixed3 powerNormal = worldNormal;
fixed3 weightedPowerNormal = worldNormal;
#endif
// texpower sets the sharpness
powerNormal = pow(abs(powerNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, 1.0);
o.powerNormal = powerNormal;
#if _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed3 lerpedPowerNormal = lerp(powerNormal, weightedPowerNormal, weightedPowerNormal.y);
#ifdef _UVFREE_LOCAL
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (lerpedPowerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (lerpedPowerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (lerpedPowerNormal.z)
;
v.tangent.w = dot(-v.normal, lerpedPowerNormal);
#else
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (lerpedPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (lerpedPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (lerpedPowerNormal.z))
;
v.tangent.w = dot(-worldNormal, lerpedPowerNormal);
#endif
}
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed topLerp = smoothstep(0.0, 1.0, _TopMultiplier);
#if _UVFREE_BOTTOM
fixed bottomLerp = smoothstep(0.0, 1.0, _BottomMultiplier);
#endif
fixed3 weightedPowerNormal = IN.normal;
#if _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed topBottomLerp = sign(IN.normal.y)*0.5 + 0.5;
fixed yLerp = weightedPowerNormal.y;
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUVTop = posY * _TopMainTex_ST.xy + _TopMainTex_ST.zw;
#ifdef _UVFREE_BOTTOM
float2 yUVBottom = posY * _BottomMainTex_ST.xy + _BottomMainTex_ST.zw;
#endif
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
yUVTop.y *= powerSign.y;
#ifdef _UVFREE_BOTTOM
yUVBottom.y *= powerSign.y;
#endif
#endif
// DIFFUSE
//
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP(_Color_arr, _Color);
fixed4 texX = tex2D(_MainTex, xUV) * tint;
fixed4 texY = tex2D(_MainTex, yUV) * tint;
fixed4 texZ = tex2D(_MainTex, zUV) * tint;
fixed4 texTop = tex2D(_TopMainTex, yUVTop) * _TopColor;
texTop = lerp(texY, texTop, topLerp);
#if _UVFREE_BOTTOM
fixed4 texBottom = tex2D(_BottomMainTex, yUVBottom) * _BottomColor;
texBottom = lerp(texY, texBottom, bottomLerp);
texTop = lerp(texBottom, texTop, topBottomLerp);
#else
texTop = lerp(texY, texTop, topBottomLerp);
#endif
fixed4 tex =
lerp(texX * IN.powerNormal.x, texTop * weightedPowerNormal.x, yLerp)
+ lerp(texY * IN.powerNormal.y, texTop * weightedPowerNormal.y, yLerp)
+ lerp(texZ * IN.powerNormal.z, texTop * weightedPowerNormal.z, yLerp)
;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
o.Albedo = max(fixed3(0.0, 0.0, 0.0), tex.rgb);
o.Alpha = tex.a;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bumpTop = UnpackScaleNormal(tex2D(_TopBumpMap, yUVTop), _TopBumpScale);
bumpTop = lerp(bumpY, bumpTop, topLerp);
#if _UVFREE_BOTTOM
fixed3 bumpBottom = UnpackScaleNormal(tex2D(_BottomBumpMap, yUVBottom), _BottomBumpScale);
bumpBottom = lerp(bumpY, bumpBottom, bottomLerp);
bumpTop = lerp(bumpBottom, bumpTop, topBottomLerp);
#else
bumpTop = lerp(bumpY, bumpTop, topBottomLerp);
#endif
o.Normal = normalize(
lerp(bumpX * IN.powerNormal.x, bumpTop * weightedPowerNormal.x, yLerp)
+ lerp(bumpY * IN.powerNormal.y, bumpTop * weightedPowerNormal.y, yLerp)
+ lerp(bumpZ * IN.powerNormal.z, bumpTop * weightedPowerNormal.z, yLerp)
);
// METALLIC/GLOSS
//
fixed2 mgX = fixed2(_Metallic, _Glossiness);
fixed2 mgY = mgX;
fixed2 mgZ = mgX;
fixed2 mgTop = fixed2(_TopMetallic, _TopGlossiness);
#ifdef _UVFREE_BOTTOM
fixed2 mgBottom = fixed2(_BottomMetallic, _BottomGlossiness);
#endif
#ifdef _METALLICGLOSSMAP
#if SHADER_API_D3D9 && _EMISSION
// skip for top and bottom, because there are not enough samplers
#else
mgX = lerp(mgX, tex2D(_MetallicGlossMap, xUV).ra, _UsingMetallicGlossMap);
mgY = lerp(mgY, tex2D(_MetallicGlossMap, yUV).ra, _UsingMetallicGlossMap);
mgZ = lerp(mgZ, tex2D(_MetallicGlossMap, zUV).ra, _UsingMetallicGlossMap);
mgTop = lerp(mgTop, tex2D(_TopMetallicGlossMap, yUVTop).ra, _TopUsingMetallicGlossMap);
#ifdef _UVFREE_BOTTOM
mgBottom = lerp(mgBottom, tex2D(_BottomMetallicGlossMap, yUVBottom).ra, _BottomUsingMetallicGlossMap);
#endif
#endif
#endif
mgTop = lerp(mgY, mgTop, topLerp);
#ifdef _UVFREE_BOTTOM
mgBottom = lerp(mgY, mgBottom, bottomLerp);
mgTop = lerp(mgBottom, mgTop, topBottomLerp);
#else
mgTop = lerp(mgY, mgTop, topBottomLerp);
#endif
fixed2 mg =
lerp(mgX * IN.powerNormal.x, mgTop * weightedPowerNormal.x, yLerp)
+ lerp(mgY * IN.powerNormal.y, mgTop * weightedPowerNormal.y, yLerp)
+ lerp(mgZ * IN.powerNormal.z, mgTop * weightedPowerNormal.z, yLerp)
;
o.Metallic = mg.x;
o.Smoothness = mg.y;
// EMISSION
//
#ifdef _EMISSION
half3 emissionX = tex2D(_EmissionMap, xUV).rgb * _EmissionColor.rgb;
half3 emissionY = tex2D(_EmissionMap, yUV).rgb * _EmissionColor.rgb;
half3 emissionYTop = tex2D(_TopEmissionMap, yUVTop).rgb * _TopEmissionColor.rgb;
emissionYTop = lerp(emissionY, emissionYTop, topLerp);
#ifdef _UVFREE_BOTTOM
half3 emissionYBottom = tex2D(_BottomEmissionMap, yUVBottom).rgb * _BottomEmissionColor.rgb;
emissionYBottom = lerp(emissionY, emissionYBottom, bottomLerp);
emissionYTop = lerp(emissionYBottom, emissionYTop, topBottomLerp);
#else
emissionYTop = lerp(emissionY, emissionYTop, topBottomLerp);
#endif
half3 emissionZ = tex2D(_EmissionMap, zUV).rgb * _EmissionColor.rgb;
o.Emission +=
lerp(emissionX * IN.powerNormal.x, emissionYTop * weightedPowerNormal.x, yLerp)
+ lerp(emissionY * IN.powerNormal.y, emissionYTop * weightedPowerNormal.y, yLerp)
+ lerp(emissionZ * IN.powerNormal.z, emissionYTop * weightedPowerNormal.z, yLerp)
;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreePBRShaderTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: cc1b0f60eb4c244ffb41d05775fdc42c
timeCreated: 1426831563
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,432 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
Shader "UVFree/StandardMetallic/Top-Bottom-Texture Non-Batched" {
Properties {
// Triplanar space, for UI
[HideInInspector] _TriplanarSpace("Triplanar Space", Float) = 0.0
_TexPower("Texture Power", Range(0, 20)) = 10.0
_TopMultiplier ("Top Multiplier", Range(0,8)) = 1.0
_BottomMultiplier ("Bottom Multiplier", Range(0,8)) = 0.0
_VertexColorStrength("Vertex Color Strength", Range(0,1)) = 1.0
// FRONT
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.0
[Gamma] _Metallic ("Metallic", Range(0,1)) = 0.0
_MetallicGlossMap("Metallic", 2D) = "black" {}
_UsingMetallicGlossMap("Using Metallic Gloss Map", float) = 0.0
_BumpScale("Bump Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_EmissionColor("Emission Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _EmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _EmissionColorUI("Color", Color) = (1,1,1)
// TOP
_TopColor ("Color", Color) = (1,1,1,1)
_TopMainTex ("Albedo (RGB)", 2D) = "white" {}
_TopGlossiness ("Smoothness", Range(0,1)) = 0.0
[Gamma] _TopMetallic ("Metallic", Range(0,1)) = 0.0
_TopMetallicGlossMap("Metallic", 2D) = "black" {}
_TopUsingMetallicGlossMap("Using Metallic Gloss Map", float) = 0.0
_TopBumpScale("Bump Scale", Float) = 1.0
_TopBumpMap("Normal Map", 2D) = "bump" {}
_TopEmissionColor("Emission Color", Color) = (0,0,0)
_TopEmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _TopEmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _TopEmissionColorUI("Color", Color) = (1,1,1)
// BOTTOM
// bottom is ignored unless _UVFREE_BOTTOM shader feature is turned on
_BottomColor ("Color", Color) = (1,1,1,1)
_BottomMainTex ("Albedo (RGB)", 2D) = "white" {}
_BottomGlossiness ("Smoothness", Range(0,1)) = 0.5
[Gamma] _BottomMetallic ("Metallic", Range(0,1)) = 0.0
_BottomMetallicGlossMap("Metallic", 2D) = "black" {}
_BottomUsingMetallicGlossMap("Using Metallic Gloss Map", float) = 0.0
_BottomBumpScale("Bump Scale", Float) = 1.0
_BottomBumpMap("Normal Map", 2D) = "bump" {}
_BottomEmissionColor("Emission Color", Color) = (0,0,0)
_BottomEmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _BottomEmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _BottomEmissionColorUI("Color", Color) = (1,1,1)
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
"DisableBatching"="True"
}
LOD 300
CGPROGRAM
#pragma target 3.0
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard vertex:vert fullforwardshadows
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _UVFREE_BOTTOM
#include "UnityCG.cginc"
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
// Comment out following line to omit vertex colors
#define _UVFREE_VERTEX_COLOR
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
half _TexPower;
// FRONT
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
fixed _Metallic;
fixed _Glossiness;
fixed _UsingMetallicGlossMap;
#ifdef _METALLICGLOSSMAP
sampler2D _MetallicGlossMap;
#endif
#ifdef _EMISSION
sampler2D _EmissionMap;
sampler2D _TopEmissionMap;
half4 _EmissionColor;
half4 _TopEmissionColor;
#endif
// TOP
half _TopMultiplier;
fixed4 _TopColor;
sampler2D _TopMainTex;
float4 _TopMainTex_ST;
sampler2D _TopBumpMap;
half _TopBumpScale;
fixed _TopMetallic;
fixed _TopGlossiness;
#ifdef _METALLICGLOSSMAP
sampler2D _TopMetallicGlossMap;
fixed _TopUsingMetallicGlossMap;
#endif
// BOTTOM
#ifdef _UVFREE_BOTTOM
half _BottomMultiplier;
fixed4 _BottomColor;
sampler2D _BottomMainTex;
float4 _BottomMainTex_ST;
sampler2D _BottomBumpMap;
half _BottomBumpScale;
fixed _BottomUsingMetallicGlossMap;
#ifdef _METALLICGLOSSMAP
sampler2D _BottomMetallicGlossMap;
#endif
fixed _BottomMetallic;
fixed _BottomGlossiness;
#ifdef _EMISSION
sampler2D _BottomEmissionMap;
half4 _BottomEmissionColor;
#endif
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed _VertexColorStrength;
#endif
struct Input {
fixed3 powerNormal;
fixed3 normal;
float3 worldPos;
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
o.normal = v.normal;
fixed3 powerNormal = v.normal;
fixed3 weightedPowerNormal = v.normal;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0)).xyz);
o.normal = worldNormal;
fixed3 powerNormal = worldNormal;
fixed3 weightedPowerNormal = worldNormal;
#endif
// texpower sets the sharpness
powerNormal = pow(abs(powerNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, 1.0);
o.powerNormal = powerNormal;
#if _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed3 lerpedPowerNormal = lerp(powerNormal, weightedPowerNormal, weightedPowerNormal.y);
#ifdef _UVFREE_LOCAL
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (lerpedPowerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (lerpedPowerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (lerpedPowerNormal.z)
;
v.tangent.w = dot(-v.normal, lerpedPowerNormal);
#else
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (lerpedPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (lerpedPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (lerpedPowerNormal.z))
;
v.tangent.w = dot(-worldNormal, lerpedPowerNormal);
#endif
}
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed topLerp = smoothstep(0.0, 1.0, _TopMultiplier);
#if _UVFREE_BOTTOM
fixed bottomLerp = smoothstep(0.0, 1.0, _BottomMultiplier);
#endif
fixed3 weightedPowerNormal = IN.normal;
#if _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed topBottomLerp = sign(IN.normal.y)*0.5 + 0.5;
fixed yLerp = weightedPowerNormal.y;
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUVTop = posY * _TopMainTex_ST.xy + _TopMainTex_ST.zw;
#ifdef _UVFREE_BOTTOM
float2 yUVBottom = posY * _BottomMainTex_ST.xy + _BottomMainTex_ST.zw;
#endif
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
yUVTop.y *= powerSign.y;
#ifdef _UVFREE_BOTTOM
yUVBottom.y *= powerSign.y;
#endif
#endif
// DIFFUSE
//
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP(_Color_arr, _Color);
fixed4 texX = tex2D(_MainTex, xUV) * tint;
fixed4 texY = tex2D(_MainTex, yUV) * tint;
fixed4 texZ = tex2D(_MainTex, zUV) * tint;
fixed4 texTop = tex2D(_TopMainTex, yUVTop) * _TopColor;
texTop = lerp(texY, texTop, topLerp);
#if _UVFREE_BOTTOM
fixed4 texBottom = tex2D(_BottomMainTex, yUVBottom) * _BottomColor;
texBottom = lerp(texY, texBottom, bottomLerp);
texTop = lerp(texBottom, texTop, topBottomLerp);
#else
texTop = lerp(texY, texTop, topBottomLerp);
#endif
fixed4 tex =
lerp(texX * IN.powerNormal.x, texTop * weightedPowerNormal.x, yLerp)
+ lerp(texY * IN.powerNormal.y, texTop * weightedPowerNormal.y, yLerp)
+ lerp(texZ * IN.powerNormal.z, texTop * weightedPowerNormal.z, yLerp)
;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
o.Albedo = max(fixed3(0.0, 0.0, 0.0), tex.rgb);
o.Alpha = tex.a;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bumpTop = UnpackScaleNormal(tex2D(_TopBumpMap, yUVTop), _TopBumpScale);
bumpTop = lerp(bumpY, bumpTop, topLerp);
#if _UVFREE_BOTTOM
fixed3 bumpBottom = UnpackScaleNormal(tex2D(_BottomBumpMap, yUVBottom), _BottomBumpScale);
bumpBottom = lerp(bumpY, bumpBottom, bottomLerp);
bumpTop = lerp(bumpBottom, bumpTop, topBottomLerp);
#else
bumpTop = lerp(bumpY, bumpTop, topBottomLerp);
#endif
o.Normal = normalize(
lerp(bumpX * IN.powerNormal.x, bumpTop * weightedPowerNormal.x, yLerp)
+ lerp(bumpY * IN.powerNormal.y, bumpTop * weightedPowerNormal.y, yLerp)
+ lerp(bumpZ * IN.powerNormal.z, bumpTop * weightedPowerNormal.z, yLerp)
);
// METALLIC/GLOSS
//
fixed2 mgX = fixed2(_Metallic, _Glossiness);
fixed2 mgY = mgX;
fixed2 mgZ = mgX;
fixed2 mgTop = fixed2(_TopMetallic, _TopGlossiness);
#ifdef _UVFREE_BOTTOM
fixed2 mgBottom = fixed2(_BottomMetallic, _BottomGlossiness);
#endif
#ifdef _METALLICGLOSSMAP
#if SHADER_API_D3D9 && _EMISSION
// skip for top and bottom, because there are not enough samplers
#else
mgX = lerp(mgX, tex2D(_MetallicGlossMap, xUV).ra, _UsingMetallicGlossMap);
mgY = lerp(mgY, tex2D(_MetallicGlossMap, yUV).ra, _UsingMetallicGlossMap);
mgZ = lerp(mgZ, tex2D(_MetallicGlossMap, zUV).ra, _UsingMetallicGlossMap);
mgTop = lerp(mgTop, tex2D(_TopMetallicGlossMap, yUVTop).ra, _TopUsingMetallicGlossMap);
#ifdef _UVFREE_BOTTOM
mgBottom = lerp(mgBottom, tex2D(_BottomMetallicGlossMap, yUVBottom).ra, _BottomUsingMetallicGlossMap);
#endif
#endif
#endif
mgTop = lerp(mgY, mgTop, topLerp);
#ifdef _UVFREE_BOTTOM
mgBottom = lerp(mgY, mgBottom, bottomLerp);
mgTop = lerp(mgBottom, mgTop, topBottomLerp);
#else
mgTop = lerp(mgY, mgTop, topBottomLerp);
#endif
fixed2 mg =
lerp(mgX * IN.powerNormal.x, mgTop * weightedPowerNormal.x, yLerp)
+ lerp(mgY * IN.powerNormal.y, mgTop * weightedPowerNormal.y, yLerp)
+ lerp(mgZ * IN.powerNormal.z, mgTop * weightedPowerNormal.z, yLerp)
;
o.Metallic = mg.x;
o.Smoothness = mg.y;
// EMISSION
//
#ifdef _EMISSION
half3 emissionX = tex2D(_EmissionMap, xUV).rgb * _EmissionColor.rgb;
half3 emissionY = tex2D(_EmissionMap, yUV).rgb * _EmissionColor.rgb;
half3 emissionYTop = tex2D(_TopEmissionMap, yUVTop).rgb * _TopEmissionColor.rgb;
emissionYTop = lerp(emissionY, emissionYTop, topLerp);
#ifdef _UVFREE_BOTTOM
half3 emissionYBottom = tex2D(_BottomEmissionMap, yUVBottom).rgb * _BottomEmissionColor.rgb;
emissionYBottom = lerp(emissionY, emissionYBottom, bottomLerp);
emissionYTop = lerp(emissionYBottom, emissionYTop, topBottomLerp);
#else
emissionYTop = lerp(emissionY, emissionYTop, topBottomLerp);
#endif
half3 emissionZ = tex2D(_EmissionMap, zUV).rgb * _EmissionColor.rgb;
o.Emission +=
lerp(emissionX * IN.powerNormal.x, emissionYTop * weightedPowerNormal.x, yLerp)
+ lerp(emissionY * IN.powerNormal.y, emissionYTop * weightedPowerNormal.y, yLerp)
+ lerp(emissionZ * IN.powerNormal.z, emissionYTop * weightedPowerNormal.z, yLerp)
;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreePBRShaderTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d8cd05889c49f4d36a42c72f6529b1e0
timeCreated: 1426831563
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0b05b2893f35c4e57956c54852900435
folderAsset: yes
timeCreated: 1427422590
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,267 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Hidden/UVFree/Terrain/StandardSpecular-AddPass" {
Properties {
_TexPower("Texture Power", Range (0.0, 20.0)) = 10.0
_UVScale("Texture Scale %", Float) = 100.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1.0)
// set by terrain engine
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
[HideInInspector] _Smoothness0 ("Smoothness 0", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness1 ("Smoothness 1", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness2 ("Smoothness 2", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness3 ("Smoothness 3", Range(0.0, 1.0)) = 1.0
}
SubShader {
Tags {
"SplatCount" = "4"
"Queue" = "Geometry-99"
"IgnoreProjector"="True"
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf StandardSpecular decal:add vertex:SplatmapVert finalcolor:SplatmapFinalColor fullforwardshadows
#define TERRAIN_SPLAT_ADDPASS
#define TERRAIN_SURFACE_OUTPUT SurfaceOutputStandardSpecular
#pragma multi_compile_fog
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
#include "UnityPBSLighting.cginc"
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
sampler2D _Control;
float4 _Control_ST;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
#ifdef _TERRAIN_NORMAL_MAP
sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
#endif
fixed _Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3;
half _TexPower;
half _BumpScale;
float _UVScale;
struct Input
{
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
float2 tc_Control : TEXCOORD4; // Not prefixing '_Control' with 'uv' allows a tighter packing of interpolators, which is necessary to support directional lightmap.
UNITY_FOG_COORDS(5)
};
void SplatmapVert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
fixed3 powerNormal = pow(abs(worldNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, half3(1.0,1.0,1.0));
o.powerNormal = powerNormal;
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (powerNormal.x))
+ (-(worldNormal.y) * (powerNormal.y))
+ (-(worldNormal.z) * (powerNormal.z))
;
// Need to manually transform uv here,
// as we choose not to use 'uv' prefix for this texcoord.
o.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);
float4 pos = UnityObjectToClipPos (v.vertex);
UNITY_TRANSFER_FOG(o, pos);
}
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
// world space positions along the axis planes
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
float2 xUV = float2(powerSign.x, 1.0);
float2 zUV = float2(powerSign.z, 1.0);
float2 yUV = float2(1.0, powerSign.y);
#else
float2 xUV = float2(1.0, 1.0);
float2 zUV = xUV;
float2 yUV = xUV;
#endif
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
splat_control = tex2D(_Control, IN.tc_Control);
weight = dot(splat_control, half4(1.0,1.0,1.0,1.0));
#ifndef UNITY_PASS_DEFERRED
splat_control /= (weight + 1e-3f); // avoid NaNs in splat_control
#endif
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS)
clip(weight - 0.0039);
#endif
fixed4 texX0 = tex2D(_Splat0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale);
fixed4 texY0 = tex2D(_Splat0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale);
fixed4 texZ0 = tex2D(_Splat0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale);
fixed4 texX1 = tex2D(_Splat1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale);
fixed4 texY1 = tex2D(_Splat1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale);
fixed4 texZ1 = tex2D(_Splat1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale);
fixed4 texX2 = tex2D(_Splat2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale);
fixed4 texY2 = tex2D(_Splat2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale);
fixed4 texZ2 = tex2D(_Splat2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale);
fixed4 texX3 = tex2D(_Splat3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale);
fixed4 texY3 = tex2D(_Splat3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale);
fixed4 texZ3 = tex2D(_Splat3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale);
fixed4 tex0 =
+ texX0 * IN.powerNormal.x
+ texY0 * IN.powerNormal.y
+ texZ0 * IN.powerNormal.z;
fixed4 tex1 =
+ texX1 * IN.powerNormal.x
+ texY1 * IN.powerNormal.y
+ texZ1 * IN.powerNormal.z;
fixed4 tex2 =
+ texX2 * IN.powerNormal.x
+ texY2 * IN.powerNormal.y
+ texZ2 * IN.powerNormal.z;
fixed4 tex3 =
+ texX3 * IN.powerNormal.x
+ texY3 * IN.powerNormal.y
+ texZ3 * IN.powerNormal.z;
mixedDiffuse = 0.0f;
mixedDiffuse += splat_control.r * tex0 * fixed4(1.0, 1.0, 1.0, _Smoothness0);
mixedDiffuse += splat_control.g * tex1 * fixed4(1.0, 1.0, 1.0, _Smoothness1);
mixedDiffuse += splat_control.b * tex2 * fixed4(1.0, 1.0, 1.0, _Smoothness2);
mixedDiffuse += splat_control.a * tex3 * fixed4(1.0, 1.0, 1.0, _Smoothness3);
o.Albedo = max(fixed3(0.0, 0.0, 0.0),mixedDiffuse.rgb);
o.Alpha = weight;
#ifdef _TERRAIN_NORMAL_MAP
// NORMAL
//
fixed4 flatNormal = fixed4(0.5,0.5,1.0,0.5); // this is "flat normal" in both DXT5nm and xyz*2-1 cases
fixed4 bumpX0 = tex2D(_Normal0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY0 = tex2D(_Normal0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ0 = tex2D(_Normal0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX1 = tex2D(_Normal1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY1 = tex2D(_Normal1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ1 = tex2D(_Normal1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX2 = tex2D(_Normal2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY2 = tex2D(_Normal2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ2 = tex2D(_Normal2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX3 = tex2D(_Normal3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY3 = tex2D(_Normal3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ3 = tex2D(_Normal3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bump0 =
+ bumpX0 * IN.powerNormal.x
+ bumpY0 * IN.powerNormal.y
+ bumpZ0 * IN.powerNormal.z;
fixed4 bump1 =
+ bumpX1 * IN.powerNormal.x
+ bumpY1 * IN.powerNormal.y
+ bumpZ1 * IN.powerNormal.z;
fixed4 bump2 =
+ bumpX2 * IN.powerNormal.x
+ bumpY2 * IN.powerNormal.y
+ bumpZ2 * IN.powerNormal.z;
fixed4 bump3 =
+ bumpX3 * IN.powerNormal.x
+ bumpY3 * IN.powerNormal.y
+ bumpZ3 * IN.powerNormal.z;
fixed4 bump =
splat_control.r * bump0
+ splat_control.g * bump1
+ splat_control.b * bump2
+ splat_control.a * bump3;
bump *= _BumpScale;
bump += flatNormal;
o.Normal = UnpackNormal(bump);
#endif
o.Smoothness = mixedDiffuse.a;
o.Specular = _SpecColor.rgb * mixedDiffuse.rgb;
}
void SplatmapFinalColor(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 color)
{
color *= o.Alpha;
#ifdef TERRAIN_SPLAT_ADDPASS
UNITY_APPLY_FOG_COLOR(IN.fogCoord, color, fixed4(0,0,0,0));
#else
UNITY_APPLY_FOG(IN.fogCoord, color);
#endif
}
ENDCG
}
Fallback "Hidden/TerrainEngine/Splatmap/Diffuse-AddPass"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7e3af7d341f674531bc6b8e837af9d37
timeCreated: 1427314227
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,50 @@
Shader "Hidden/UVFree/Terrain/StandardSpecular-Base" {
Properties {
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1.0)
_Smoothness ("Smoothness", Range (0.03, 1)) = 0.078125
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
// used in fallback on old cards
_Color ("Main Color", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
Tags {
"RenderType" = "Opaque"
"Queue" = "Geometry-100"
}
LOD 200
CGPROGRAM
#pragma surface surf StandardSpecular fullforwardshadows
#pragma target 3.0
#pragma exclude_renderers gles
#include "UnityPBSLighting.cginc"
sampler2D _MainTex;
fixed _Smoothness;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = max(fixed3(0.001, 0.001, 0.001),c.rgb);
o.Alpha = 1.0;
#ifdef _TERRAIN_OVERRIDE_SMOOTHNESS
o.Smoothness = _Smoothness;
#else
o.Smoothness = c.a;
#endif
o.Specular = _SpecColor;
}
ENDCG
}
FallBack "Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 13504394cfd4f420b90356efe9ec74fa
timeCreated: 1427314224
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,271 @@
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "UVFree/Terrain/StandardSpecular" {
Properties {
_TexPower("Texture Power", Range (0.0, 20.0)) = 10.0
_UVScale("Texture Scale %", Float) = 100.0
_BumpScale("Bump Scale", Range(-2.0, 2.0)) = 1.0
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1.0)
// set by terrain engine
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
[HideInInspector] _Smoothness0 ("Smoothness 0", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness1 ("Smoothness 1", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness2 ("Smoothness 2", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness3 ("Smoothness 3", Range(0.0, 1.0)) = 1.0
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
Tags {
"SplatCount" = "4"
"Queue" = "Geometry-100"
"RenderType" = "Opaque"
}
CGPROGRAM
#pragma surface surf StandardSpecular vertex:SplatmapVert finalcolor:SplatmapFinalColor fullforwardshadows
#define TERRAIN_SURFACE_OUTPUT SurfaceOutputStandardSpecular
#pragma multi_compile_fog
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
#include "UnityPBSLighting.cginc"
#pragma multi_compile __ _TERRAIN_NORMAL_MAP
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
sampler2D _Control;
float4 _Control_ST;
sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
half4 _Splat0_ST, _Splat1_ST, _Splat2_ST, _Splat3_ST;
#ifdef _TERRAIN_NORMAL_MAP
sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
#endif
fixed _Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3;
half _TexPower;
half _BumpScale;
float _UVScale;
struct Input
{
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
float2 tc_Control : TEXCOORD4; // Not prefixing '_Control' with 'uv' allows a tighter packing of interpolators, which is necessary to support directional lightmap.
UNITY_FOG_COORDS(5)
};
void SplatmapVert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
fixed3 powerNormal = pow(abs(worldNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, half3(1.0,1.0,1.0));
o.powerNormal = powerNormal;
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (powerNormal.x))
+ (-(worldNormal.y) * (powerNormal.y))
+ (-(worldNormal.z) * (powerNormal.z))
;
// Need to manually transform uv here,
// as we choose not to use 'uv' prefix for this texcoord.
o.tc_Control = TRANSFORM_TEX(v.texcoord, _Control);
float4 pos = UnityObjectToClipPos (v.vertex);
UNITY_TRANSFER_FOG(o, pos);
}
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
// world space positions along the axis planes
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
float2 xUV = float2(powerSign.x, 1.0);
float2 zUV = float2(powerSign.z, 1.0);
float2 yUV = float2(1.0, powerSign.y);
#else
float2 xUV = float2(1.0, 1.0);
float2 zUV = xUV;
float2 yUV = xUV;
#endif
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
splat_control = tex2D(_Control, IN.tc_Control);
weight = dot(splat_control, half4(1.0,1.0,1.0,1.0));
#ifndef UNITY_PASS_DEFERRED
splat_control /= (weight + 1e-3f); // avoid NaNs in splat_control
#endif
#if !defined(SHADER_API_MOBILE) && defined(TERRAIN_SPLAT_ADDPASS)
clip(weight - 0.0039);
#endif
fixed4 texX0 = tex2D(_Splat0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale);
fixed4 texY0 = tex2D(_Splat0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale);
fixed4 texZ0 = tex2D(_Splat0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale);
fixed4 texX1 = tex2D(_Splat1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale);
fixed4 texY1 = tex2D(_Splat1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale);
fixed4 texZ1 = tex2D(_Splat1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale);
fixed4 texX2 = tex2D(_Splat2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale);
fixed4 texY2 = tex2D(_Splat2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale);
fixed4 texZ2 = tex2D(_Splat2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale);
fixed4 texX3 = tex2D(_Splat3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale);
fixed4 texY3 = tex2D(_Splat3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale);
fixed4 texZ3 = tex2D(_Splat3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale);
fixed4 tex0 =
+ texX0 * IN.powerNormal.x
+ texY0 * IN.powerNormal.y
+ texZ0 * IN.powerNormal.z;
fixed4 tex1 =
+ texX1 * IN.powerNormal.x
+ texY1 * IN.powerNormal.y
+ texZ1 * IN.powerNormal.z;
fixed4 tex2 =
+ texX2 * IN.powerNormal.x
+ texY2 * IN.powerNormal.y
+ texZ2 * IN.powerNormal.z;
fixed4 tex3 =
+ texX3 * IN.powerNormal.x
+ texY3 * IN.powerNormal.y
+ texZ3 * IN.powerNormal.z;
mixedDiffuse = 0.0f;
mixedDiffuse += splat_control.r * tex0 * fixed4(1.0, 1.0, 1.0, _Smoothness0);
mixedDiffuse += splat_control.g * tex1 * fixed4(1.0, 1.0, 1.0, _Smoothness1);
mixedDiffuse += splat_control.b * tex2 * fixed4(1.0, 1.0, 1.0, _Smoothness2);
mixedDiffuse += splat_control.a * tex3 * fixed4(1.0, 1.0, 1.0, _Smoothness3);
o.Albedo = max(fixed3(0.0, 0.0, 0.0),mixedDiffuse.rgb);
o.Alpha = weight;
#ifdef _TERRAIN_NORMAL_MAP
// NORMAL
//
fixed4 flatNormal = fixed4(0.5,0.5,1.0,0.5); // this is "flat normal" in both DXT5nm and xyz*2-1 cases
fixed4 bumpX0 = tex2D(_Normal0, (posX * _Splat0_ST.xy + _Splat0_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY0 = tex2D(_Normal0, (posY * _Splat0_ST.xy + _Splat0_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ0 = tex2D(_Normal0, (posZ * _Splat0_ST.xy + _Splat0_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX1 = tex2D(_Normal1, (posX * _Splat1_ST.xy + _Splat1_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY1 = tex2D(_Normal1, (posY * _Splat1_ST.xy + _Splat1_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ1 = tex2D(_Normal1, (posZ * _Splat1_ST.xy + _Splat1_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX2 = tex2D(_Normal2, (posX * _Splat2_ST.xy + _Splat2_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY2 = tex2D(_Normal2, (posY * _Splat2_ST.xy + _Splat2_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ2 = tex2D(_Normal2, (posZ * _Splat2_ST.xy + _Splat2_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bumpX3 = tex2D(_Normal3, (posX * _Splat3_ST.xy + _Splat3_ST.zw)*xUV/_UVScale) - flatNormal;
fixed4 bumpY3 = tex2D(_Normal3, (posY * _Splat3_ST.xy + _Splat3_ST.zw)*yUV/_UVScale) - flatNormal;
fixed4 bumpZ3 = tex2D(_Normal3, (posZ * _Splat3_ST.xy + _Splat3_ST.zw)*zUV/_UVScale) - flatNormal;
fixed4 bump0 =
+ bumpX0 * IN.powerNormal.x
+ bumpY0 * IN.powerNormal.y
+ bumpZ0 * IN.powerNormal.z;
fixed4 bump1 =
+ bumpX1 * IN.powerNormal.x
+ bumpY1 * IN.powerNormal.y
+ bumpZ1 * IN.powerNormal.z;
fixed4 bump2 =
+ bumpX2 * IN.powerNormal.x
+ bumpY2 * IN.powerNormal.y
+ bumpZ2 * IN.powerNormal.z;
fixed4 bump3 =
+ bumpX3 * IN.powerNormal.x
+ bumpY3 * IN.powerNormal.y
+ bumpZ3 * IN.powerNormal.z;
fixed4 bump =
splat_control.r * bump0
+ splat_control.g * bump1
+ splat_control.b * bump2
+ splat_control.a * bump3;
bump *= _BumpScale;
bump += flatNormal;
o.Normal = UnpackNormal(bump);
#endif
o.Smoothness = mixedDiffuse.a;
o.Specular = _SpecColor.rgb * mixedDiffuse.rgb;
}
void SplatmapFinalColor(Input IN, TERRAIN_SURFACE_OUTPUT o, inout fixed4 color)
{
color *= o.Alpha;
#ifdef TERRAIN_SPLAT_ADDPASS
UNITY_APPLY_FOG_COLOR(IN.fogCoord, color, fixed4(0,0,0,0));
#else
UNITY_APPLY_FOG(IN.fogCoord, color);
#endif
}
ENDCG
}
Dependency "AddPassShader" = "Hidden/UVFree/Terrain/StandardSpecular-AddPass"
Dependency "BaseMapShader" = "Hidden/UVFree/Terrain/StandardSpecular-Base"
Fallback "Nature/Terrain/Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: cd37e0b49bce84f099a62f77d42e8a90
timeCreated: 1427314231
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 45d491b295c2147108081df19e215aa4
folderAsset: yes
timeCreated: 1426831333
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,407 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
// Use the non-batching version of this shader if you are using
// local mode, and are seeing the textures move when you zoom in
// due to dynamic batching. (Dynamic batching converts local vertex
// data into world space, making local vertex position data unavailable
// to the shader.)
Shader "UVFree/StandardSpecular/Single-Texture" {
Properties {
// Triplanar space, for UI
[HideInInspector] _TriplanarSpace("Triplanar Space", Float) = 0.0
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_Color ("Color", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 1.0
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_SpecColor("Specular", Color) = (0.2,0.2,0.2)
_SpecGlossMap("Specular", 2D) = "white" {}
_UsingSpecGlossMap("Using Spec Gloss Map", float) = 0.0
_BumpScale("Bump 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("Occlusion Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
_EmissionColor("Emission Color", Color) = (0.0,0.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" {}
// UI-only data
[HideInInspector] _EmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _EmissionColorUI("Color", Color) = (1.0,1.0,1.0)
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
}
LOD 300
CGPROGRAM
#pragma target 3.0
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf StandardSpecular vertex:vert fullforwardshadows
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _EMISSION
#pragma shader_feature _SPECGLOSSMAP
#pragma shader_feature _DETAIL
#pragma shader_feature _OCCLUSION
#pragma shader_feature _PARALLAXMAP
#include "UnityCG.cginc"
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
// Comment out following line to omit vertex colors
#define _UVFREE_VERTEX_COLOR
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
half _TexPower;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
fixed _Glossiness;
#ifdef _DETAIL
sampler2D _DetailAlbedoMap;
float4 _DetailAlbedoMap_ST;
sampler2D _DetailMask;
sampler2D _DetailNormalMap;
half _DetailNormalMapScale;
#endif
#ifdef _SPECGLOSSMAP
sampler2D _SpecGlossMap;
fixed _UsingSpecGlossMap;
#endif
#ifdef _OCCLUSION
sampler2D _OcclusionMap;
fixed _OcclusionStrength;
#endif
#ifdef _PARALLAXMAP
sampler2D _ParallaxMap;
half _Parallax;
#endif
#ifdef _EMISSION
sampler2D _EmissionMap;
half4 _EmissionColor;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed _VertexColorStrength;
#endif
half _UVSec;
struct Input {
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
fixed3 viewDirForParallax;
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = v.normal;
#endif
o.powerNormal = pow(abs(v.normal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (o.powerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (o.powerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (o.powerNormal.z)
;
v.tangent.w =
(-(v.normal.x) * (o.powerNormal.x))
+ (-(v.normal.y) * (o.powerNormal.y))
+ (-(v.normal.z) * (o.powerNormal.z))
;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
o.powerNormal = pow(abs(worldNormal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (o.powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (o.powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (o.powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (o.powerNormal.x))
+ (-(worldNormal.y) * (o.powerNormal.y))
+ (-(worldNormal.z) * (o.powerNormal.z))
;
#endif
#ifdef _PARALLAXMAP
TANGENT_SPACE_ROTATION;
o.viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex));
#endif
}
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float3 pos = IN.worldPos;
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
#endif
// PARALLAX
//
#ifdef _PARALLAXMAP
half parallaxX = tex2D (_ParallaxMap, xUV).r;
half parallaxY = tex2D (_ParallaxMap, yUV).g;
half parallaxZ = tex2D (_ParallaxMap, zUV).b;
half parallax =
parallaxX * IN.powerNormal.x
+ parallaxY * IN.powerNormal.y
+ parallaxZ * IN.powerNormal.z
;
float2 parallaxOffset = ParallaxOffset (parallax, _Parallax, IN.viewDirForParallax);
xUV += parallaxOffset;
yUV += parallaxOffset;
zUV += parallaxOffset;
#endif
// DIFFUSE
//
fixed4 texX = tex2D(_MainTex, xUV);
fixed4 texY = tex2D(_MainTex, yUV);
fixed4 texZ = tex2D(_MainTex, zUV);
fixed4 tex =
texX * IN.powerNormal.x
+ texY * IN.powerNormal.y
+ texZ * IN.powerNormal.z;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
fixed3 albedo = max(fixed3(0.0, 0.0, 0.0), tex.rgb * tint.rgb);
// DIFFUSE DETAIL
//
#ifdef _DETAIL
fixed detailMaskX = tex2D(_DetailMask, xUV).a;
fixed detailMaskY = tex2D(_DetailMask, yUV).a;
fixed detailMaskZ = tex2D(_DetailMask, zUV).a;
fixed detailMask =
detailMaskX * IN.powerNormal.x
+ detailMaskY * IN.powerNormal.y
+ detailMaskZ * IN.powerNormal.z;
float2 xUVDetail = pos.zy * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
float2 yUVDetail = pos.xz * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
float2 zUVDetail = float2(-pos.x, pos.y) * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
xUVDetail.x *= powerSign.x;
zUVDetail.x *= powerSign.z;
yUVDetail.y *= powerSign.y;
#endif
#ifdef _PARALLAXMAP
xUVDetail += parallaxOffset;
yUVDetail += parallaxOffset;
zUVDetail += parallaxOffset;
#endif
fixed3 detailAlbedoX = tex2D (_DetailAlbedoMap, xUVDetail).rgb;
fixed3 detailAlbedoY = tex2D (_DetailAlbedoMap, yUVDetail).rgb;
fixed3 detailAlbedoZ = tex2D (_DetailAlbedoMap, zUVDetail).rgb;
fixed3 detailAlbedo =
detailAlbedoX * IN.powerNormal.x
+ detailAlbedoY * IN.powerNormal.y
+ detailAlbedoZ * IN.powerNormal.z;
albedo *= LerpWhiteTo (detailAlbedo * unity_ColorSpaceDouble.rgb, detailMask);
#endif
o.Albedo = albedo;
o.Alpha = tex.a * tint.a;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bump =
bumpX * IN.powerNormal.x
+ bumpY * IN.powerNormal.y
+ bumpZ * IN.powerNormal.z
;
// NORMAL DETAIL
//
#ifdef _DETAIL
fixed3 detailNormalTangentX = UnpackScaleNormal(tex2D (_DetailNormalMap, xUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangentY = UnpackScaleNormal(tex2D (_DetailNormalMap, yUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangentZ = UnpackScaleNormal(tex2D (_DetailNormalMap, zUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangent =
detailNormalTangentX * IN.powerNormal.x
+ detailNormalTangentY * IN.powerNormal.y
+ detailNormalTangentZ * IN.powerNormal.z;
bump = lerp(
bump,
BlendNormals(bump, detailNormalTangent),
detailMask);
#endif
o.Normal = normalize(bump);
// SPECULAR/GLOSS
//
fixed4 sg = fixed4(
_SpecColor.rgb,
_Glossiness
);
#ifdef _SPECGLOSSMAP
fixed4 sgX = lerp(sg, tex2D(_SpecGlossMap, xUV), _UsingSpecGlossMap);
fixed4 sgY = lerp(sg, tex2D(_SpecGlossMap, yUV), _UsingSpecGlossMap);
fixed4 sgZ = lerp(sg, tex2D(_SpecGlossMap, zUV), _UsingSpecGlossMap);
sg =
sgX * IN.powerNormal.x
+ sgY * IN.powerNormal.y
+ sgZ * IN.powerNormal.z;
#endif
o.Specular = sg.rgb;
o.Smoothness = sg.a;
// EMISSION
//
#ifndef _EMISSION
o.Emission = 0.0;
#else
fixed3 emissionX = tex2D(_EmissionMap, xUV).rgb;
fixed3 emissionY = tex2D(_EmissionMap, yUV).rgb;
fixed3 emissionZ = tex2D(_EmissionMap, zUV).rgb;
o.Emission = (emissionX * IN.powerNormal.x + emissionY * IN.powerNormal.y + emissionZ * IN.powerNormal.z)
* _EmissionColor.rgb;
#endif
// OCCLUSION
//
#ifdef _OCCLUSION
fixed occX = tex2D(_OcclusionMap, xUV).g;
fixed occY = tex2D(_OcclusionMap, yUV).g;
fixed occZ = tex2D(_OcclusionMap, zUV).g;
o.Occlusion = LerpOneTo(
(occX * IN.powerNormal.x + occY * IN.powerNormal.y + occZ * IN.powerNormal.z),
_OcclusionStrength);
#else
o.Occlusion = 1.0;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreePBRShaderGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b037cc9f7b4b34ed8be6c81e1b20c146
timeCreated: 1426794818
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,402 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
Shader "UVFree/StandardSpecular/Single-Texture Non-Batching" {
Properties {
// Triplanar space, for UI
[HideInInspector] _TriplanarSpace("Triplanar Space", Float) = 0.0
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_Color ("Color", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 1.0
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_SpecColor("Specular", Color) = (0.2,0.2,0.2)
_SpecGlossMap("Specular", 2D) = "white" {}
_UsingSpecGlossMap("Using Spec Gloss Map", float) = 0.0
_BumpScale("Bump 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("Occlusion Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
_EmissionColor("Emission Color", Color) = (0.0,0.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" {}
// UI-only data
[HideInInspector] _EmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _EmissionColorUI("Color", Color) = (1.0,1.0,1.0)
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
"DisableBatching"="True"
}
LOD 300
CGPROGRAM
#pragma target 3.0
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf StandardSpecular vertex:vert fullforwardshadows
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _EMISSION
#pragma shader_feature _SPECGLOSSMAP
#pragma shader_feature _DETAIL
#pragma shader_feature _OCCLUSION
#pragma shader_feature _PARALLAXMAP
#include "UnityCG.cginc"
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
// Comment out following line to omit vertex colors
#define _UVFREE_VERTEX_COLOR
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
// Non-instanced properties
half _TexPower;
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
fixed _Glossiness;
#ifdef _DETAIL
sampler2D _DetailAlbedoMap;
float4 _DetailAlbedoMap_ST;
sampler2D _DetailMask;
sampler2D _DetailNormalMap;
half _DetailNormalMapScale;
#endif
#ifdef _SPECGLOSSMAP
sampler2D _SpecGlossMap;
fixed _UsingSpecGlossMap;
#endif
#ifdef _OCCLUSION
sampler2D _OcclusionMap;
fixed _OcclusionStrength;
#endif
#ifdef _PARALLAXMAP
sampler2D _ParallaxMap;
half _Parallax;
#endif
#ifdef _EMISSION
sampler2D _EmissionMap;
half4 _EmissionColor;
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed _VertexColorStrength;
#endif
half _UVSec;
struct Input {
fixed3 powerNormal;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 normal;
#endif
float3 worldPos;
fixed3 viewDirForParallax;
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = v.normal;
#endif
o.powerNormal = pow(abs(v.normal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (o.powerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (o.powerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (o.powerNormal.z)
;
v.tangent.w =
(-(v.normal.x) * (o.powerNormal.x))
+ (-(v.normal.y) * (o.powerNormal.y))
+ (-(v.normal.z) * (o.powerNormal.z))
;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
o.normal = worldNormal;
#endif
o.powerNormal = pow(abs(worldNormal), _TexPower);
o.powerNormal = max(o.powerNormal, 0.0001);
o.powerNormal /= dot(o.powerNormal, 1.0);
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (o.powerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (o.powerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (o.powerNormal.z))
;
v.tangent.w =
(-(worldNormal.x) * (o.powerNormal.x))
+ (-(worldNormal.y) * (o.powerNormal.y))
+ (-(worldNormal.z) * (o.powerNormal.z))
;
#endif
#ifdef _PARALLAXMAP
TANGENT_SPACE_ROTATION;
o.viewDirForParallax = mul (rotation, ObjSpaceViewDir(v.vertex));
#endif
}
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float3 pos = IN.worldPos;
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
#endif
// PARALLAX
//
#ifdef _PARALLAXMAP
half parallaxX = tex2D (_ParallaxMap, xUV).r;
half parallaxY = tex2D (_ParallaxMap, yUV).g;
half parallaxZ = tex2D (_ParallaxMap, zUV).b;
half parallax =
parallaxX * IN.powerNormal.x
+ parallaxY * IN.powerNormal.y
+ parallaxZ * IN.powerNormal.z
;
float2 parallaxOffset = ParallaxOffset (parallax, _Parallax, IN.viewDirForParallax);
xUV += parallaxOffset;
yUV += parallaxOffset;
zUV += parallaxOffset;
#endif
// DIFFUSE
//
fixed4 texX = tex2D(_MainTex, xUV);
fixed4 texY = tex2D(_MainTex, yUV);
fixed4 texZ = tex2D(_MainTex, zUV);
fixed4 tex =
texX * IN.powerNormal.x
+ texY * IN.powerNormal.y
+ texZ * IN.powerNormal.z;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP (_Color_arr, _Color);
fixed3 albedo = max(fixed3(0.0, 0.0, 0.0), tex.rgb * tint.rgb);
// DIFFUSE DETAIL
//
#ifdef _DETAIL
fixed detailMaskX = tex2D(_DetailMask, xUV).a;
fixed detailMaskY = tex2D(_DetailMask, yUV).a;
fixed detailMaskZ = tex2D(_DetailMask, zUV).a;
fixed detailMask =
detailMaskX * IN.powerNormal.x
+ detailMaskY * IN.powerNormal.y
+ detailMaskZ * IN.powerNormal.z;
float2 xUVDetail = pos.zy * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
float2 yUVDetail = pos.xz * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
float2 zUVDetail = float2(-pos.x, pos.y) * _DetailAlbedoMap_ST.xy + _DetailAlbedoMap_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
xUVDetail.x *= powerSign.x;
zUVDetail.x *= powerSign.z;
yUVDetail.y *= powerSign.y;
#endif
#ifdef _PARALLAXMAP
xUVDetail += parallaxOffset;
yUVDetail += parallaxOffset;
zUVDetail += parallaxOffset;
#endif
fixed3 detailAlbedoX = tex2D (_DetailAlbedoMap, xUVDetail).rgb;
fixed3 detailAlbedoY = tex2D (_DetailAlbedoMap, yUVDetail).rgb;
fixed3 detailAlbedoZ = tex2D (_DetailAlbedoMap, zUVDetail).rgb;
fixed3 detailAlbedo =
detailAlbedoX * IN.powerNormal.x
+ detailAlbedoY * IN.powerNormal.y
+ detailAlbedoZ * IN.powerNormal.z;
albedo *= LerpWhiteTo (detailAlbedo * unity_ColorSpaceDouble.rgb, detailMask);
#endif
o.Albedo = albedo;
o.Alpha = tex.a * tint.a;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bump =
bumpX * IN.powerNormal.x
+ bumpY * IN.powerNormal.y
+ bumpZ * IN.powerNormal.z
;
// NORMAL DETAIL
//
#ifdef _DETAIL
fixed3 detailNormalTangentX = UnpackScaleNormal(tex2D (_DetailNormalMap, xUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangentY = UnpackScaleNormal(tex2D (_DetailNormalMap, yUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangentZ = UnpackScaleNormal(tex2D (_DetailNormalMap, zUVDetail), _DetailNormalMapScale);
fixed3 detailNormalTangent =
detailNormalTangentX * IN.powerNormal.x
+ detailNormalTangentY * IN.powerNormal.y
+ detailNormalTangentZ * IN.powerNormal.z;
bump = lerp(
bump,
BlendNormals(bump, detailNormalTangent),
detailMask);
#endif
o.Normal = normalize(bump);
// SPECULAR/GLOSS
//
fixed4 sg = fixed4(
_SpecColor.rgb,
_Glossiness
);
#ifdef _SPECGLOSSMAP
fixed4 sgX = lerp(sg, tex2D(_SpecGlossMap, xUV), _UsingSpecGlossMap);
fixed4 sgY = lerp(sg, tex2D(_SpecGlossMap, yUV), _UsingSpecGlossMap);
fixed4 sgZ = lerp(sg, tex2D(_SpecGlossMap, zUV), _UsingSpecGlossMap);
sg =
sgX * IN.powerNormal.x
+ sgY * IN.powerNormal.y
+ sgZ * IN.powerNormal.z;
#endif
o.Specular = sg.rgb;
o.Smoothness = sg.a;
// EMISSION
//
#ifndef _EMISSION
o.Emission = 0.0;
#else
fixed3 emissionX = tex2D(_EmissionMap, xUV).rgb;
fixed3 emissionY = tex2D(_EmissionMap, yUV).rgb;
fixed3 emissionZ = tex2D(_EmissionMap, zUV).rgb;
o.Emission = (emissionX * IN.powerNormal.x + emissionY * IN.powerNormal.y + emissionZ * IN.powerNormal.z)
* _EmissionColor.rgb;
#endif
// OCCLUSION
//
#ifdef _OCCLUSION
fixed occX = tex2D(_OcclusionMap, xUV).g;
fixed occY = tex2D(_OcclusionMap, yUV).g;
fixed occZ = tex2D(_OcclusionMap, zUV).g;
o.Occlusion = LerpOneTo(
(occX * IN.powerNormal.x + occY * IN.powerNormal.y + occZ * IN.powerNormal.z),
_OcclusionStrength);
#else
o.Occlusion = 1.0;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreePBRShaderGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 85b575738c24e452dae1e4251469cee7
timeCreated: 1426794818
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,445 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
// Use the non-batching version of this shader if you are using
// local mode, and are seeing the textures move when you zoom in
// due to dynamic batching. (Dynamic batching converts local vertex
// data into world space, making local vertex position data unavailable
// to the shader.)
Shader "UVFree/StandardSpecular/Top-Bottom-Texture" {
Properties {
// Triplanar space, for UI
[HideInInspector] _TriplanarSpace("Triplanar Space", Float) = 0.0
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_TopMultiplier ("Top Multiplier", Range(0.0,8.0)) = 1.0
_BottomMultiplier ("Bottom Multiplier", Range(0.0,8.0)) = 0.0
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 1.0
// FRONT
_Color ("Color", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_SpecColor("Specular", Color) = (0.2,0.2,0.2)
_SpecGlossMap("Specular", 2D) = "white" {}
_UsingSpecGlossMap("Using Spec Gloss Map", float) = 0.0
_BumpScale("Bump Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _EmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _EmissionColorUI("Color", Color) = (1.0,1.0,1.0)
// TOP
_TopColor ("Color", Color) = (1.0,1.0,1.0,1.0)
_TopMainTex ("Albedo (RGB)", 2D) = "white" {}
_TopGlossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_TopSpecColor("Specular", Color) = (0.2,0.2,0.2)
_TopSpecGlossMap("Specular", 2D) = "white" {}
_TopUsingSpecGlossMap("Using Spec Gloss Map", float) = 0.0
_TopBumpScale("Bump Scale", Float) = 1.0
_TopBumpMap("Normal Map", 2D) = "bump" {}
_TopEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_TopEmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _TopEmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _TopEmissionColorUI("Color", Color) = (1,1,1)
// BOTTOM
// bottom is ignored unless _UVFREE_BOTTOM shader feature is turned on
_BottomColor ("Color", Color) = (1.0,1.0,1.0,1.0)
_BottomMainTex ("Albedo (RGB)", 2D) = "white" {}
_BottomGlossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_BottomSpecColor("Specular", Color) = (0.2,0.2,0.2)
_BottomSpecGlossMap("Specular", 2D) = "white" {}
_BottomUsingSpecGlossMap("Using Spec Gloss Map", float) = 0.0
_BottomBumpScale("Bump Scale", Float) = 1.0
_BottomBumpMap("Normal Map", 2D) = "bump" {}
_BottomEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_BottomEmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _BottomEmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _BottomEmissionColorUI("Color", Color) = (1.0,1.0,1.0)
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
}
LOD 300
CGPROGRAM
#pragma target 3.0
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf StandardSpecular vertex:vert fullforwardshadows
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _EMISSION
#pragma shader_feature _SPECGLOSSMAP
#pragma shader_feature _UVFREE_BOTTOM
#include "UnityCG.cginc"
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
// Comment out following line to omit vertex colors
#define _UVFREE_VERTEX_COLOR
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
half _TexPower;
// FRONT
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
fixed _Glossiness;
#ifdef _SPECGLOSSMAP
sampler2D _SpecGlossMap;
fixed _UsingSpecGlossMap;
#endif
#ifdef _EMISSION
half4 _EmissionColor;
sampler2D _EmissionMap;
sampler2D _TopEmissionMap;
half4 _TopEmissionColor;
#endif
// TOP
half _TopMultiplier;
fixed4 _TopColor;
sampler2D _TopMainTex;
float4 _TopMainTex_ST;
sampler2D _TopBumpMap;
half _TopBumpScale;
fixed _TopGlossiness;
fixed4 _TopSpecColor;
#ifdef _SPECGLOSSMAP
sampler2D _TopSpecGlossMap;
fixed _TopUsingSpecGlossMap;
#endif
// BOTTOM
#ifdef _UVFREE_BOTTOM
half _BottomMultiplier;
fixed4 _BottomColor;
sampler2D _BottomMainTex;
float4 _BottomMainTex_ST;
sampler2D _BottomBumpMap;
half _BottomBumpScale;
fixed4 _BottomSpecColor;
fixed _BottomGlossiness;
#ifdef _SPECGLOSSMAP
sampler2D _BottomSpecGlossMap;
fixed _BottomUsingSpecGlossMap;
#endif
#ifdef _EMISSION
sampler2D _BottomEmissionMap;
half4 _BottomEmissionColor;
#endif
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed _VertexColorStrength;
#endif
struct Input {
fixed3 powerNormal;
fixed3 normal;
float3 worldPos;
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
fixed3 powerNormal = v.normal;
o.normal = v.normal;
fixed topFactor = sign(v.normal.y)*0.5+0.5;
fixed3 weightedPowerNormal = v.normal;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
o.normal = worldNormal;
fixed3 powerNormal = worldNormal;
fixed3 weightedPowerNormal = worldNormal;
#endif
// texpower sets the sharpness
powerNormal = pow(abs(powerNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, 1.0);
o.powerNormal = powerNormal;
#if _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed3 lerpedPowerNormal = lerp(powerNormal, weightedPowerNormal, weightedPowerNormal.y);
#ifdef _UVFREE_LOCAL
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (lerpedPowerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (lerpedPowerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (lerpedPowerNormal.z)
;
v.tangent.w = dot(-v.normal, lerpedPowerNormal);
#else
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (lerpedPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (lerpedPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (lerpedPowerNormal.z))
;
v.tangent.w = dot(-worldNormal, lerpedPowerNormal);
#endif
}
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
fixed topLerp = smoothstep(0.0, 1.0, _TopMultiplier);
#if _UVFREE_BOTTOM
fixed bottomLerp = smoothstep(0.0, 1.0, _BottomMultiplier);
#endif
fixed3 weightedPowerNormal = IN.normal;
#if _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed topBottomLerp = sign(IN.normal.y)*0.5 + 0.5;
fixed yLerp = weightedPowerNormal.y;
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUVTop = posY * _TopMainTex_ST.xy + _TopMainTex_ST.zw;
#ifdef _UVFREE_BOTTOM
float2 yUVBottom = posY * _BottomMainTex_ST.xy + _BottomMainTex_ST.zw;
#endif
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
yUVTop.y *= powerSign.y;
#ifdef _UVFREE_BOTTOM
yUVBottom.y *= powerSign.y;
#endif
#endif
// DIFFUSE
//
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP(_Color_arr, _Color);
fixed4 texX = tex2D(_MainTex, xUV) * tint;
fixed4 texY = tex2D(_MainTex, yUV) * tint;
fixed4 texZ = tex2D(_MainTex, zUV) * tint;
fixed4 texTop = tex2D(_TopMainTex, yUVTop) * _TopColor;
texTop = lerp(texY, texTop, topLerp);
#if _UVFREE_BOTTOM
fixed4 texBottom = tex2D(_BottomMainTex, yUVBottom) * _BottomColor;
texBottom = lerp(texY, texBottom, bottomLerp);
texTop = lerp(texBottom, texTop, topBottomLerp);
#else
texTop = lerp(texY, texTop, topBottomLerp);
#endif
fixed4 tex =
lerp(texX * IN.powerNormal.x, texTop * weightedPowerNormal.x, yLerp)
+ lerp(texY * IN.powerNormal.y, texTop * weightedPowerNormal.y, yLerp)
+ lerp(texZ * IN.powerNormal.z, texTop * weightedPowerNormal.z, yLerp)
;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
o.Albedo = max(fixed3(0.0, 0.0, 0.0), tex.rgb);
o.Alpha = tex.a;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bumpTop = UnpackScaleNormal(tex2D(_TopBumpMap, yUVTop), _TopBumpScale);
bumpTop = lerp(bumpY, bumpTop, topLerp);
#if _UVFREE_BOTTOM
fixed3 bumpBottom = UnpackScaleNormal(tex2D(_BottomBumpMap, yUVBottom), _BottomBumpScale);
bumpBottom = lerp(bumpY, bumpBottom, bottomLerp);
bumpTop = lerp(bumpBottom, bumpTop, topBottomLerp);
#else
bumpTop = lerp(bumpY, bumpTop, topBottomLerp);
#endif
o.Normal = normalize(
lerp(bumpX * IN.powerNormal.x, bumpTop * weightedPowerNormal.x, yLerp)
+ lerp(bumpY * IN.powerNormal.y, bumpTop * weightedPowerNormal.y, yLerp)
+ lerp(bumpZ * IN.powerNormal.z, bumpTop * weightedPowerNormal.z, yLerp)
);
// SPECULAR/GLOSS
//
fixed4 sgX = fixed4(_SpecColor.rgb, _Glossiness);
fixed4 sgY = sgX;
fixed4 sgZ = sgX;
fixed4 sgTop = fixed4(_TopSpecColor.rgb, _TopGlossiness);
#ifdef _UVFREE_BOTTOM
fixed4 sgBottom = fixed4(_BottomSpecColor.rgb, _BottomGlossiness);
#endif
#ifdef _SPECGLOSSMAP
sgX = lerp(sgX, tex2D(_SpecGlossMap, xUV), _UsingSpecGlossMap);
sgY = lerp(sgY, tex2D(_SpecGlossMap, yUV), _UsingSpecGlossMap);
sgZ = lerp(sgZ, tex2D(_SpecGlossMap, zUV), _UsingSpecGlossMap);
#if SHADER_API_D3D9 && _EMISSION
// skip for top and bottom, because there are not enough samplers
#else
sgTop = lerp(sgTop, tex2D(_TopSpecGlossMap, yUVTop), _TopUsingSpecGlossMap);
#ifdef _UVFREE_BOTTOM
sgBottom = lerp(sgBottom, tex2D(_BottomSpecGlossMap, yUVBottom), _BottomUsingSpecGlossMap);
#endif
#endif
#endif
sgTop = lerp(sgY, sgTop, topLerp);
#ifdef _UVFREE_BOTTOM
sgBottom = lerp(sgY, sgBottom, bottomLerp);
sgTop = lerp(sgBottom, sgTop, topBottomLerp);
#else
sgTop = lerp(sgY, sgTop, topBottomLerp);
#endif
fixed4 sg =
lerp(sgX * IN.powerNormal.x, sgTop * weightedPowerNormal.x, yLerp)
+ lerp(sgY * IN.powerNormal.y, sgTop * weightedPowerNormal.y, yLerp)
+ lerp(sgZ * IN.powerNormal.z, sgTop * weightedPowerNormal.z, yLerp)
;
o.Specular = sg.rgb;
o.Smoothness = sg.a;
// EMISSION
//
#ifdef _EMISSION
half3 emissionX = tex2D(_EmissionMap, xUV).rgb * _EmissionColor.rgb;
half3 emissionY = tex2D(_EmissionMap, yUV).rgb * _EmissionColor.rgb;
half3 emissionYTop = tex2D(_TopEmissionMap, yUVTop).rgb * _TopEmissionColor.rgb;
emissionYTop = lerp(emissionY, emissionYTop, topLerp);
#ifdef _UVFREE_BOTTOM
half3 emissionYBottom = tex2D(_BottomEmissionMap, yUVBottom).rgb * _BottomEmissionColor.rgb;
emissionYBottom = lerp(emissionY, emissionYBottom, bottomLerp);
emissionYTop = lerp(emissionYBottom, emissionYTop, topBottomLerp);
#else
emissionYTop = lerp(emissionY, emissionYTop, topBottomLerp);
#endif
half3 emissionZ = tex2D(_EmissionMap, zUV).rgb * _EmissionColor.rgb;
o.Emission +=
lerp(emissionX * IN.powerNormal.x, emissionYTop * weightedPowerNormal.x, yLerp)
+ lerp(emissionY * IN.powerNormal.y, emissionYTop * weightedPowerNormal.y, yLerp)
+ lerp(emissionZ * IN.powerNormal.z, emissionYTop * weightedPowerNormal.z, yLerp)
;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreePBRShaderTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4ab1ec931c54345fbba6c717fb297e9a
timeCreated: 1426831500
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,440 @@
// Upgrade NOTE: upgraded instancing buffer 'MyProperties' to new syntax.
Shader "UVFree/StandardSpecular/Top-Bottom-Texture Non-Batching" {
Properties {
// Triplanar space, for UI
[HideInInspector] _TriplanarSpace("Triplanar Space", Float) = 0.0
_TexPower("Texture Power", Range(0.0, 20.0)) = 10.0
_TopMultiplier ("Top Multiplier", Range(0.0,8.0)) = 1.0
_BottomMultiplier ("Bottom Multiplier", Range(0.0,8.0)) = 0.0
_VertexColorStrength("Vertex Color Strength", Range(0.0,1.0)) = 1.0
// FRONT
_Color ("Color", Color) = (1.0,1.0,1.0,1.0)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_SpecColor("Specular", Color) = (0.2,0.2,0.2)
_SpecGlossMap("Specular", 2D) = "white" {}
_UsingSpecGlossMap("Using Spec Gloss Map", float) = 0.0
_BumpScale("Bump Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_EmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_EmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _EmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _EmissionColorUI("Color", Color) = (1.0,1.0,1.0)
// TOP
_TopColor ("Color", Color) = (1.0,1.0,1.0,1.0)
_TopMainTex ("Albedo (RGB)", 2D) = "white" {}
_TopGlossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_TopSpecColor("Specular", Color) = (0.2,0.2,0.2)
_TopSpecGlossMap("Specular", 2D) = "white" {}
_TopUsingSpecGlossMap("Using Spec Gloss Map", float) = 0.0
_TopBumpScale("Bump Scale", Float) = 1.0
_TopBumpMap("Normal Map", 2D) = "bump" {}
_TopEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_TopEmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _TopEmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _TopEmissionColorUI("Color", Color) = (1,1,1)
// BOTTOM
// bottom is ignored unless _UVFREE_BOTTOM shader feature is turned on
_BottomColor ("Color", Color) = (1.0,1.0,1.0,1.0)
_BottomMainTex ("Albedo (RGB)", 2D) = "white" {}
_BottomGlossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_BottomSpecColor("Specular", Color) = (0.2,0.2,0.2)
_BottomSpecGlossMap("Specular", 2D) = "white" {}
_BottomUsingSpecGlossMap("Using Spec Gloss Map", float) = 0.0
_BottomBumpScale("Bump Scale", Float) = 1.0
_BottomBumpMap("Normal Map", 2D) = "bump" {}
_BottomEmissionColor("Emission Color", Color) = (0.0,0.0,0.0)
_BottomEmissionMap("Emission", 2D) = "white" {}
[HideInInspector] _BottomEmissionScaleUI("Scale", Float) = 0.0
[HideInInspector] _BottomEmissionColorUI("Color", Color) = (1.0,1.0,1.0)
}
SubShader {
Tags {
"RenderType"="Opaque"
"PerformanceChecks"="False"
"DisableBatching"="True"
}
LOD 300
CGPROGRAM
#pragma target 3.0
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf StandardSpecular vertex:vert fullforwardshadows
#pragma shader_feature _UVFREE_LOCAL
#pragma shader_feature _EMISSION
#pragma shader_feature _SPECGLOSSMAP
#pragma shader_feature _UVFREE_BOTTOM
#include "UnityCG.cginc"
// Uncomment to enable experimental feature which flips
// backward textures. Note: Causes some normals to be flipped.
// #define _UVFREE_FLIP_BACKWARD_TEXTURES
// Comment out following line to omit vertex colors
#define _UVFREE_VERTEX_COLOR
// Instanced Properties
// https://docs.unity3d.com/Manual/GPUInstancing.html
UNITY_INSTANCING_BUFFER_START (MyProperties)
UNITY_DEFINE_INSTANCED_PROP(fixed4, _Color)
#define _Color_arr MyProperties
UNITY_INSTANCING_BUFFER_END(MyProperties)
half _TexPower;
// FRONT
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BumpMap;
half _BumpScale;
fixed _Glossiness;
#ifdef _SPECGLOSSMAP
sampler2D _SpecGlossMap;
fixed _UsingSpecGlossMap;
#endif
#ifdef _EMISSION
half4 _EmissionColor;
sampler2D _EmissionMap;
sampler2D _TopEmissionMap;
half4 _TopEmissionColor;
#endif
// TOP
half _TopMultiplier;
fixed4 _TopColor;
sampler2D _TopMainTex;
float4 _TopMainTex_ST;
sampler2D _TopBumpMap;
half _TopBumpScale;
fixed _TopGlossiness;
fixed4 _TopSpecColor;
#ifdef _SPECGLOSSMAP
sampler2D _TopSpecGlossMap;
fixed _TopUsingSpecGlossMap;
#endif
// BOTTOM
#ifdef _UVFREE_BOTTOM
half _BottomMultiplier;
fixed4 _BottomColor;
sampler2D _BottomMainTex;
float4 _BottomMainTex_ST;
sampler2D _BottomBumpMap;
half _BottomBumpScale;
fixed4 _BottomSpecColor;
fixed _BottomGlossiness;
#ifdef _SPECGLOSSMAP
sampler2D _BottomSpecGlossMap;
fixed _BottomUsingSpecGlossMap;
#endif
#ifdef _EMISSION
sampler2D _BottomEmissionMap;
half4 _BottomEmissionColor;
#endif
#endif
#ifdef _UVFREE_VERTEX_COLOR
fixed _VertexColorStrength;
#endif
struct Input {
fixed3 powerNormal;
fixed3 normal;
float3 worldPos;
#ifdef _UVFREE_VERTEX_COLOR
fixed4 color:COLOR;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
};
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
#ifdef _UVFREE_LOCAL
fixed3 powerNormal = v.normal;
o.normal = v.normal;
fixed topFactor = sign(v.normal.y)*0.5+0.5;
fixed3 weightedPowerNormal = v.normal;
#else
fixed3 worldNormal = normalize(mul(unity_ObjectToWorld, fixed4(v.normal, 0.0)).xyz);
o.normal = worldNormal;
fixed3 powerNormal = worldNormal;
fixed3 weightedPowerNormal = worldNormal;
#endif
// texpower sets the sharpness
powerNormal = pow(abs(powerNormal), _TexPower);
powerNormal = max(powerNormal, 0.0001);
powerNormal /= dot(powerNormal, 1.0);
o.powerNormal = powerNormal;
#if _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed3 lerpedPowerNormal = lerp(powerNormal, weightedPowerNormal, weightedPowerNormal.y);
#ifdef _UVFREE_LOCAL
v.tangent.xyz =
cross(v.normal, fixed3(0.0,sign(v.normal.x),0.0)) * (lerpedPowerNormal.x)
+ cross(v.normal, fixed3(0.0,0.0,sign(v.normal.y))) * (lerpedPowerNormal.y)
+ cross(v.normal, fixed3(0.0,sign(v.normal.z),0.0)) * (lerpedPowerNormal.z)
;
v.tangent.w = dot(-v.normal, lerpedPowerNormal);
#else
v.tangent.xyz =
cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.x),0.0,0.0)).xyz * (lerpedPowerNormal.x))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,0.0,sign(worldNormal.y),0.0)).xyz * (lerpedPowerNormal.y))
+ cross(v.normal, mul(unity_WorldToObject,fixed4(0.0,sign(worldNormal.z),0.0,0.0)).xyz * (lerpedPowerNormal.z))
;
v.tangent.w = dot(-worldNormal, lerpedPowerNormal);
#endif
}
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
fixed topLerp = smoothstep(0.0, 1.0, _TopMultiplier);
#if _UVFREE_BOTTOM
fixed bottomLerp = smoothstep(0.0, 1.0, _BottomMultiplier);
#endif
fixed3 weightedPowerNormal = IN.normal;
#if _UVFREE_BOTTOM
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y)*_BottomMultiplier;
#else
weightedPowerNormal.y = max(0.0, weightedPowerNormal.y)*_TopMultiplier + min(0.0, weightedPowerNormal.y);
#endif
weightedPowerNormal = pow(abs(weightedPowerNormal), _TexPower);
weightedPowerNormal = max(weightedPowerNormal, 0.0001);
weightedPowerNormal /= dot(weightedPowerNormal, 1.0);
fixed topBottomLerp = sign(IN.normal.y)*0.5 + 0.5;
fixed yLerp = weightedPowerNormal.y;
// TRIPLANAR UVs BASED ON WORLD OR LOCAL POSITION
//
#ifdef _UVFREE_LOCAL
float3 pos = mul(unity_WorldToObject, float4(IN.worldPos, 1.0)).xyz;
float2 posX = pos.zy;
float2 posY = pos.xz;
float2 posZ = float2(-pos.x, pos.y);
#else
float2 posX = IN.worldPos.zy;
float2 posY = IN.worldPos.xz;
float2 posZ = float2(-IN.worldPos.x, IN.worldPos.y);
#endif
float2 xUV = posX * _MainTex_ST.xy + _MainTex_ST.zw;
float2 yUVTop = posY * _TopMainTex_ST.xy + _TopMainTex_ST.zw;
#ifdef _UVFREE_BOTTOM
float2 yUVBottom = posY * _BottomMainTex_ST.xy + _BottomMainTex_ST.zw;
#endif
float2 yUV = posY * _MainTex_ST.xy + _MainTex_ST.zw;
float2 zUV = posZ * _MainTex_ST.xy + _MainTex_ST.zw;
#ifdef _UVFREE_FLIP_BACKWARD_TEXTURES
fixed3 powerSign = sign(IN.normal);
xUV.x *= powerSign.x;
zUV.x *= powerSign.z;
yUV.y *= powerSign.y;
yUVTop.y *= powerSign.y;
#ifdef _UVFREE_BOTTOM
yUVBottom.y *= powerSign.y;
#endif
#endif
// DIFFUSE
//
fixed4 tint = UNITY_ACCESS_INSTANCED_PROP(_Color_arr, _Color);
fixed4 texX = tex2D(_MainTex, xUV) * tint;
fixed4 texY = tex2D(_MainTex, yUV) * tint;
fixed4 texZ = tex2D(_MainTex, zUV) * tint;
fixed4 texTop = tex2D(_TopMainTex, yUVTop) * _TopColor;
texTop = lerp(texY, texTop, topLerp);
#if _UVFREE_BOTTOM
fixed4 texBottom = tex2D(_BottomMainTex, yUVBottom) * _BottomColor;
texBottom = lerp(texY, texBottom, bottomLerp);
texTop = lerp(texBottom, texTop, topBottomLerp);
#else
texTop = lerp(texY, texTop, topBottomLerp);
#endif
fixed4 tex =
lerp(texX * IN.powerNormal.x, texTop * weightedPowerNormal.x, yLerp)
+ lerp(texY * IN.powerNormal.y, texTop * weightedPowerNormal.y, yLerp)
+ lerp(texZ * IN.powerNormal.z, texTop * weightedPowerNormal.z, yLerp)
;
#ifdef _UVFREE_VERTEX_COLOR
tex *= lerp(fixed4(1.0,1.0,1.0,1.0), IN.color, _VertexColorStrength);
#endif
o.Albedo = max(fixed3(0.0, 0.0, 0.0), tex.rgb);
o.Alpha = tex.a;
// NORMAL
//
fixed3 bumpX = UnpackScaleNormal(tex2D(_BumpMap, xUV), _BumpScale);
fixed3 bumpY = UnpackScaleNormal(tex2D(_BumpMap, yUV), _BumpScale);
fixed3 bumpZ = UnpackScaleNormal(tex2D(_BumpMap, zUV), _BumpScale);
fixed3 bumpTop = UnpackScaleNormal(tex2D(_TopBumpMap, yUVTop), _TopBumpScale);
bumpTop = lerp(bumpY, bumpTop, topLerp);
#if _UVFREE_BOTTOM
fixed3 bumpBottom = UnpackScaleNormal(tex2D(_BottomBumpMap, yUVBottom), _BottomBumpScale);
bumpBottom = lerp(bumpY, bumpBottom, bottomLerp);
bumpTop = lerp(bumpBottom, bumpTop, topBottomLerp);
#else
bumpTop = lerp(bumpY, bumpTop, topBottomLerp);
#endif
o.Normal = normalize(
lerp(bumpX * IN.powerNormal.x, bumpTop * weightedPowerNormal.x, yLerp)
+ lerp(bumpY * IN.powerNormal.y, bumpTop * weightedPowerNormal.y, yLerp)
+ lerp(bumpZ * IN.powerNormal.z, bumpTop * weightedPowerNormal.z, yLerp)
);
// SPECULAR/GLOSS
//
fixed4 sgX = fixed4(_SpecColor.rgb, _Glossiness);
fixed4 sgY = sgX;
fixed4 sgZ = sgX;
fixed4 sgTop = fixed4(_TopSpecColor.rgb, _TopGlossiness);
#ifdef _UVFREE_BOTTOM
fixed4 sgBottom = fixed4(_BottomSpecColor.rgb, _BottomGlossiness);
#endif
#ifdef _SPECGLOSSMAP
sgX = lerp(sgX, tex2D(_SpecGlossMap, xUV), _UsingSpecGlossMap);
sgY = lerp(sgY, tex2D(_SpecGlossMap, yUV), _UsingSpecGlossMap);
sgZ = lerp(sgZ, tex2D(_SpecGlossMap, zUV), _UsingSpecGlossMap);
#if SHADER_API_D3D9 && _EMISSION
// skip for top and bottom, because there are not enough samplers
#else
sgTop = lerp(sgTop, tex2D(_TopSpecGlossMap, yUVTop), _TopUsingSpecGlossMap);
#ifdef _UVFREE_BOTTOM
sgBottom = lerp(sgBottom, tex2D(_BottomSpecGlossMap, yUVBottom), _BottomUsingSpecGlossMap);
#endif
#endif
#endif
sgTop = lerp(sgY, sgTop, topLerp);
#ifdef _UVFREE_BOTTOM
sgBottom = lerp(sgY, sgBottom, bottomLerp);
sgTop = lerp(sgBottom, sgTop, topBottomLerp);
#else
sgTop = lerp(sgY, sgTop, topBottomLerp);
#endif
fixed4 sg =
lerp(sgX * IN.powerNormal.x, sgTop * weightedPowerNormal.x, yLerp)
+ lerp(sgY * IN.powerNormal.y, sgTop * weightedPowerNormal.y, yLerp)
+ lerp(sgZ * IN.powerNormal.z, sgTop * weightedPowerNormal.z, yLerp)
;
o.Specular = sg.rgb;
o.Smoothness = sg.a;
// EMISSION
//
#ifdef _EMISSION
half3 emissionX = tex2D(_EmissionMap, xUV).rgb * _EmissionColor.rgb;
half3 emissionY = tex2D(_EmissionMap, yUV).rgb * _EmissionColor.rgb;
half3 emissionYTop = tex2D(_TopEmissionMap, yUVTop).rgb * _TopEmissionColor.rgb;
emissionYTop = lerp(emissionY, emissionYTop, topLerp);
#ifdef _UVFREE_BOTTOM
half3 emissionYBottom = tex2D(_BottomEmissionMap, yUVBottom).rgb * _BottomEmissionColor.rgb;
emissionYBottom = lerp(emissionY, emissionYBottom, bottomLerp);
emissionYTop = lerp(emissionYBottom, emissionYTop, topBottomLerp);
#else
emissionYTop = lerp(emissionY, emissionYTop, topBottomLerp);
#endif
half3 emissionZ = tex2D(_EmissionMap, zUV).rgb * _EmissionColor.rgb;
o.Emission +=
lerp(emissionX * IN.powerNormal.x, emissionYTop * weightedPowerNormal.x, yLerp)
+ lerp(emissionY * IN.powerNormal.y, emissionYTop * weightedPowerNormal.y, yLerp)
+ lerp(emissionZ * IN.powerNormal.z, emissionYTop * weightedPowerNormal.z, yLerp)
;
#endif
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "UVFreePBRShaderTopBottomGUI"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a18eb636b612d497bb0afa0ce8c67b12
timeCreated: 1426831500
licenseType: Store
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant: