アセット選定
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// URP uses _half
|
||||
|
||||
void CTIBillboardFragment_half (
|
||||
in float4 UV,
|
||||
in real2 BlendCv,
|
||||
in float4 ScreenPosRaw,
|
||||
|
||||
out real3 o_Albedo,
|
||||
out real o_Alpha,
|
||||
out real3 o_NormalTS,
|
||||
out real o_Smoothness,
|
||||
out real o_Occlusion,
|
||||
out real o_Thickness
|
||||
) {
|
||||
|
||||
|
||||
real4 sampleA = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, UV.xy);
|
||||
real4 n_sampleA = SAMPLE_TEXTURE2D(_BumpSpecMap, sampler_BumpSpecMap, UV.xy);
|
||||
|
||||
real blend = saturate(1.0 - BlendCv.x);
|
||||
|
||||
if (_BlendBB)
|
||||
{
|
||||
real4 sampleB = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, UV.zw);
|
||||
real4 n_sampleB = SAMPLE_TEXTURE2D(_BumpSpecMap, sampler_BumpSpecMap, UV.zw);
|
||||
|
||||
// Dither
|
||||
if (_BlendBBDithering)
|
||||
{
|
||||
float2 screenPos = floor( (ScreenPosRaw.xy / ScreenPosRaw.w) * _ScreenParams.xy);
|
||||
real alphaClip = InterleavedGradientNoise(float4(screenPos, ScreenPosRaw.zw), (real)0.0);
|
||||
// real alphaClip = GenerateHashedRandomFloat( asuint((int2)screenPos.xy) );
|
||||
|
||||
real blend = BlendCv.x;
|
||||
blend = saturate( ((real)1.0 - blend - alphaClip) * (real)1000.0);
|
||||
}
|
||||
|
||||
sampleA.a = sampleA.a * blend;
|
||||
sampleB.a = sampleB.a * (1.0 - blend);
|
||||
|
||||
sampleA.rgb = sampleA.rgb * blend;
|
||||
sampleA.rgb += sampleB.rgb * (1.0 - blend);
|
||||
|
||||
//n_sampleA = n_sampleA * blend + n_sampleB * (1.0 - blend); // Needs dithering!
|
||||
n_sampleA = lerp(n_sampleA, n_sampleB, sampleB.aaaa);
|
||||
|
||||
sampleA.a += sampleB.a;
|
||||
}
|
||||
|
||||
// Up is flipped!
|
||||
n_sampleA.g = 1.0 - n_sampleA.g;
|
||||
real3 normalTS = UnpackNormalAG(n_sampleA, _BumpScale);
|
||||
|
||||
// Alpha Leak
|
||||
o_Occlusion = (sampleA.a <= _AlphaLeak) ? (real)1.0 : sampleA.a; // Eliminate alpha leaking into ao
|
||||
|
||||
// Add Color Variation
|
||||
o_Albedo = lerp(sampleA.rgb, (sampleA.rgb + _HueVariation.rgb) * (real)0.5, (BlendCv.y * _HueVariation.a).xxx );
|
||||
o_Alpha = sampleA.a;
|
||||
o_NormalTS = normalTS;
|
||||
o_Smoothness = n_sampleA.b * _Smoothness;
|
||||
o_Thickness = n_sampleA.r * _ThicknessRemap;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 068055334d98c4f488fc319e9ee2ed4f
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,148 @@
|
||||
// Not needed as we use our own calculation for eyevec!
|
||||
|
||||
// CBUFFER_START(UnityBillboardPerCamera)
|
||||
// float3 unity_BillboardNormal;
|
||||
// float3 unity_BillboardTangent;
|
||||
// float4 unity_BillboardCameraParams;
|
||||
// #define unity_BillboardCameraPosition (unity_BillboardCameraParams.xyz)
|
||||
// #define unity_BillboardCameraXZAngle (unity_BillboardCameraParams.w)
|
||||
// CBUFFER_END
|
||||
|
||||
CBUFFER_START(UnityBillboardPerBatch)
|
||||
float3 unity_BillboardSize;
|
||||
CBUFFER_END
|
||||
|
||||
float4 _CTI_SRP_Wind;
|
||||
float _CTI_SRP_Turbulence;
|
||||
|
||||
#if defined(_PARALLAXMAP)
|
||||
float2 _CTI_TransFade;
|
||||
#endif
|
||||
|
||||
|
||||
float4 SmoothCurve(float4 x) {
|
||||
return x * x * (3.0 - 2.0 * x);
|
||||
}
|
||||
|
||||
float4 TriangleWave(float4 x) {
|
||||
return abs(frac(x + 0.5) * 2.0 - 1.0);
|
||||
}
|
||||
|
||||
float4 SmoothTriangleWave(float4 x) {
|
||||
return (SmoothCurve(TriangleWave(x)) - 0.5) * 2.0;
|
||||
}
|
||||
|
||||
// Billboard Vertex Function
|
||||
void CTI_BillboardVert_float (
|
||||
float3 positionOS,
|
||||
float2 texcoord,
|
||||
float3 texcoord1,
|
||||
|
||||
// float3 lightDir,
|
||||
|
||||
out float3 o_positionOS,
|
||||
out real3 o_normalOS,
|
||||
out real3 o_tangentOS,
|
||||
out float4 o_uv,
|
||||
out real2 o_cv
|
||||
)
|
||||
{
|
||||
|
||||
float3 position = positionOS;
|
||||
float3 positionWS = positionOS + UNITY_MATRIX_M._m03_m13_m23;
|
||||
|
||||
// Store Color Variation
|
||||
//float3 TreeWorldPos = abs(positionWS.xyz * 0.125f);
|
||||
o_cv.y = saturate((frac(positionWS.x + positionWS.y + positionWS.z) + frac((positionWS.x + positionWS.y + positionWS.z) * 3.3)) * 0.5);
|
||||
|
||||
// ////////////////////////////////////
|
||||
// Set vertex position
|
||||
// #if (SHADERPASS == SHADERPASS_SHADOWCASTER)
|
||||
// float3 eyeVec = -lightDir; //normalize(GetCurrentViewPosition() - positionWS);
|
||||
// #else
|
||||
// float3 eyeVec = normalize(_WorldSpaceCameraPos - positionWS);
|
||||
// #endif
|
||||
// Shadows go nuts:
|
||||
// float3 eyeVec = normalize(unity_BillboardCameraPosition - positionWS);
|
||||
|
||||
// So we do it manually
|
||||
// We do not have access to _LightDirection or _LightPosition as these are defined later in code...
|
||||
#if (SHADERPASS == SHADERPASS_SHADOWCASTER)
|
||||
#define cameraForward UNITY_MATRIX_V[2].xyz
|
||||
#if _CASTING_PUNCTUAL_LIGHT_SHADOW
|
||||
// Matches HDRP GetCurrentViewPosition()
|
||||
float3 eyeVec = normalize(UNITY_MATRIX_I_V._14_24_34 - positionWS); // normalize(_LightPosition - worldPos);
|
||||
#else
|
||||
float3 eyeVec = cameraForward; // _LightDirection;
|
||||
#endif
|
||||
#else
|
||||
float3 eyeVec = GetWorldSpaceNormalizeViewDir(positionWS);
|
||||
#endif
|
||||
|
||||
// NOTE: We have incorrect triangle winding...
|
||||
float3 billboardTangent = normalize(float3(-eyeVec.z, 0, eyeVec.x));
|
||||
real3 billboardNormal = real3(billboardTangent.z, 0, -billboardTangent.x);
|
||||
float2 percent = texcoord.xy;
|
||||
float3 billboardPos = (percent.x - 0.5) * unity_BillboardSize.x * texcoord1.x * billboardTangent;
|
||||
billboardPos.y += (percent.y * unity_BillboardSize.y + unity_BillboardSize.z) * texcoord1.y;
|
||||
|
||||
// Wind - make sure we apply it in "object space" (use billboardPos)
|
||||
if (_WindStrength > 0)
|
||||
{
|
||||
float origLength = length(billboardPos);
|
||||
float sinuswave = _SinTime.z;
|
||||
float4 vOscillations = SmoothTriangleWave(float4(positionWS.x + sinuswave, positionWS.z + sinuswave * 0.8, 0.0, 0.0));
|
||||
float fOsc = vOscillations.x + (vOscillations.y * vOscillations.y);
|
||||
fOsc = 0.75 + (fOsc + 3.33) * 0.33;
|
||||
// saturate added to stop warning on dx11...
|
||||
float percentage = pow(saturate(percent.y), _WindPower); // pow(y,1.5) matches the wind baked to the mesh trees
|
||||
billboardPos.xyz += _CTI_SRP_Wind.xyz * ( _CTI_SRP_Wind.w * _WindStrength * fOsc * percentage );
|
||||
billboardPos = normalize(billboardPos) * origLength;
|
||||
}
|
||||
|
||||
// Now bring it to the proper position
|
||||
position.xyz += billboardPos;
|
||||
o_positionOS.xyz = position.xyz;
|
||||
|
||||
// ////////////////////////////////////
|
||||
// Get billboard texture coords
|
||||
o_uv = 0.0;
|
||||
o_cv.x = 0.0;
|
||||
|
||||
float angle = atan2(billboardNormal.z, billboardNormal.x); // signed angle between billboardNormal to {0,0,1}
|
||||
angle += angle < 0 ? 2 * PI : 0;
|
||||
// Set Rotation
|
||||
angle += texcoord1.z;
|
||||
// Write final billboard texture coords
|
||||
const float invDelta = 1.0 / (45.0 * ((PI * 2.0) / 360.0));
|
||||
float imageIndex = fmod(floor(angle * invDelta + 0.5f), 8.0);
|
||||
float2 column_row;
|
||||
column_row.x = imageIndex * 0.25;
|
||||
column_row.y = saturate(4.0 - imageIndex) * 0.5;
|
||||
o_uv.xy = column_row + texcoord.xy * float2(0.25, 0.5);
|
||||
|
||||
// /////////////////////////
|
||||
if (_BlendBB)
|
||||
{
|
||||
float percentage = frac(angle / (PI / 4));
|
||||
// So percentage 0 - 1: 0 - 0.5 = next texture / 0.5 - 1 prev texture
|
||||
imageIndex = (percentage < 0.5) ? imageIndex + 1.0 : imageIndex - 1.0;
|
||||
// Needed!
|
||||
imageIndex = (imageIndex < 0.0) ? 7.0 : imageIndex;
|
||||
imageIndex = (imageIndex > 7.0) ? 0.0 : imageIndex;
|
||||
|
||||
column_row.x = imageIndex * 0.25; // we do not care about the horizontal coord that much as our billboard texture tiles
|
||||
column_row.y = saturate(4.0 - imageIndex) * 0.5;
|
||||
o_uv.zw = column_row + texcoord.xy * float2(0.25, 0.5);
|
||||
|
||||
// Set Blend value
|
||||
o_cv.x = (percentage < 0.5) ? (percentage * 2.0) : (1.0 - percentage * 2.0);
|
||||
//o_cv.x = smoothstep (0, 1, o_cv.x); // Nope
|
||||
}
|
||||
|
||||
// ////////////////////////////////////
|
||||
// Set Normal and Tangent
|
||||
o_normalOS = billboardNormal.xyz;
|
||||
// We have to fix normalTS in pixel shader as up is flipped!?
|
||||
o_tangentOS = billboardTangent.xyz;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 135f75a97ae2e2e43b2cc94a2ee0898d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,135 @@
|
||||
// Not needed as we use our own calculation for eyevec!
|
||||
|
||||
// CBUFFER_START(UnityBillboardPerCamera)
|
||||
// float3 unity_BillboardNormal;
|
||||
// float3 unity_BillboardTangent;
|
||||
// float4 unity_BillboardCameraParams;
|
||||
// #define unity_BillboardCameraPosition (unity_BillboardCameraParams.xyz)
|
||||
// #define unity_BillboardCameraXZAngle (unity_BillboardCameraParams.w)
|
||||
// CBUFFER_END
|
||||
|
||||
CBUFFER_START(UnityBillboardPerBatch)
|
||||
float3 unity_BillboardSize;
|
||||
CBUFFER_END
|
||||
|
||||
float4 _CTI_SRP_Wind;
|
||||
float _CTI_SRP_Turbulence;
|
||||
|
||||
#if defined(_PARALLAXMAP)
|
||||
float2 _CTI_TransFade;
|
||||
#endif
|
||||
|
||||
|
||||
float4 SmoothCurve(float4 x) {
|
||||
return x * x * (3.0 - 2.0 * x);
|
||||
}
|
||||
|
||||
float4 TriangleWave(float4 x) {
|
||||
return abs(frac(x + 0.5) * 2.0 - 1.0);
|
||||
}
|
||||
|
||||
float4 SmoothTriangleWave(float4 x) {
|
||||
return (SmoothCurve(TriangleWave(x)) - 0.5) * 2.0;
|
||||
}
|
||||
|
||||
// Billboard Vertex Function
|
||||
void CTI_BillboardVert_float (
|
||||
float3 positionOS,
|
||||
float2 texcoord,
|
||||
float3 texcoord1,
|
||||
|
||||
// float3 lightDir,
|
||||
|
||||
out float3 o_positionOS,
|
||||
out half3 o_normalOS,
|
||||
out half3 o_tangentOS,
|
||||
out float2 o_uv,
|
||||
out float o_cv
|
||||
)
|
||||
{
|
||||
|
||||
float3 position = positionOS;
|
||||
float3 positionWS = positionOS + UNITY_MATRIX_M._m03_m13_m23;
|
||||
|
||||
// Store Color Variation
|
||||
//float3 TreeWorldPos = abs(positionWS.xyz * 0.125f);
|
||||
o_cv = saturate((frac(positionWS.x + positionWS.y + positionWS.z) + frac((positionWS.x + positionWS.y + positionWS.z) * 3.3)) * 0.5);
|
||||
|
||||
// #if defined(_PARALLAXMAP)
|
||||
// float3 distVec = _WorldSpaceCameraPos - positionWS;
|
||||
// float distSq = dot(distVec, distVec);
|
||||
// o_UvColorVariationStipple.w = saturate( (_CTI_TransFade.x - distSq) / _CTI_TransFade.y);
|
||||
// #endif
|
||||
|
||||
// ////////////////////////////////////
|
||||
// Set vertex position
|
||||
// #if (SHADERPASS == SHADERPASS_SHADOWCASTER)
|
||||
// float3 eyeVec = -lightDir; //normalize(GetCurrentViewPosition() - positionWS);
|
||||
// #else
|
||||
// float3 eyeVec = normalize(_WorldSpaceCameraPos - positionWS);
|
||||
// #endif
|
||||
// Shadows go nuts:
|
||||
// float3 eyeVec = normalize(unity_BillboardCameraPosition - positionWS);
|
||||
|
||||
// So we do it manually
|
||||
// We do not have access to _LightDirection or _LightPosition as these are defined later in code...
|
||||
#if (SHADERPASS == SHADERPASS_SHADOWCASTER)
|
||||
#define cameraForward UNITY_MATRIX_V[2].xyz
|
||||
#if _CASTING_PUNCTUAL_LIGHT_SHADOW
|
||||
// Matches HDRP GetCurrentViewPosition()
|
||||
float3 eyeVec = normalize(UNITY_MATRIX_I_V._14_24_34 - positionWS); // normalize(_LightPosition - worldPos);
|
||||
#else
|
||||
float3 eyeVec = cameraForward; // _LightDirection;
|
||||
#endif
|
||||
#else
|
||||
float3 eyeVec = GetWorldSpaceNormalizeViewDir(positionWS);
|
||||
#endif
|
||||
|
||||
// NOTE: We have incorrect triangle winding...
|
||||
float3 billboardTangent = normalize(float3(-eyeVec.z, 0, eyeVec.x));
|
||||
float3 billboardNormal = float3(billboardTangent.z, 0, -billboardTangent.x);
|
||||
float2 percent = texcoord.xy;
|
||||
float3 billboardPos = (percent.x - 0.5) * unity_BillboardSize.x * texcoord1.x * billboardTangent;
|
||||
billboardPos.y += (percent.y * unity_BillboardSize.y + unity_BillboardSize.z) * texcoord1.y;
|
||||
|
||||
// Wind
|
||||
// Make sure we apply it in "object space" (use billboardPos)
|
||||
if (_WindStrength > 0)
|
||||
{
|
||||
//positionWS.xyz = abs(positionWS.xyz * 0.125f);
|
||||
float origLength = length(billboardPos);
|
||||
float sinuswave = _SinTime.z;
|
||||
float4 vOscillations = SmoothTriangleWave(float4(positionWS.x + sinuswave, positionWS.z + sinuswave * 0.8, 0.0, 0.0));
|
||||
float fOsc = vOscillations.x + (vOscillations.y * vOscillations.y);
|
||||
fOsc = 0.75 + (fOsc + 3.33) * 0.33;
|
||||
// saturate added to stop warning on dx11...
|
||||
float percentage = pow(saturate(percent.y), _WindPower); // pow(y,1.5) matches the wind baked to the mesh trees
|
||||
billboardPos.xyz += _CTI_SRP_Wind.xyz * ( _CTI_SRP_Wind.w * _WindStrength * fOsc * percentage );
|
||||
billboardPos = normalize(billboardPos) * origLength;
|
||||
}
|
||||
|
||||
// Now bring it to the proper position
|
||||
position.xyz += billboardPos;
|
||||
o_positionOS.xyz = position.xyz;
|
||||
|
||||
|
||||
// ////////////////////////////////////
|
||||
// Get billboard texture coords
|
||||
float angle = atan2(billboardNormal.z, billboardNormal.x); // signed angle between billboardNormal to {0,0,1}
|
||||
angle += angle < 0 ? 2 * PI : 0;
|
||||
// Set Rotation
|
||||
angle += texcoord1.z;
|
||||
// Write final billboard texture coords
|
||||
const float invDelta = 1.0 / (45.0 * ((PI * 2.0) / 360.0));
|
||||
float imageIndex = fmod(floor(angle * invDelta + 0.5f), 8.0);
|
||||
float2 column_row;
|
||||
column_row.x = imageIndex * 0.25;
|
||||
column_row.y = saturate(4.0 - imageIndex) * 0.5;
|
||||
o_uv.xy = column_row + texcoord.xy * float2(0.25, 0.5);
|
||||
|
||||
// ////////////////////////////////////
|
||||
// Set Normal and Tangent
|
||||
o_normalOS = billboardNormal.xyz;
|
||||
// We have to fix normalTS in pixel shader as up is flipped!?
|
||||
o_tangentOS = billboardTangent.xyz;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a599a3b81d0717d44a255d53c65784ed
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
void CTI_SimpleTranslucentLighting_half(
|
||||
float3 PositionWS,
|
||||
half3 NormalWS,
|
||||
half3 TangentWS,
|
||||
half3 BitangentWS,
|
||||
|
||||
half3 Albedo,
|
||||
half3 NormalTS,
|
||||
half3 Transmission,
|
||||
half TransmissionMask,
|
||||
|
||||
half Occlusion,
|
||||
|
||||
out half3 o_NormalWS,
|
||||
out half3 o_Transmission
|
||||
)
|
||||
{
|
||||
#ifdef SHADERGRAPH_PREVIEW
|
||||
o_NormalWS = half3(0,1,0);
|
||||
o_Transmission = 0;
|
||||
#else
|
||||
|
||||
half3 translucency = 1;
|
||||
half3 viewDirWS = GetWorldSpaceNormalizeViewDir(PositionWS);
|
||||
half3x3 tangentToWorld = half3x3(TangentWS, BitangentWS, NormalWS);
|
||||
o_NormalWS = NormalizeNormalPerPixel(TransformTangentToWorld(NormalTS, tangentToWorld));
|
||||
|
||||
half4 shadowCoord = TransformWorldToShadowCoord(PositionWS);
|
||||
Light mainLight = GetMainLight(shadowCoord);
|
||||
|
||||
half w = 0.3; // 0.4
|
||||
half NdotL = saturate((dot(o_NormalWS, mainLight.direction) + w) / ((1 + w) * (1 + w)));
|
||||
|
||||
half3 transLightDir = mainLight.direction + o_NormalWS * Transmission.z;
|
||||
half transDot = dot( transLightDir, -viewDirWS );
|
||||
transDot = exp2(saturate(transDot) * Transmission.y - Transmission.y);
|
||||
o_Transmission = transDot * (1.0 - NdotL) * mainLight.color * mainLight.shadowAttenuation * Transmission.x;
|
||||
|
||||
if(_AmbientTranslucency > 0)
|
||||
{
|
||||
o_Transmission += SampleSH(-o_NormalWS) * _AmbientTranslucency * Occlusion;
|
||||
}
|
||||
|
||||
o_Transmission *= Albedo * TransmissionMask;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void SampleSH(half3 normalWS, out half3 Ambient)
|
||||
{
|
||||
// LPPV is not supported in Ligthweight Pipeline
|
||||
real4 SHCoefficients[7];
|
||||
SHCoefficients[0] = unity_SHAr;
|
||||
SHCoefficients[1] = unity_SHAg;
|
||||
SHCoefficients[2] = unity_SHAb;
|
||||
SHCoefficients[3] = unity_SHBr;
|
||||
SHCoefficients[4] = unity_SHBg;
|
||||
SHCoefficients[5] = unity_SHBb;
|
||||
SHCoefficients[6] = unity_SHC;
|
||||
|
||||
Ambient = max(half3(0, 0, 0), SampleSH9(SHCoefficients, normalWS));
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f091e92bb3c3a8346a1a082b1b1260dc
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
void CTI_ShadowFade_half(
|
||||
half alpha,
|
||||
out half o_alpha
|
||||
)
|
||||
{
|
||||
#if (SHADERPASS == SHADERPASS_SHADOWS)
|
||||
o_alpha = 1.0;
|
||||
#else
|
||||
o_alpha = alpha;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CTI_ColorVariation_half(
|
||||
half3 Albedo,
|
||||
half4 ColorVariation,
|
||||
half ColorVariationStrength,
|
||||
|
||||
out half3 o_Albedo
|
||||
)
|
||||
{
|
||||
o_Albedo = lerp(Albedo, (Albedo + ColorVariation.rgb) * 0.5, (ColorVariationStrength * ColorVariation.a).xxx );
|
||||
}
|
||||
|
||||
void CTI_UnpackFixNormal_half(
|
||||
half4 normalSample,
|
||||
half normalScale,
|
||||
float isFrontFace,
|
||||
out half3 o_normalTS
|
||||
)
|
||||
{
|
||||
o_normalTS = UnpackNormalAG(normalSample, normalScale);
|
||||
o_normalTS.z *= isFrontFace ? 1 : -1;
|
||||
}
|
||||
|
||||
void CTI_UnpackNormal_half(
|
||||
half4 normalSample,
|
||||
half normalScale,
|
||||
out half3 o_normalTS
|
||||
)
|
||||
{
|
||||
o_normalTS = UnpackNormalAG(normalSample, normalScale);
|
||||
}
|
||||
|
||||
void CTI_UnpackNormalBillboard_half(
|
||||
half4 normalSample,
|
||||
half normalScale,
|
||||
out half3 o_normalTS
|
||||
)
|
||||
{
|
||||
// Up is flipped!
|
||||
normalSample.g = 1 - normalSample.g;
|
||||
o_normalTS = UnpackNormalAG(normalSample, normalScale);
|
||||
}
|
||||
|
||||
void CTI_AlphaLeak_half(
|
||||
half alphaSample,
|
||||
half leak,
|
||||
out half o_Occlusion
|
||||
)
|
||||
{
|
||||
o_Occlusion = (alphaSample <= leak) ? 1 : alphaSample; // Eliminate alpha leaking into ao
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5d97cde99a37644e83755790f752d33
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,271 @@
|
||||
float4 _CTI_SRP_Wind;
|
||||
float _CTI_SRP_Turbulence;
|
||||
|
||||
float3x3 GetRotationMatrix(float3 axis, float angle)
|
||||
{
|
||||
//axis = normalize(axis); // moved to calling function
|
||||
float s = sin(angle);
|
||||
float c = cos(angle);
|
||||
float oc = 1.0 - c;
|
||||
|
||||
return float3x3 (oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s,
|
||||
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s,
|
||||
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c);
|
||||
}
|
||||
|
||||
float4 SmoothCurve( float4 x ) {
|
||||
return x * x *( 3.0 - 2.0 * x );
|
||||
}
|
||||
float4 TriangleWave( float4 x ) {
|
||||
return abs( frac( x + 0.5 ) * 2.0 - 1.0 );
|
||||
}
|
||||
float4 SmoothTriangleWave( float4 x ) {
|
||||
return SmoothCurve( TriangleWave( x ) );
|
||||
}
|
||||
// Overloads for single float
|
||||
float SmoothCurve( float x ) {
|
||||
return x * x *( 3.0 - 2.0 * x );
|
||||
}
|
||||
float TriangleWave( float x ) {
|
||||
return abs( frac( x + 0.5 ) * 2.0 - 1.0 );
|
||||
}
|
||||
float SmoothTriangleWave( float x ) {
|
||||
return SmoothCurve( TriangleWave( x ) );
|
||||
}
|
||||
|
||||
half3 CTI_UnpackScaleNormal(half4 packednormal, half bumpScale)
|
||||
{
|
||||
half3 normal;
|
||||
normal.xy = (packednormal.wy * 2 - 1);
|
||||
#if (SHADER_TARGET >= 30)
|
||||
// SM2.0: instruction count limitation
|
||||
// SM2.0: normal scaler is not supported
|
||||
normal.xy *= bumpScale;
|
||||
#endif
|
||||
normal.z = sqrt(1.0f - saturate(dot(normal.xy, normal.xy)));
|
||||
return normal;
|
||||
}
|
||||
|
||||
float4 AfsSmoothTriangleWave( float4 x ) {
|
||||
return (SmoothCurve( TriangleWave( x )) - 0.5f) * 2.0f;
|
||||
}
|
||||
|
||||
void CTI_AnimateVertexSG_float(
|
||||
float3 PositionOS,
|
||||
half3 NormalOS,
|
||||
half4 VertexColor,
|
||||
float2 UV2,
|
||||
float3 UV3,
|
||||
|
||||
float leafNoise,
|
||||
|
||||
float3 baseWindMultipliers,
|
||||
|
||||
bool enableNormalRotation,
|
||||
|
||||
bool EnableAdvancedEdgeBending,
|
||||
float2 AdvancedEdgeBending,
|
||||
|
||||
float3 timeParams,
|
||||
|
||||
bool IsLeaves,
|
||||
|
||||
out float3 o_positionOS,
|
||||
out half3 o_normalOS,
|
||||
out half2 o_colorVariationAmbient
|
||||
|
||||
) {
|
||||
const float fDetailAmp = 0.1f;
|
||||
const float fBranchAmp = 0.3f;
|
||||
|
||||
#define Phase animParams.r
|
||||
#define Flutter animParams.g
|
||||
#define MainBending animParams.z
|
||||
#define BranchBending animParams.w
|
||||
|
||||
float4 animParams = float4(VertexColor.rg, UV2.xy);
|
||||
animParams.zwy *= baseWindMultipliers.xyz;
|
||||
|
||||
// Init output
|
||||
o_positionOS = PositionOS;
|
||||
o_normalOS = NormalOS;
|
||||
// Store ambient occlusion
|
||||
o_colorVariationAmbient = 0;
|
||||
|
||||
const float3 TreeWorldPos = UNITY_MATRIX_M._m03_m13_m23;
|
||||
|
||||
float sinuswave = sin(timeParams.x * 0.5);
|
||||
float shiftedsinuswave = (sinuswave + timeParams.y) * 0.5;
|
||||
|
||||
//#if defined (_LEAFTUMBLING)
|
||||
// float shiftedsinuswave = sin(_Time.y * 0.5 + _TimeOffset);
|
||||
// float4 vOscillations = SmoothTriangleWave(float4(TreeWorldPos.x + sinuswave, TreeWorldPos.z + sinuswave * 0.7, TreeWorldPos.x + shiftedsinuswave, TreeWorldPos.z + shiftedsinuswave * 0.8));
|
||||
//#else
|
||||
float4 vOscillations = SmoothTriangleWave(float4(TreeWorldPos.x + sinuswave, TreeWorldPos.z + sinuswave * 0.7, TreeWorldPos.x + shiftedsinuswave, TreeWorldPos.z + shiftedsinuswave * 0.8));
|
||||
//#endif
|
||||
|
||||
// x used for main wind bending / y used for tumbling
|
||||
float2 fOsc = vOscillations.xz + (vOscillations.yw * vOscillations.yw);
|
||||
fOsc = 0.75 + (fOsc + 3.33) * 0.33;
|
||||
|
||||
// float fObjPhase = abs(frac((TreeWorldPos.x + TreeWorldPos.z) * 0.5) * 2 - 1);
|
||||
// NOTE: We have to limit (frac) fObjPhase in case we use fBranchPhase in tumbling or turbulence
|
||||
float fObjPhase = dot(TreeWorldPos, 1);
|
||||
float fBranchPhase = fObjPhase + Phase;
|
||||
float fVtxPhase = dot(o_positionOS.xyz, Flutter + fBranchPhase);
|
||||
|
||||
// x is used for edges; y is used for branches
|
||||
float2 vWavesIn = timeParams.xx + float2(fVtxPhase, fBranchPhase );
|
||||
|
||||
// 1.975, 0.793, 0.375, 0.193 are good frequencies
|
||||
float4 vWaves = (frac( vWavesIn.xxyy * float4(1.975, 0.793, 0.375, 0.193) ) * 2.0 - 1.0);
|
||||
vWaves = SmoothTriangleWave( vWaves );
|
||||
float2 vWavesSum = vWaves.xz + vWaves.yw;
|
||||
|
||||
// Get local Wind
|
||||
#define absWindStrength _CTI_SRP_Wind.w
|
||||
|
||||
float turbulence = _CTI_SRP_Turbulence;
|
||||
float3 windDir = mul((float3x3)GetWorldToObjectMatrix(), _CTI_SRP_Wind.xyz);
|
||||
float4 Wind = float4(windDir, absWindStrength);
|
||||
|
||||
// Leaf specific bending
|
||||
if (IsLeaves)
|
||||
{
|
||||
float3 pivot;
|
||||
|
||||
// Decode UV3
|
||||
// 15bit compression 2 components only, important: sign of y
|
||||
pivot.xz = (frac(float2(1.0f, 32768.0f) * UV3.xx) * 2) - 1;
|
||||
pivot.y = sqrt(1 - saturate(dot(pivot.xz, pivot.xz)));
|
||||
pivot *= UV3.y;
|
||||
|
||||
half tumbleInfluence = frac(VertexColor.b * 2.0);
|
||||
|
||||
// Move point to 0,0,0
|
||||
o_positionOS.xyz -= pivot;
|
||||
|
||||
#if defined(_LEAFTUMBLING) || defined (_LEAFTURBULENCE)
|
||||
|
||||
float3 fracs = frac(pivot * 33.3);
|
||||
|
||||
//float offset = fracs.x + fracs.y + fracs.z; // /* this adds a lot of noise, so we use * 0.1 */ + (BranchBending + Phase) * leafNoise;
|
||||
|
||||
float offset = fracs.x + fracs.y + fracs.z /* this adds a lot of noise, so we use * 0.1 */ + (BranchBending + Phase) * leafNoise;
|
||||
float tFrequency = _TumbleFrequency * (timeParams.x + fObjPhase * 10.0 );
|
||||
float4 vWaves1 = SmoothTriangleWave( float4( (tFrequency + offset) * (1.0 + offset * 0.25), tFrequency * 0.75 + offset, tFrequency * 0.5 + offset, tFrequency * 1.5 + offset));
|
||||
|
||||
float3 windTangent = float3(-windDir.z, windDir.y, windDir.x);
|
||||
float twigPhase = vWaves1.x + vWaves1.y + (vWaves1.z * vWaves1.z);
|
||||
|
||||
#define packedBranchAxis UV3.z
|
||||
|
||||
//#if defined (_EMISSION)
|
||||
// This was the root of the fern issue: branchAxes slightly varied on different LODs!
|
||||
float3 branchAxis = frac( packedBranchAxis * float3(1.0, 256.0, 65536.0) );
|
||||
branchAxis = branchAxis * 2.0 - 1.0;
|
||||
branchAxis = normalize(branchAxis);
|
||||
// we can do better in case we have the baked branch main axis
|
||||
float facingWind = (dot(branchAxis, windDir));
|
||||
//#else
|
||||
// half facingWind = (dot(normalize(float3(v.positionOS.x, 0, v.positionOS.z)), windDir)); //saturate
|
||||
//#endif
|
||||
|
||||
|
||||
|
||||
//float localWindStrength = dot(abs(xWind.xyz), 1) * tumbleInfluence * (1.35 - facingWind) * xWind.w + absWindStrength; // Use abs(_Wind)!!!!!!
|
||||
half localWindStrength = (1.35h - facingWind) * tumbleInfluence * absWindStrength;
|
||||
|
||||
// tumbling
|
||||
#if defined(_LEAFTUMBLING)
|
||||
// float angleTumble =
|
||||
// (twigPhase + fBranchPhase * 0.25 + BranchBending)
|
||||
// * localWindStrength * tumbleStrength
|
||||
// * fOsc.y
|
||||
// ;
|
||||
// Let's keep it simple
|
||||
float angleTumble = (twigPhase + BranchBending) * localWindStrength * _TumbleStrength;
|
||||
|
||||
float3x3 tumbleRot = GetRotationMatrix( windTangent, angleTumble);
|
||||
o_positionOS.xyz = mul(tumbleRot, o_positionOS.xyz);
|
||||
if(enableNormalRotation)
|
||||
{
|
||||
o_normalOS = mul(tumbleRot, o_normalOS);
|
||||
}
|
||||
#endif
|
||||
|
||||
// turbulence
|
||||
#if defined (_LEAFTURBULENCE)
|
||||
// float angleTurbulence =
|
||||
// // center rotation so the leaves rotate leftwards as well as rightwards according to the incoming waves
|
||||
// ((twigPhase + vWaves1.w) * 0.25 - 0.5)
|
||||
// // make rotation strength depend on absWindStrength and all other inputs
|
||||
// * localWindStrength * leafTurbulence * saturate(lerp(1.0, Flutter * 8.0, _EdgeFlutterInfluence))
|
||||
// * fOsc.x
|
||||
// ;
|
||||
// Let's keep it simple
|
||||
float angleTurbulence =
|
||||
((twigPhase + vWaves1.w) * 0.25 - 0.5)
|
||||
* localWindStrength * _LeafTurbulence * saturate(lerp(1.0, Flutter * 8.0, _EdgeFlutterInfluence))
|
||||
;
|
||||
|
||||
float3x3 turbulenceRot = GetRotationMatrix( -branchAxis, angleTurbulence);
|
||||
o_positionOS.xyz = mul(turbulenceRot, o_positionOS.xyz);
|
||||
if(enableNormalRotation)
|
||||
{
|
||||
o_normalOS = mul(turbulenceRot, NormalOS);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// fade in/out leave planes
|
||||
// float lodfade = ceil(pos.w - 0.51);
|
||||
// asset store
|
||||
// float lodfade = (pos.w > 0.5) ? 1 : 0;
|
||||
// latest
|
||||
if (unity_LODFade.x < 1.0)
|
||||
{
|
||||
float lodfade = (VertexColor.b > (1.0f / 255.0f * 126.0f) ) ? 1 : 0; // Make sure that the 1st vertex is taken into account
|
||||
o_positionOS.xyz *= 1.0 - unity_LODFade.x * lodfade;
|
||||
}
|
||||
|
||||
// Move point back to origin
|
||||
o_positionOS.xyz += pivot;
|
||||
|
||||
// Advanced edge fluttering (has to be outside preserve length)
|
||||
if(EnableAdvancedEdgeBending)
|
||||
{
|
||||
o_positionOS.xyz += o_normalOS.xyz * SmoothTriangleWave( tumbleInfluence * timeParams.x * AdvancedEdgeBending.y + Phase ) * AdvancedEdgeBending.x * Flutter * absWindStrength;
|
||||
}
|
||||
}
|
||||
|
||||
// Preserve Length
|
||||
float origLength = length(o_positionOS.xyz);
|
||||
|
||||
// Primary bending / Displace position
|
||||
o_positionOS.xyz += animParams.z * Wind.xyz * fOsc.x * absWindStrength ;
|
||||
|
||||
#if defined(_NORMALIZEBRANCH)
|
||||
// Preserve Length - good here but stretches real branches
|
||||
o_positionOS.xyz = normalize(o_positionOS.xyz) * origLength;
|
||||
#endif
|
||||
|
||||
// Apply secondary bending and edge flutter
|
||||
float3 bend = animParams.y * fDetailAmp * abs(o_normalOS.xyz);
|
||||
bend.y = animParams.w * fBranchAmp;
|
||||
o_positionOS.xyz += ((vWavesSum.xyx * bend) + (Wind.xyz * vWavesSum.y * animParams.w)) * absWindStrength * _CTI_SRP_Turbulence;
|
||||
|
||||
#if !defined(_NORMALIZEBRANCH)
|
||||
// Preserve Length - good here but stretches real branches
|
||||
o_positionOS.xyz = normalize(o_positionOS.xyz) * origLength;
|
||||
#endif
|
||||
|
||||
// Store Variation
|
||||
#if !defined(UNITY_PASS_SHADOWCASTER) && !defined(DEPTHONLYPASS)
|
||||
o_colorVariationAmbient.x = saturate ( ( frac(TreeWorldPos.x + TreeWorldPos.y + TreeWorldPos.z) + frac( (TreeWorldPos.x + TreeWorldPos.y + TreeWorldPos.z) * 3.3 ) ) * 0.5 );
|
||||
o_colorVariationAmbient.y = VertexColor.a;
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6edaaabf19fadfe4fa45576b1902b0c8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user