type shit
This commit is contained in:
@@ -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:
|
||||
@@ -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:
|
||||
@@ -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"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f12406e1126a444b79fee18cce430514
|
||||
timeCreated: 1427690221
|
||||
licenseType: Store
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
Reference in New Issue
Block a user