initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
|
@ -0,0 +1,4 @@
|
|||
// This file is only to force Unity to load the ShaderLibrary's hlsl files in visual studio project via asmdef file, so they can be browse.
|
||||
class DummyShaderGraphLibrary
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1cfbf2a3c53e704ba1a9450da64c95c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
// UNITY_SHADER_NO_UPGRADE
|
||||
#ifndef UNITY_GRAPHFUNCTIONS_INCLUDED
|
||||
#define UNITY_GRAPHFUNCTIONS_INCLUDED
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Included in generated graph shaders
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef BUILTIN_TARGET_API
|
||||
bool IsGammaSpace()
|
||||
{
|
||||
#ifdef UNITY_COLORSPACE_GAMMA
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
float4 ComputeScreenPos (float4 pos, float projectionSign)
|
||||
{
|
||||
float4 o = pos * 0.5f;
|
||||
o.xy = float2(o.x, o.y * projectionSign) + o.w;
|
||||
o.zw = pos.zw;
|
||||
return o;
|
||||
}
|
||||
|
||||
struct Gradient
|
||||
{
|
||||
int type;
|
||||
int colorsLength;
|
||||
int alphasLength;
|
||||
float4 colors[8];
|
||||
float2 alphas[8];
|
||||
};
|
||||
|
||||
Gradient NewGradient(int type, int colorsLength, int alphasLength,
|
||||
float4 colors0, float4 colors1, float4 colors2, float4 colors3, float4 colors4, float4 colors5, float4 colors6, float4 colors7,
|
||||
float2 alphas0, float2 alphas1, float2 alphas2, float2 alphas3, float2 alphas4, float2 alphas5, float2 alphas6, float2 alphas7)
|
||||
{
|
||||
Gradient output =
|
||||
{
|
||||
type, colorsLength, alphasLength,
|
||||
{colors0, colors1, colors2, colors3, colors4, colors5, colors6, colors7},
|
||||
{alphas0, alphas1, alphas2, alphas3, alphas4, alphas5, alphas6, alphas7}
|
||||
};
|
||||
return output;
|
||||
}
|
||||
|
||||
#ifndef SHADERGRAPH_SAMPLE_SCENE_DEPTH
|
||||
#define SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv) shadergraph_SampleSceneDepth(uv)
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_SAMPLE_SCENE_COLOR
|
||||
#define SHADERGRAPH_SAMPLE_SCENE_COLOR(uv) shadergraph_SampleSceneColor(uv)
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_BAKED_GI
|
||||
#define SHADERGRAPH_BAKED_GI(positionWS, normalWS, uvStaticLightmap, uvDynamicLightmap, applyScaling) shadergraph_BakedGI(positionWS, normalWS, uvStaticLightmap, uvDynamicLightmap, applyScaling)
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_REFLECTION_PROBE
|
||||
#define SHADERGRAPH_REFLECTION_PROBE(viewDir, normalOS, lod) shadergraph_ReflectionProbe(viewDir, normalOS, lod)
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_FOG
|
||||
#define SHADERGRAPH_FOG(position, color, density) shadergraph_Fog(position, color, density)
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_AMBIENT_SKY
|
||||
#define SHADERGRAPH_AMBIENT_SKY float3(0,0,0)
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_AMBIENT_EQUATOR
|
||||
#define SHADERGRAPH_AMBIENT_EQUATOR float3(0,0,0)
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_AMBIENT_GROUND
|
||||
#define SHADERGRAPH_AMBIENT_GROUND float3(0,0,0)
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_OBJECT_POSITION
|
||||
#define SHADERGRAPH_OBJECT_POSITION UNITY_MATRIX_M._m03_m13_m23
|
||||
#endif
|
||||
|
||||
float shadergraph_SampleSceneDepth(float2 uv)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
float3 shadergraph_SampleSceneColor(float2 uv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float3 shadergraph_BakedGI(float3 positionWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap, bool applyScaling)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float3 shadergraph_ReflectionProbe(float3 viewDir, float3 normalOS, float lod)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void shadergraph_Fog(float3 position, out float4 color, out float density)
|
||||
{
|
||||
color = 0;
|
||||
density = 0;
|
||||
}
|
||||
|
||||
#endif // UNITY_GRAPHFUNCTIONS_INCLUDED
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 76c5c0b7561134f0ca526e50f239a4a2
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
#ifndef UNITY_GEOMETRICTOOLS_INCLUDED
|
||||
#define UNITY_GEOMETRICTOOLS_INCLUDED
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Intersection functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// return furthest near intersection in x and closest far intersection in y
|
||||
// if (intersections.y > intersections.x) the ray hit the box, else it miss it
|
||||
// Assume dir is normalize
|
||||
float2 BoxRayIntersect(float3 start, float3 dir, float3 boxMin, float3 boxMax)
|
||||
{
|
||||
float3 invDir = 1.0 / dir;
|
||||
|
||||
// Find the ray intersection with box plane
|
||||
float3 firstPlaneIntersect = (boxMin - start) * invDir;
|
||||
float3 secondPlaneIntersect = (boxMax - start) * invDir;
|
||||
|
||||
// Get the closest/furthest of these intersections along the ray (Ok because x/0 give +inf and -x/0 give -inf )
|
||||
float3 closestPlane = min(firstPlaneIntersect, secondPlaneIntersect);
|
||||
float3 furthestPlane = max(firstPlaneIntersect, secondPlaneIntersect);
|
||||
|
||||
float2 intersections;
|
||||
// Find the furthest near intersection
|
||||
intersections.x = max(closestPlane.x, max(closestPlane.y, closestPlane.z));
|
||||
// Find the closest far intersection
|
||||
intersections.y = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
|
||||
|
||||
return intersections;
|
||||
}
|
||||
|
||||
// This simplified version assume that we care about the result only when we are inside the box
|
||||
// Assume dir is normalize
|
||||
float BoxRayIntersectSimple(float3 start, float3 dir, float3 boxMin, float3 boxMax)
|
||||
{
|
||||
float3 invDir = 1.0 / dir;
|
||||
|
||||
// Find the ray intersection with box plane
|
||||
float3 rbmin = (boxMin - start) * invDir;
|
||||
float3 rbmax = (boxMax - start) * invDir;
|
||||
|
||||
float3 rbminmax = (dir > 0.0) ? rbmax : rbmin;
|
||||
|
||||
return min(min(rbminmax.x, rbminmax.y), rbminmax.z);
|
||||
}
|
||||
|
||||
// Assume Sphere is at the origin (i.e start = position - spherePosition)
|
||||
float2 SphereRayIntersect(float3 start, float3 dir, float radius, out bool intersect)
|
||||
{
|
||||
float a = dot(dir, dir);
|
||||
float b = dot(dir, start) * 2.0;
|
||||
float c = dot(start, start) - radius * radius;
|
||||
float discriminant = b * b - 4.0 * a * c;
|
||||
|
||||
float2 intersections = float2(0.0, 0.0);
|
||||
intersect = false;
|
||||
if (discriminant < 0.0 || a == 0.0)
|
||||
{
|
||||
intersections.x = 0.0;
|
||||
intersections.y = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
float sqrtDiscriminant = sqrt(discriminant);
|
||||
intersections.x = (-b - sqrtDiscriminant) / (2.0 * a);
|
||||
intersections.y = (-b + sqrtDiscriminant) / (2.0 * a);
|
||||
intersect = true;
|
||||
}
|
||||
|
||||
return intersections;
|
||||
}
|
||||
|
||||
// This simplified version assume that we care about the result only when we are inside the sphere
|
||||
// Assume Sphere is at the origin (i.e start = position - spherePosition) and dir is normalized
|
||||
// Ref: http://http.developer.nvidia.com/GPUGems/gpugems_ch19.html
|
||||
float SphereRayIntersectSimple(float3 start, float3 dir, float radius)
|
||||
{
|
||||
float b = dot(dir, start) * 2.0;
|
||||
float c = dot(start, start) - radius * radius;
|
||||
float discriminant = b * b - 4.0 * c;
|
||||
|
||||
return abs(sqrt(discriminant) - b) * 0.5;
|
||||
}
|
||||
|
||||
float3 RayPlaneIntersect(in float3 rayOrigin, in float3 rayDirection, in float3 planeOrigin, in float3 planeNormal)
|
||||
{
|
||||
float dist = dot(planeNormal, planeOrigin - rayOrigin) / dot(planeNormal, rayDirection);
|
||||
return rayOrigin + rayDirection * dist;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Miscellaneous functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Box is AABB
|
||||
float DistancePointBox(float3 position, float3 boxMin, float3 boxMax)
|
||||
{
|
||||
return length(max(max(position - boxMax, boxMin - position), float3(0.0, 0.0, 0.0)));
|
||||
}
|
||||
|
||||
float3 ProjectPointOnPlane(float3 position, float3 planePosition, float3 planeNormal)
|
||||
{
|
||||
return position - (dot(position - planePosition, planeNormal) * planeNormal);
|
||||
}
|
||||
|
||||
// Plane equation: {(a, b, c) = N, d = -dot(N, P)}.
|
||||
// Returns the distance from the plane to the point 'p' along the normal.
|
||||
// Positive -> in front (above), negative -> behind (below).
|
||||
float DistanceFromPlane(float3 p, float4 plane)
|
||||
{
|
||||
return dot(float4(p, 1.0), plane);
|
||||
}
|
||||
|
||||
// Returns 'true' if the triangle is outside of the frustum.
|
||||
// 'epsilon' is the (negative) distance to (outside of) the frustum below which we cull the triangle.
|
||||
bool CullTriangleFrustum(float3 p0, float3 p1, float3 p2, float epsilon, float4 frustumPlanes[6], int numPlanes)
|
||||
{
|
||||
bool outside = false;
|
||||
|
||||
for (int i = 0; i < numPlanes; i++)
|
||||
{
|
||||
// If all 3 points are behind any of the planes, we cull.
|
||||
outside = outside || Max3(DistanceFromPlane(p0, frustumPlanes[i]),
|
||||
DistanceFromPlane(p1, frustumPlanes[i]),
|
||||
DistanceFromPlane(p2, frustumPlanes[i])) < epsilon;
|
||||
}
|
||||
|
||||
return outside;
|
||||
}
|
||||
|
||||
// Returns 'true' if the edge of the triangle is outside of the frustum.
|
||||
// The edges are defined s.t. they are on the opposite side of the point with the given index.
|
||||
// 'epsilon' is the (negative) distance to (outside of) the frustum below which we cull the triangle.
|
||||
bool3 CullTriangleEdgesFrustum(float3 p0, float3 p1, float3 p2, float epsilon, float4 frustumPlanes[6], int numPlanes)
|
||||
{
|
||||
bool3 edgesOutside = false;
|
||||
|
||||
for (int i = 0; i < numPlanes; i++)
|
||||
{
|
||||
bool3 pointsOutside = bool3(DistanceFromPlane(p0, frustumPlanes[i]) < epsilon,
|
||||
DistanceFromPlane(p1, frustumPlanes[i]) < epsilon,
|
||||
DistanceFromPlane(p2, frustumPlanes[i]) < epsilon);
|
||||
|
||||
// If both points of the edge are behind any of the planes, we cull.
|
||||
edgesOutside.x = edgesOutside.x || (pointsOutside.y && pointsOutside.z);
|
||||
edgesOutside.y = edgesOutside.y || (pointsOutside.x && pointsOutside.z);
|
||||
edgesOutside.z = edgesOutside.z || (pointsOutside.x && pointsOutside.y);
|
||||
}
|
||||
|
||||
return edgesOutside;
|
||||
}
|
||||
|
||||
// Returns 'true' if a triangle defined by 3 vertices is back-facing.
|
||||
// 'epsilon' is the (negative) value of dot(N, V) below which we cull the triangle.
|
||||
// 'winding' can be used to change the order: pass 1 for (p0 -> p1 -> p2), or -1 for (p0 -> p2 -> p1).
|
||||
bool CullTriangleBackFace(float3 p0, float3 p1, float3 p2, float epsilon, float3 viewPos, float winding)
|
||||
{
|
||||
float3 edge1 = p1 - p0;
|
||||
float3 edge2 = p2 - p0;
|
||||
|
||||
float3 N = cross(edge1, edge2);
|
||||
float3 V = viewPos - p0;
|
||||
float NdotV = dot(N, V) * winding;
|
||||
|
||||
// Optimize:
|
||||
// NdotV / (length(N) * length(V)) < Epsilon
|
||||
// NdotV < Epsilon * length(N) * length(V)
|
||||
// NdotV < Epsilon * sqrt(dot(N, N)) * sqrt(dot(V, V))
|
||||
// NdotV < Epsilon * sqrt(dot(N, N) * dot(V, V))
|
||||
return NdotV < epsilon * sqrt(dot(N, N) * dot(V, V));
|
||||
}
|
||||
|
||||
#endif // UNITY_GEOMETRICTOOLS_INCLUDED
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 07d3f5482ecfe425f91b12cd32be4cbe
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
// Shadergraph-friendly implementation of LODDitheringTransition.
|
||||
// The function as defined in Common.hlsl terminates on clip(f).
|
||||
// However, since it does not return or output anything, shadergraph
|
||||
// doesn't recognize it as code that gets used. This file can be removed
|
||||
// and replaced with a string custom function if Shader Graph ever adds
|
||||
// support for flagging custom function nodes as used, even if not
|
||||
// connected to anything.
|
||||
#ifndef SHADERGRAPH_CROSSFADE_INCLUDED
|
||||
#define SHADERGRAPH_CROSSFADE_INCLUDED
|
||||
#ifndef UNITY_MATERIAL_INCLUDED
|
||||
uint2 ComputeFadeMaskSeed(float3 V, uint2 positionSS)
|
||||
{
|
||||
uint2 fadeMaskSeed;
|
||||
|
||||
// Is this a reasonable quality gate?
|
||||
#if defined(SHADER_QUALITY_HIGH)
|
||||
if (IsPerspectiveProjection())
|
||||
{
|
||||
// Start with the world-space direction V. It is independent from the orientation of the camera,
|
||||
// and only depends on the position of the camera and the position of the fragment.
|
||||
// Now, project and transform it into [-1, 1].
|
||||
float2 pv = PackNormalOctQuadEncode(V);
|
||||
// Rescale it to account for the resolution of the screen.
|
||||
pv *= _ScreenParams.xy;
|
||||
// The camera only sees a small portion of the sphere, limited by hFoV and vFoV.
|
||||
// Therefore, we must rescale again (before quantization), roughly, by 1/tan(FoV/2).
|
||||
pv *= UNITY_MATRIX_P._m00_m11;
|
||||
// Truncate and quantize.
|
||||
fadeMaskSeed = asuint((int2)pv);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// Can't use the view direction, it is the same across the entire screen.
|
||||
fadeMaskSeed = positionSS;
|
||||
}
|
||||
|
||||
return fadeMaskSeed;
|
||||
}
|
||||
#endif
|
||||
void LODDitheringTransitionSG_float(float3 viewDirWS, float4 screenPos, out float multiplyAlpha)
|
||||
{
|
||||
#if !defined (SHADER_API_GLES) && !defined(SHADER_STAGE_RAY_TRACING)
|
||||
float p = GenerateHashedRandomFloat(ComputeFadeMaskSeed(viewDirWS, screenPos.xy));
|
||||
float f = unity_LODFade.x - CopySign(p, unity_LODFade.x);
|
||||
multiplyAlpha = f < 0 ? 0.0f : 1.0f;
|
||||
#endif
|
||||
}
|
||||
void DoLODCrossFade_half(float3 viewDirWS, float4 screenPos, out half halfAlpha)
|
||||
{
|
||||
#if !defined (SHADER_API_GLES) && !defined(SHADER_STAGE_RAY_TRACING)
|
||||
float p = GenerateHashedRandomFloat(ComputeFadeMaskSeed(viewDirWS, screenPos.xy));
|
||||
float f = unity_LODFade.x - CopySign(p, unity_LODFade.x);
|
||||
float multiplyAlpha = f < 0 ? 0.0f : 1.0f;
|
||||
halfAlpha = (half)multiplyAlpha;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5248225944112fb418a213fa587fe10d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4cc7da0ede79c9248a9e2e96a546813d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89c32740b629abb41bf9b65e3a64c373
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1b4ecad27a9bc714e8d3af3ffb8a368c
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b04441f4a83ad224d92d547d170c366b
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
|
||||
|
|
@ -0,0 +1,810 @@
|
|||
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
|
||||
|
||||
#ifndef SPEEDTREE_WIND_INCLUDED
|
||||
#define SPEEDTREE_WIND_INCLUDED
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Wind Info
|
||||
|
||||
CBUFFER_START(SpeedTreeWind)
|
||||
float4 _ST_WindVector;
|
||||
float4 _ST_WindGlobal;
|
||||
float4 _ST_WindBranch;
|
||||
float4 _ST_WindBranchTwitch;
|
||||
float4 _ST_WindBranchWhip;
|
||||
float4 _ST_WindBranchAnchor;
|
||||
float4 _ST_WindBranchAdherences;
|
||||
float4 _ST_WindTurbulences;
|
||||
float4 _ST_WindLeaf1Ripple;
|
||||
float4 _ST_WindLeaf1Tumble;
|
||||
float4 _ST_WindLeaf1Twitch;
|
||||
float4 _ST_WindLeaf2Ripple;
|
||||
float4 _ST_WindLeaf2Tumble;
|
||||
float4 _ST_WindLeaf2Twitch;
|
||||
float4 _ST_WindFrondRipple;
|
||||
float4 _ST_WindAnimation;
|
||||
CBUFFER_END
|
||||
|
||||
#define ST_WIND_QUALITY_NONE 0
|
||||
#define ST_WIND_QUALITY_FASTEST 1
|
||||
#define ST_WIND_QUALITY_FAST 2
|
||||
#define ST_WIND_QUALITY_BETTER 3
|
||||
#define ST_WIND_QUALITY_BEST 4
|
||||
#define ST_WIND_QUALITY_PALM 5
|
||||
|
||||
#define ST_GEOM_TYPE_BRANCH 0
|
||||
#define ST_GEOM_TYPE_FROND 1
|
||||
#define ST_GEOM_TYPE_LEAF 2
|
||||
#define ST_GEOM_TYPE_FACINGLEAF 3
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// UnpackNormalFromFloat
|
||||
|
||||
float3 UnpackNormalFromFloat(float fValue)
|
||||
{
|
||||
float3 vDecodeKey = float3(16.0, 1.0, 0.0625);
|
||||
|
||||
// decode into [0,1] range
|
||||
float3 vDecodedValue = frac(fValue / vDecodeKey);
|
||||
|
||||
// move back into [-1,1] range & normalize
|
||||
return (vDecodedValue * 2.0 - 1.0);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// CubicSmooth
|
||||
|
||||
float4 CubicSmooth(float4 vData)
|
||||
{
|
||||
return vData * vData * (3.0 - 2.0 * vData);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// TriangleWave
|
||||
|
||||
float4 TriangleWave(float4 vData)
|
||||
{
|
||||
return abs((frac(vData + 0.5) * 2.0) - 1.0);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// TrigApproximate
|
||||
|
||||
float4 TrigApproximate(float4 vData)
|
||||
{
|
||||
return (CubicSmooth(TriangleWave(vData)) - 0.5) * 2.0;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// RotationMatrix
|
||||
//
|
||||
// Constructs an arbitrary axis rotation matrix
|
||||
|
||||
float3x3 RotationMatrix(float3 vAxis, float fAngle)
|
||||
{
|
||||
// compute sin/cos of fAngle
|
||||
float2 vSinCos;
|
||||
#ifdef OPENGL
|
||||
vSinCos.x = sin(fAngle);
|
||||
vSinCos.y = cos(fAngle);
|
||||
#else
|
||||
sincos(fAngle, vSinCos.x, vSinCos.y);
|
||||
#endif
|
||||
|
||||
const float c = vSinCos.y;
|
||||
const float s = vSinCos.x;
|
||||
const float t = 1.0 - c;
|
||||
const float x = vAxis.x;
|
||||
const float y = vAxis.y;
|
||||
const float z = vAxis.z;
|
||||
|
||||
return float3x3(t * x * x + c, t * x * y - s * z, t * x * z + s * y,
|
||||
t * x * y + s * z, t * y * y + c, t * y * z - s * x,
|
||||
t * x * z - s * y, t * y * z + s * x, t * z * z + c);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// mul_float3x3_float3x3
|
||||
|
||||
float3x3 mul_float3x3_float3x3(float3x3 mMatrixA, float3x3 mMatrixB)
|
||||
{
|
||||
return mul(mMatrixA, mMatrixB);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// mul_float3x3_float3
|
||||
|
||||
float3 mul_float3x3_float3(float3x3 mMatrix, float3 vVector)
|
||||
{
|
||||
return mul(mMatrix, vVector);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// cross()'s parameters are backwards in GLSL
|
||||
|
||||
#define wind_cross(a, b) cross((a), (b))
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Roll
|
||||
|
||||
float Roll(float fCurrent,
|
||||
float fMaxScale,
|
||||
float fMinScale,
|
||||
float fSpeed,
|
||||
float fRipple,
|
||||
float3 vPos,
|
||||
float fTime,
|
||||
float3 vRotatedWindVector)
|
||||
{
|
||||
float fWindAngle = dot(vPos, -vRotatedWindVector) * fRipple;
|
||||
float fAdjust = TrigApproximate(float4(fWindAngle + fTime * fSpeed, 0.0, 0.0, 0.0)).x;
|
||||
fAdjust = (fAdjust + 1.0) * 0.5;
|
||||
|
||||
return lerp(fCurrent * fMinScale, fCurrent * fMaxScale, fAdjust);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Twitch
|
||||
|
||||
float Twitch(float3 vPos, float fAmount, float fSharpness, float fTime)
|
||||
{
|
||||
const float c_fTwitchFudge = 0.87;
|
||||
float4 vOscillations = TrigApproximate(float4(fTime + (vPos.x + vPos.z), c_fTwitchFudge * fTime + vPos.y, 0.0, 0.0));
|
||||
|
||||
//float fTwitch = sin(fFreq1 * fTime + (vPos.x + vPos.z)) * cos(fFreq2 * fTime + vPos.y);
|
||||
float fTwitch = vOscillations.x * vOscillations.y * vOscillations.y;
|
||||
fTwitch = (fTwitch + 1.0) * 0.5;
|
||||
|
||||
return fAmount * pow(saturate(fTwitch), fSharpness);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Oscillate
|
||||
//
|
||||
// This function computes an oscillation value and whip value if necessary.
|
||||
// Whip and oscillation are combined like this to minimize calls to
|
||||
// TrigApproximate( ) when possible.
|
||||
|
||||
float Oscillate(float3 vPos,
|
||||
float fTime,
|
||||
float fOffset,
|
||||
float fWeight,
|
||||
float fWhip,
|
||||
bool bWhip,
|
||||
bool bRoll,
|
||||
bool bComplex,
|
||||
float fTwitch,
|
||||
float fTwitchFreqScale,
|
||||
inout float4 vOscillations,
|
||||
float3 vRotatedWindVector)
|
||||
{
|
||||
float fOscillation = 1.0;
|
||||
if (bComplex)
|
||||
{
|
||||
if (bWhip)
|
||||
vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * fTwitchFreqScale + fOffset, fTwitchFreqScale * 0.5 * (fTime + fOffset), fTime + fOffset + (1.0 - fWeight)));
|
||||
else
|
||||
vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * fTwitchFreqScale + fOffset, fTwitchFreqScale * 0.5 * (fTime + fOffset), 0.0));
|
||||
|
||||
float fFineDetail = vOscillations.x;
|
||||
float fBroadDetail = vOscillations.y * vOscillations.z;
|
||||
|
||||
float fTarget = 1.0;
|
||||
float fAmount = fBroadDetail;
|
||||
if (fBroadDetail < 0.0)
|
||||
{
|
||||
fTarget = -fTarget;
|
||||
fAmount = -fAmount;
|
||||
}
|
||||
|
||||
fBroadDetail = lerp(fBroadDetail, fTarget, fAmount);
|
||||
fBroadDetail = lerp(fBroadDetail, fTarget, fAmount);
|
||||
|
||||
fOscillation = fBroadDetail * fTwitch * (1.0 - _ST_WindVector.w) + fFineDetail * (1.0 - fTwitch);
|
||||
|
||||
if (bWhip)
|
||||
fOscillation *= 1.0 + (vOscillations.w * fWhip);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bWhip)
|
||||
vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * 0.689 + fOffset, 0.0, fTime + fOffset + (1.0 - fWeight)));
|
||||
else
|
||||
vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * 0.689 + fOffset, 0.0, 0.0));
|
||||
|
||||
fOscillation = vOscillations.x + vOscillations.y * vOscillations.x;
|
||||
|
||||
if (bWhip)
|
||||
fOscillation *= 1.0 + (vOscillations.w * fWhip);
|
||||
}
|
||||
|
||||
//if (bRoll)
|
||||
//{
|
||||
// fOscillation = Roll(fOscillation, _ST_WindRollingBranches.x, _ST_WindRollingBranches.y, _ST_WindRollingBranches.z, _ST_WindRollingBranches.w, vPos.xyz, fTime + fOffset, vRotatedWindVector);
|
||||
//}
|
||||
|
||||
return fOscillation;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Turbulence
|
||||
|
||||
float Turbulence(float fTime, float fOffset, float fGlobalTime, float fTurbulence)
|
||||
{
|
||||
const float c_fTurbulenceFactor = 0.1;
|
||||
|
||||
float4 vOscillations = TrigApproximate(float4(fTime * c_fTurbulenceFactor + fOffset, fGlobalTime * fTurbulence * c_fTurbulenceFactor + fOffset, 0.0, 0.0));
|
||||
|
||||
return 1.0 - (vOscillations.x * vOscillations.y * vOscillations.x * vOscillations.y * fTurbulence);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// GlobalWind
|
||||
//
|
||||
// This function positions any tree geometry based on their untransformed
|
||||
// position and 4 wind floats.
|
||||
|
||||
float3 GlobalWind(float3 vPos, float3 vInstancePos, bool bPreserveShape, float3 vRotatedWindVector, float time)
|
||||
{
|
||||
// WIND_LOD_GLOBAL may be on, but if the global wind effect (WIND_EFFECT_GLOBAL_ST_Wind)
|
||||
// was disabled for the tree in the Modeler, we should skip it
|
||||
|
||||
float fLength = 1.0;
|
||||
if (bPreserveShape)
|
||||
fLength = length(vPos.xyz);
|
||||
|
||||
// compute how much the height contributes
|
||||
#ifdef SPEEDTREE_Z_UP
|
||||
float fAdjust = max(vPos.z - (1.0 / _ST_WindGlobal.z) * 0.25, 0.0) * _ST_WindGlobal.z;
|
||||
#else
|
||||
float fAdjust = max(vPos.y - (1.0 / _ST_WindGlobal.z) * 0.25, 0.0) * _ST_WindGlobal.z;
|
||||
#endif
|
||||
if (fAdjust != 0.0)
|
||||
fAdjust = pow(abs(fAdjust), _ST_WindGlobal.w);
|
||||
|
||||
// primary oscillation
|
||||
float4 vOscillations = TrigApproximate(float4(vInstancePos.x + time, vInstancePos.y + time * 0.8, 0.0, 0.0));
|
||||
float fOsc = vOscillations.x + (vOscillations.y * vOscillations.y);
|
||||
float fMoveAmount = _ST_WindGlobal.y * fOsc;
|
||||
|
||||
// move a minimum amount based on direction adherence
|
||||
fMoveAmount += _ST_WindBranchAdherences.x / _ST_WindGlobal.z;
|
||||
|
||||
// adjust based on how high up the tree this vertex is
|
||||
fMoveAmount *= fAdjust;
|
||||
|
||||
// xy component
|
||||
#ifdef SPEEDTREE_Z_UP
|
||||
vPos.xy += vRotatedWindVector.xy * fMoveAmount;
|
||||
#else
|
||||
vPos.xz += vRotatedWindVector.xz * fMoveAmount;
|
||||
#endif
|
||||
|
||||
if (bPreserveShape)
|
||||
vPos.xyz = normalize(vPos.xyz) * fLength;
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// SimpleBranchWind
|
||||
|
||||
float3 SimpleBranchWind(float3 vPos,
|
||||
float3 vInstancePos,
|
||||
float fWeight,
|
||||
float fOffset,
|
||||
float fTime,
|
||||
float fDistance,
|
||||
float fTwitch,
|
||||
float fTwitchScale,
|
||||
float fWhip,
|
||||
bool bWhip,
|
||||
bool bRoll,
|
||||
bool bComplex,
|
||||
float3 vRotatedWindVector)
|
||||
{
|
||||
// turn the offset back into a nearly normalized vector
|
||||
float3 vWindVector = UnpackNormalFromFloat(fOffset);
|
||||
vWindVector = vWindVector * fWeight;
|
||||
|
||||
// try to fudge time a bit so that instances aren't in sync
|
||||
fTime += vInstancePos.x + vInstancePos.y;
|
||||
|
||||
// oscillate
|
||||
float4 vOscillations;
|
||||
float fOsc = Oscillate(vPos, fTime, fOffset, fWeight, fWhip, bWhip, bRoll, bComplex, fTwitch, fTwitchScale, vOscillations, vRotatedWindVector);
|
||||
|
||||
vPos.xyz += vWindVector * fOsc * fDistance;
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// DirectionalBranchWind
|
||||
|
||||
float3 DirectionalBranchWind(float3 vPos,
|
||||
float3 vInstancePos,
|
||||
float fWeight,
|
||||
float fOffset,
|
||||
float fTime,
|
||||
float fDistance,
|
||||
float fTurbulence,
|
||||
float fAdherence,
|
||||
float fTwitch,
|
||||
float fTwitchScale,
|
||||
float fWhip,
|
||||
bool bWhip,
|
||||
bool bRoll,
|
||||
bool bComplex,
|
||||
bool bTurbulence,
|
||||
float3 vRotatedWindVector)
|
||||
{
|
||||
// turn the offset back into a nearly normalized vector
|
||||
float3 vWindVector = UnpackNormalFromFloat(fOffset);
|
||||
vWindVector = vWindVector * fWeight;
|
||||
|
||||
// try to fudge time a bit so that instances aren't in sync
|
||||
fTime += vInstancePos.x + vInstancePos.y;
|
||||
|
||||
// oscillate
|
||||
float4 vOscillations;
|
||||
float fOsc = Oscillate(vPos, fTime, fOffset, fWeight, fWhip, bWhip, false, bComplex, fTwitch, fTwitchScale, vOscillations, vRotatedWindVector);
|
||||
|
||||
vPos.xyz += vWindVector * fOsc * fDistance;
|
||||
|
||||
// add in the direction, accounting for turbulence
|
||||
float fAdherenceScale = 1.0;
|
||||
if (bTurbulence)
|
||||
fAdherenceScale = Turbulence(fTime, fOffset, _ST_WindAnimation.x, fTurbulence);
|
||||
|
||||
if (bWhip)
|
||||
fAdherenceScale += vOscillations.w * _ST_WindVector.w * fWhip;
|
||||
|
||||
//if (bRoll)
|
||||
// fAdherenceScale = Roll(fAdherenceScale, _ST_WindRollingBranches.x, _ST_WindRollingBranches.y, _ST_WindRollingBranches.z, _ST_WindRollingBranches.w, vPos.xyz, fTime + fOffset, vRotatedWindVector);
|
||||
|
||||
vPos.xyz += vRotatedWindVector * fAdherence * fAdherenceScale * fWeight;
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// DirectionalBranchWindFrondStyle
|
||||
|
||||
float3 DirectionalBranchWindFrondStyle(float3 vPos,
|
||||
float3 vInstancePos,
|
||||
float fWeight,
|
||||
float fOffset,
|
||||
float fTime,
|
||||
float fDistance,
|
||||
float fTurbulence,
|
||||
float fAdherence,
|
||||
float fTwitch,
|
||||
float fTwitchScale,
|
||||
float fWhip,
|
||||
bool bWhip,
|
||||
bool bRoll,
|
||||
bool bComplex,
|
||||
bool bTurbulence,
|
||||
float3 vRotatedWindVector,
|
||||
float3 vRotatedBranchAnchor)
|
||||
{
|
||||
// turn the offset back into a nearly normalized vector
|
||||
float3 vWindVector = UnpackNormalFromFloat(fOffset);
|
||||
vWindVector = vWindVector * fWeight;
|
||||
|
||||
// try to fudge time a bit so that instances aren't in sync
|
||||
fTime += vInstancePos.x + vInstancePos.y;
|
||||
|
||||
// oscillate
|
||||
float4 vOscillations;
|
||||
float fOsc = Oscillate(vPos, fTime, fOffset, fWeight, fWhip, bWhip, false, bComplex, fTwitch, fTwitchScale, vOscillations, vRotatedWindVector);
|
||||
|
||||
vPos.xyz += vWindVector * fOsc * fDistance;
|
||||
|
||||
// add in the direction, accounting for turbulence
|
||||
float fAdherenceScale = 1.0;
|
||||
if (bTurbulence)
|
||||
fAdherenceScale = Turbulence(fTime, fOffset, _ST_WindAnimation.x, fTurbulence);
|
||||
|
||||
//if (bRoll)
|
||||
// fAdherenceScale = Roll(fAdherenceScale, _ST_WindRollingBranches.x, _ST_WindRollingBranches.y, _ST_WindRollingBranches.z, _ST_WindRollingBranches.w, vPos.xyz, fTime + fOffset, vRotatedWindVector);
|
||||
|
||||
if (bWhip)
|
||||
fAdherenceScale += vOscillations.w * _ST_WindVector.w * fWhip;
|
||||
|
||||
float3 vWindAdherenceVector = vRotatedBranchAnchor - vPos.xyz;
|
||||
vPos.xyz += vWindAdherenceVector * fAdherence * fAdherenceScale * fWeight;
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// BranchWind
|
||||
|
||||
// Apply only to better, best, palm winds
|
||||
float3 BranchWind(bool isPalmWind, float3 vPos, float3 vInstancePos, float4 vWindData, float3 vRotatedWindVector, float3 vRotatedBranchAnchor)
|
||||
{
|
||||
if (isPalmWind)
|
||||
{
|
||||
vPos = DirectionalBranchWindFrondStyle(vPos, vInstancePos, vWindData.x, vWindData.y, _ST_WindBranch.x, _ST_WindBranch.y, _ST_WindTurbulences.x, _ST_WindBranchAdherences.y, _ST_WindBranchTwitch.x, _ST_WindBranchTwitch.y, _ST_WindBranchWhip.x, true, false, true, true, vRotatedWindVector, vRotatedBranchAnchor);
|
||||
}
|
||||
else
|
||||
{
|
||||
vPos = SimpleBranchWind(vPos, vInstancePos, vWindData.x, vWindData.y, _ST_WindBranch.x, _ST_WindBranch.y, _ST_WindBranchTwitch.x, _ST_WindBranchTwitch.y, _ST_WindBranchWhip.x, false, false, true, vRotatedWindVector);
|
||||
}
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// LeafRipple
|
||||
|
||||
float3 LeafRipple(float3 vPos,
|
||||
inout float3 vDirection,
|
||||
float fScale,
|
||||
float fPackedRippleDir,
|
||||
float fTime,
|
||||
float fAmount,
|
||||
bool bDirectional,
|
||||
float fTrigOffset)
|
||||
{
|
||||
// compute how much to move
|
||||
float4 vInput = float4(fTime + fTrigOffset, 0.0, 0.0, 0.0);
|
||||
float fMoveAmount = fAmount * TrigApproximate(vInput).x;
|
||||
|
||||
if (bDirectional)
|
||||
{
|
||||
vPos.xyz += vDirection.xyz * fMoveAmount * fScale;
|
||||
}
|
||||
else
|
||||
{
|
||||
float3 vRippleDir = UnpackNormalFromFloat(fPackedRippleDir);
|
||||
vPos.xyz += vRippleDir * fMoveAmount * fScale;
|
||||
}
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// LeafTumble
|
||||
|
||||
float3 LeafTumble(float3 vPos,
|
||||
inout float3 vDirection,
|
||||
float fScale,
|
||||
float3 vAnchor,
|
||||
float3 vGrowthDir,
|
||||
float fTrigOffset,
|
||||
float fTime,
|
||||
float fFlip,
|
||||
float fTwist,
|
||||
float fAdherence,
|
||||
float3 vTwitch,
|
||||
float4 vRoll,
|
||||
bool bTwitch,
|
||||
bool bRoll,
|
||||
float3 vRotatedWindVector)
|
||||
{
|
||||
// compute all oscillations up front
|
||||
float3 vFracs = frac((vAnchor + fTrigOffset) * 30.3);
|
||||
float fOffset = vFracs.x + vFracs.y + vFracs.z;
|
||||
float4 vOscillations = TrigApproximate(float4(fTime + fOffset, fTime * 0.75 - fOffset, fTime * 0.01 + fOffset, fTime * 1.0 + fOffset));
|
||||
|
||||
// move to the origin and get the growth direction
|
||||
float3 vOriginPos = vPos.xyz - vAnchor;
|
||||
float fLength = length(vOriginPos);
|
||||
|
||||
// twist
|
||||
float fOsc = vOscillations.x + vOscillations.y * vOscillations.y;
|
||||
float3x3 matTumble = RotationMatrix(vGrowthDir, fScale * fTwist * fOsc);
|
||||
|
||||
// with wind
|
||||
float3 vAxis = wind_cross(vGrowthDir.xyz, vRotatedWindVector.xyz);
|
||||
float fDot = clamp(dot(vRotatedWindVector, vGrowthDir), -1.0, 1.0);
|
||||
#ifdef SPEEDTREE_Z_UP
|
||||
vAxis.z += fDot;
|
||||
#else
|
||||
vAxis.y += fDot;
|
||||
#endif
|
||||
vAxis = normalize(vAxis);
|
||||
|
||||
float fAngle = acos(fDot);
|
||||
|
||||
float fAdherenceScale = 1.0;
|
||||
//if (bRoll)
|
||||
//{
|
||||
// fAdherenceScale = Roll(fAdherenceScale, vRoll.x, vRoll.y, vRoll.z, vRoll.w, vAnchor.xyz, fTime, vRotatedWindVector);
|
||||
//}
|
||||
|
||||
fOsc = vOscillations.y - vOscillations.x * vOscillations.x;
|
||||
|
||||
float fTwitch = 0.0;
|
||||
if (bTwitch)
|
||||
fTwitch = Twitch(vAnchor.xyz, vTwitch.x, vTwitch.y, vTwitch.z + fOffset);
|
||||
|
||||
matTumble = mul_float3x3_float3x3(matTumble, RotationMatrix(vAxis, fScale * (fAngle * fAdherence * fAdherenceScale + fOsc * fFlip + fTwitch)));
|
||||
|
||||
vDirection = mul_float3x3_float3(matTumble, vDirection);
|
||||
vOriginPos = mul_float3x3_float3(matTumble, vOriginPos);
|
||||
|
||||
vOriginPos = normalize(vOriginPos) * fLength;
|
||||
|
||||
return (vOriginPos + vAnchor);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// LeafWind
|
||||
// Optimized (for instruction count) version. Assumes leaf 1 and 2 have the same options
|
||||
|
||||
float3 LeafWind(bool isBestWind,
|
||||
bool bLeaf2,
|
||||
float3 vPos,
|
||||
inout float3 vDirection,
|
||||
float fScale,
|
||||
float3 vAnchor,
|
||||
float fPackedGrowthDir,
|
||||
float fPackedRippleDir,
|
||||
float fRippleTrigOffset,
|
||||
float3 vRotatedWindVector)
|
||||
{
|
||||
|
||||
vPos = LeafRipple(vPos, vDirection, fScale, fPackedRippleDir,
|
||||
(bLeaf2 ? _ST_WindLeaf2Ripple.x : _ST_WindLeaf1Ripple.x),
|
||||
(bLeaf2 ? _ST_WindLeaf2Ripple.y : _ST_WindLeaf1Ripple.y),
|
||||
false, fRippleTrigOffset);
|
||||
|
||||
if (isBestWind)
|
||||
{
|
||||
float3 vGrowthDir = UnpackNormalFromFloat(fPackedGrowthDir);
|
||||
vPos = LeafTumble(vPos, vDirection, fScale, vAnchor, vGrowthDir, fPackedGrowthDir,
|
||||
(bLeaf2 ? _ST_WindLeaf2Tumble.x : _ST_WindLeaf1Tumble.x),
|
||||
(bLeaf2 ? _ST_WindLeaf2Tumble.y : _ST_WindLeaf1Tumble.y),
|
||||
(bLeaf2 ? _ST_WindLeaf2Tumble.z : _ST_WindLeaf1Tumble.z),
|
||||
(bLeaf2 ? _ST_WindLeaf2Tumble.w : _ST_WindLeaf1Tumble.w),
|
||||
(bLeaf2 ? _ST_WindLeaf2Twitch.xyz : _ST_WindLeaf1Twitch.xyz),
|
||||
0.0f,
|
||||
(bLeaf2 ? true : true),
|
||||
(bLeaf2 ? true : true),
|
||||
vRotatedWindVector);
|
||||
}
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// RippleFrondOneSided
|
||||
|
||||
float3 RippleFrondOneSided(float3 vPos,
|
||||
inout float3 vDirection,
|
||||
float fU,
|
||||
float fV,
|
||||
float fRippleScale
|
||||
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
|
||||
, float3 vBinormal
|
||||
, float3 vTangent
|
||||
#endif
|
||||
)
|
||||
{
|
||||
float fOffset = 0.0;
|
||||
if (fU < 0.5)
|
||||
fOffset = 0.75;
|
||||
|
||||
float4 vOscillations = TrigApproximate(float4((_ST_WindFrondRipple.x + fV) * _ST_WindFrondRipple.z + fOffset, 0.0, 0.0, 0.0));
|
||||
|
||||
float fAmount = fRippleScale * vOscillations.x * _ST_WindFrondRipple.y;
|
||||
float3 vOffset = fAmount * vDirection;
|
||||
vPos.xyz += vOffset;
|
||||
|
||||
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
|
||||
vTangent.xyz = normalize(vTangent.xyz + vOffset * _ST_WindFrondRipple.w);
|
||||
float3 vNewNormal = normalize(wind_cross(vBinormal.xyz, vTangent.xyz));
|
||||
if (dot(vNewNormal, vDirection.xyz) < 0.0)
|
||||
vNewNormal = -vNewNormal;
|
||||
vDirection.xyz = vNewNormal;
|
||||
#endif
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// RippleFrondTwoSided
|
||||
|
||||
float3 RippleFrondTwoSided(float3 vPos,
|
||||
inout float3 vDirection,
|
||||
float fU,
|
||||
float fLengthPercent,
|
||||
float fPackedRippleDir,
|
||||
float fRippleScale
|
||||
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
|
||||
, float3 vBinormal
|
||||
, float3 vTangent
|
||||
#endif
|
||||
)
|
||||
{
|
||||
float4 vOscillations = TrigApproximate(float4(_ST_WindFrondRipple.x * fLengthPercent * _ST_WindFrondRipple.z, 0.0, 0.0, 0.0));
|
||||
|
||||
float3 vRippleDir = UnpackNormalFromFloat(fPackedRippleDir);
|
||||
|
||||
float fAmount = fRippleScale * vOscillations.x * _ST_WindFrondRipple.y;
|
||||
float3 vOffset = fAmount * vRippleDir;
|
||||
|
||||
vPos.xyz += vOffset;
|
||||
|
||||
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
|
||||
vTangent.xyz = normalize(vTangent.xyz + vOffset * _ST_WindFrondRipple.w);
|
||||
float3 vNewNormal = normalize(wind_cross(vBinormal.xyz, vTangent.xyz));
|
||||
if (dot(vNewNormal, vDirection.xyz) < 0.0)
|
||||
vNewNormal = -vNewNormal;
|
||||
vDirection.xyz = vNewNormal;
|
||||
#endif
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// RippleFrond
|
||||
|
||||
float3 RippleFrond(float3 vPos,
|
||||
inout float3 vDirection,
|
||||
float fU,
|
||||
float fV,
|
||||
float fPackedRippleDir,
|
||||
float fRippleScale,
|
||||
float fLenghtPercent
|
||||
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
|
||||
, float3 vBinormal
|
||||
, float3 vTangent
|
||||
#endif
|
||||
)
|
||||
{
|
||||
return RippleFrondOneSided(vPos,
|
||||
vDirection,
|
||||
fU,
|
||||
fV,
|
||||
fRippleScale
|
||||
#ifdef WIND_EFFECT_FROND_RIPPLE_ADJUST_LIGHTING
|
||||
, vBinormal
|
||||
, vTangent
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// SpeedTreeWind
|
||||
|
||||
float3 SpeedTreeWind(float3 vPos, float3 vNormal, float4 vTexcoord0, float4 vTexcoord1, float4 vTexcoord2, float4 vTexcoord3, int iWindQuality, bool bBillboard, bool bCrossfade)
|
||||
{
|
||||
float3 vReturnPos = vPos;
|
||||
|
||||
// geometry type
|
||||
int geometryType = (int)(vTexcoord3.w + 0.25);
|
||||
bool leafTwo = false;
|
||||
if (geometryType > ST_GEOM_TYPE_FACINGLEAF)
|
||||
{
|
||||
geometryType -= 2;
|
||||
leafTwo = true;
|
||||
}
|
||||
|
||||
// smooth LOD
|
||||
if (!bCrossfade && !bBillboard)
|
||||
{
|
||||
vReturnPos = lerp(vReturnPos, vTexcoord2.xyz, unity_LODFade.x);
|
||||
}
|
||||
|
||||
// do leaf facing even when we don't have wind
|
||||
if (geometryType == ST_GEOM_TYPE_FACINGLEAF)
|
||||
{
|
||||
float3 anchor = float3(vTexcoord1.zw, vTexcoord2.w);
|
||||
float3 facingPosition = vReturnPos - anchor;
|
||||
|
||||
// face camera-facing leaf to camera
|
||||
float offsetLen = length(facingPosition);
|
||||
facingPosition = float3(facingPosition.x, -facingPosition.z, facingPosition.y);
|
||||
float4x4 itmv = transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V));
|
||||
facingPosition = mul(facingPosition.xyz, (float3x3)itmv);
|
||||
facingPosition = normalize(facingPosition) * offsetLen; // make sure the offset vector is still scaled
|
||||
|
||||
vReturnPos = facingPosition + anchor;
|
||||
}
|
||||
|
||||
// wind
|
||||
if ((iWindQuality > 0) && (length(_ST_WindVector) > 0))
|
||||
{
|
||||
float3 rotatedWindVector = TransformWorldToObjectDir(_ST_WindVector.xyz);
|
||||
float windLength = length(rotatedWindVector);
|
||||
if (windLength < 1.0e-5)
|
||||
{
|
||||
// sanity check that wind data is available
|
||||
return vReturnPos;
|
||||
}
|
||||
rotatedWindVector /= windLength;
|
||||
|
||||
float4x4 matObjectToWorld = GetObjectToWorldMatrix();
|
||||
float3 treePos = GetAbsolutePositionWS(float3(matObjectToWorld[0].w, matObjectToWorld[1].w, matObjectToWorld[2].w));
|
||||
|
||||
if (!bBillboard)
|
||||
{
|
||||
// leaves
|
||||
if (geometryType > ST_GEOM_TYPE_FROND)
|
||||
{
|
||||
// remove anchor position
|
||||
float3 anchor = float3(vTexcoord1.zw, vTexcoord2.w);
|
||||
vReturnPos -= anchor;
|
||||
|
||||
// leaf wind
|
||||
if ((iWindQuality == ST_WIND_QUALITY_FAST) || (iWindQuality == ST_WIND_QUALITY_BETTER) || (iWindQuality == ST_WIND_QUALITY_BEST))
|
||||
{
|
||||
bool bBestWind = (iWindQuality == ST_WIND_QUALITY_BEST);
|
||||
float leafWindTrigOffset = anchor.x + anchor.y;
|
||||
vReturnPos = LeafWind(bBestWind, leafTwo, vReturnPos, vNormal, vTexcoord3.x, float3(0, 0, 0), vTexcoord3.y, vTexcoord3.z, leafWindTrigOffset, rotatedWindVector);
|
||||
}
|
||||
|
||||
// move back out to anchor
|
||||
vReturnPos += anchor;
|
||||
}
|
||||
|
||||
// frond wind
|
||||
bool bPalmWind = false;
|
||||
if (iWindQuality == ST_WIND_QUALITY_PALM)
|
||||
{
|
||||
bPalmWind = true;
|
||||
if (geometryType == ST_GEOM_TYPE_FROND)
|
||||
{
|
||||
vReturnPos = RippleFrond(vReturnPos, vNormal, vTexcoord0.x, vTexcoord0.y, vTexcoord3.x, vTexcoord3.y, vTexcoord3.z);
|
||||
}
|
||||
}
|
||||
|
||||
// branch wind (applies to all 3D geometry)
|
||||
if ((iWindQuality == ST_WIND_QUALITY_BETTER) || (iWindQuality == ST_WIND_QUALITY_BEST) || (iWindQuality == ST_WIND_QUALITY_PALM))
|
||||
{
|
||||
float3 rotatedBranchAnchor = TransformWorldToObjectDir(_ST_WindBranchAnchor.xyz) * _ST_WindBranchAnchor.w;
|
||||
vReturnPos = BranchWind(bPalmWind, vReturnPos, treePos, float4(vTexcoord0.zw, 0, 0), rotatedWindVector, rotatedBranchAnchor);
|
||||
}
|
||||
}
|
||||
|
||||
// global wind
|
||||
float globalWindTime = _ST_WindGlobal.x;
|
||||
//#if defined(EFFECT_BILLBOARD) && defined(UNITY_INSTANCING_ENABLED)
|
||||
// globalWindTime += UNITY_ACCESS_INSTANCED_PROP(STWind, _GlobalWindTime);
|
||||
//#endif
|
||||
vReturnPos = GlobalWind(vReturnPos, treePos, true, rotatedWindVector, globalWindTime);
|
||||
}
|
||||
|
||||
return vReturnPos;
|
||||
}
|
||||
|
||||
// This version is used by ShaderGraph
|
||||
void SpeedTreeWind_float(float3 vPos, float3 vNormal, float4 vTexcoord0, float4 vTexcoord1, float4 vTexcoord2, float4 vTexcoord3, int iWindQuality, bool bBillboard, bool bCrossfade, out float3 outPos)
|
||||
{
|
||||
if (iWindQuality != ST_WIND_QUALITY_NONE)
|
||||
{
|
||||
outPos = SpeedTreeWind(vPos, vNormal, vTexcoord0, vTexcoord1, vTexcoord2, vTexcoord3, iWindQuality, bBillboard, bCrossfade);
|
||||
}
|
||||
else
|
||||
outPos = vPos;
|
||||
|
||||
}
|
||||
#endif // SPEEDTREE_WIND_INCLUDED
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8b4aa8c48881d4142b1c30e408b503d8
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e9398b7940890a74eafc240b5a593541
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
PackedVaryings vert(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
output = BuildVaryings(input);
|
||||
PackedVaryings packedOutput = PackVaryings(output);
|
||||
return packedOutput;
|
||||
}
|
||||
|
||||
half4 frag(PackedVaryings packedInput) : SV_TARGET
|
||||
{
|
||||
Varyings unpacked = UnpackVaryings(packedInput);
|
||||
|
||||
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(unpacked);
|
||||
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
|
||||
|
||||
return surfaceDescription.Out;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0db5a27336918594d860a43da98f2b47
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
Varyings BuildVaryings(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
|
||||
// Returns the camera relative position (if enabled)
|
||||
float3 positionWS = TransformObjectToWorld(input.positionOS);
|
||||
|
||||
#ifdef ATTRIBUTES_NEED_NORMAL
|
||||
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
|
||||
#else
|
||||
// Required to compile ApplyVertexModification that doesn't use normal.
|
||||
float3 normalWS = float3(0.0, 0.0, 0.0);
|
||||
#endif
|
||||
|
||||
#ifdef ATTRIBUTES_NEED_TANGENT
|
||||
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
|
||||
#endif
|
||||
|
||||
#ifdef VARYINGS_NEED_POSITION_WS
|
||||
output.positionWS = positionWS;
|
||||
#endif
|
||||
|
||||
#ifdef VARYINGS_NEED_POSITIONPREDISPLACEMENT_WS
|
||||
output.positionPredisplacementWS = positionWS;
|
||||
#endif
|
||||
|
||||
#ifdef VARYINGS_NEED_NORMAL_WS
|
||||
output.normalWS = normalize(normalWS);
|
||||
#endif
|
||||
|
||||
#ifdef VARYINGS_NEED_TANGENT_WS
|
||||
output.tangentWS = normalize(tangentWS);
|
||||
#endif
|
||||
|
||||
output.positionCS = TransformWorldToHClip(positionWS);
|
||||
|
||||
#if defined(VARYINGS_NEED_TEXCOORD0) || defined(VARYINGS_DS_NEED_TEXCOORD0)
|
||||
output.texCoord0 = input.uv0;
|
||||
#endif
|
||||
#if defined(VARYINGS_NEED_TEXCOORD1) || defined(VARYINGS_DS_NEED_TEXCOORD1)
|
||||
output.texCoord1 = input.uv1;
|
||||
#endif
|
||||
#if defined(VARYINGS_NEED_TEXCOORD2) || defined(VARYINGS_DS_NEED_TEXCOORD2)
|
||||
output.texCoord2 = input.uv2;
|
||||
#endif
|
||||
#if defined(VARYINGS_NEED_TEXCOORD3) || defined(VARYINGS_DS_NEED_TEXCOORD3)
|
||||
output.texCoord3 = input.uv3;
|
||||
#endif
|
||||
|
||||
#if defined(VARYINGS_NEED_COLOR) || defined(VARYINGS_DS_NEED_COLOR)
|
||||
output.color = input.color;
|
||||
#endif
|
||||
|
||||
#if defined(VARYINGS_NEED_VERTEXID)
|
||||
output.vertexID = input.vertexID;
|
||||
#endif
|
||||
|
||||
#ifdef VARYINGS_NEED_VIEWDIRECTION_WS
|
||||
output.viewDirectionWS = _WorldSpaceCameraPos.xyz - positionWS;
|
||||
#endif
|
||||
|
||||
#ifdef VARYINGS_NEED_BITANGENT_WS
|
||||
output.bitangentWS = cross(normalWS, tangentWS.xyz) * tangentWS.w;
|
||||
#endif
|
||||
|
||||
#ifdef VARYINGS_NEED_SCREENPOSITION
|
||||
output.screenPosition = ComputeScreenPos(output.positionCS, _ProjectionParams.x);
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1634e4cba986f4a4aabc82c280e09d13
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// This file was automatically generated. Please don't edit by hand.
|
||||
//
|
||||
|
||||
#ifndef SHADERCONFIG_CS_HLSL
|
||||
#define SHADERCONFIG_CS_HLSL
|
||||
//
|
||||
// UnityEngine.Rendering.HighDefinition.ShaderOptions: static fields
|
||||
//
|
||||
#define SHADEROPTIONS_VELOCITY_IN_GBUFFER (0)
|
||||
#define SHADEROPTIONS_PACK_GBUFFER_IN_U16 (0)
|
||||
#define SHADEROPTIONS_CAMERA_RELATIVE_RENDERING (1)
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c6472a689b6ae34e806881d3066cfb3
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,284 @@
|
|||
// UNITY_SHADER_NO_UPGRADE
|
||||
|
||||
#ifndef UNITY_SHADER_VARIABLES_INCLUDED
|
||||
#define UNITY_SHADER_VARIABLES_INCLUDED
|
||||
|
||||
#include "ShaderConfig.cs.hlsl"
|
||||
|
||||
// CAUTION:
|
||||
// Currently the shaders compiler always include regualr Unity shaderVariables, so I get a conflict here were UNITY_SHADER_VARIABLES_INCLUDED is already define, this need to be fixed.
|
||||
// As I haven't change the variables name yet, I simply don't define anything, and I put the transform function at the end of the file outside the guard header.
|
||||
// This need to be fixed.
|
||||
|
||||
#if defined (DIRECTIONAL_COOKIE) || defined (DIRECTIONAL)
|
||||
#define USING_DIRECTIONAL_LIGHT
|
||||
#endif
|
||||
|
||||
#if defined(UNITY_SINGLE_PASS_STEREO) || defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
#define USING_STEREO_MATRICES
|
||||
#endif
|
||||
|
||||
#if defined(USING_STEREO_MATRICES)
|
||||
#define glstate_matrix_projection unity_StereoMatrixP[unity_StereoEyeIndex]
|
||||
#define unity_MatrixV unity_StereoMatrixV[unity_StereoEyeIndex]
|
||||
#define unity_MatrixInvV unity_StereoMatrixInvV[unity_StereoEyeIndex]
|
||||
#define unity_MatrixVP unity_StereoMatrixVP[unity_StereoEyeIndex]
|
||||
|
||||
#define unity_CameraProjection unity_StereoCameraProjection[unity_StereoEyeIndex]
|
||||
#define unity_CameraInvProjection unity_StereoCameraInvProjection[unity_StereoEyeIndex]
|
||||
#define unity_WorldToCamera unity_StereoWorldToCamera[unity_StereoEyeIndex]
|
||||
#define unity_CameraToWorld unity_StereoCameraToWorld[unity_StereoEyeIndex]
|
||||
#define _WorldSpaceCameraPos unity_StereoWorldSpaceCameraPos[unity_StereoEyeIndex]
|
||||
#endif
|
||||
|
||||
#define UNITY_LIGHTMODEL_AMBIENT (glstate_lightmodel_ambient * 2)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
CBUFFER_START(UnityPerCamera)
|
||||
// Time (t = time since current level load) values from Unity
|
||||
float4 _Time; // (t/20, t, t*2, t*3)
|
||||
float4 _LastTime; // Last frame time (t/20, t, t*2, t*3)
|
||||
float4 _SinTime; // sin(t/8), sin(t/4), sin(t/2), sin(t)
|
||||
float4 _CosTime; // cos(t/8), cos(t/4), cos(t/2), cos(t)
|
||||
float4 unity_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt
|
||||
float4 _TimeParameters;
|
||||
|
||||
#if !defined(USING_STEREO_MATRICES)
|
||||
float3 _WorldSpaceCameraPos;
|
||||
#endif
|
||||
|
||||
// x = 1 or -1 (-1 if projection is flipped)
|
||||
// y = near plane
|
||||
// z = far plane
|
||||
// w = 1/far plane
|
||||
float4 _ProjectionParams;
|
||||
|
||||
// x = width
|
||||
// y = height
|
||||
// z = 1 + 1.0/width
|
||||
// w = 1 + 1.0/height
|
||||
float4 _ScreenParams;
|
||||
|
||||
// Values used to linearize the Z buffer (http://www.humus.name/temp/Linearize%20depth.txt)
|
||||
// x = 1-far/near
|
||||
// y = far/near
|
||||
// z = x/far
|
||||
// w = y/far
|
||||
// or in case of a reversed depth buffer (UNITY_REVERSED_Z is 1)
|
||||
// x = -1+far/near
|
||||
// y = 1
|
||||
// z = x/far
|
||||
// w = 1/far
|
||||
float4 _ZBufferParams;
|
||||
|
||||
// x = orthographic camera's width
|
||||
// y = orthographic camera's height
|
||||
// z = unused
|
||||
// w = 1.0 if camera is ortho, 0.0 if perspective
|
||||
float4 unity_OrthoParams;
|
||||
CBUFFER_END
|
||||
|
||||
|
||||
CBUFFER_START(UnityPerCameraRare)
|
||||
float4 unity_CameraWorldClipPlanes[6];
|
||||
|
||||
#if !defined(USING_STEREO_MATRICES)
|
||||
// Projection matrices of the camera. Note that this might be different from projection matrix
|
||||
// that is set right now, e.g. while rendering shadows the matrices below are still the projection
|
||||
// of original camera.
|
||||
float4x4 unity_CameraProjection;
|
||||
float4x4 unity_CameraInvProjection;
|
||||
float4x4 unity_WorldToCamera;
|
||||
float4x4 unity_CameraToWorld;
|
||||
#endif
|
||||
CBUFFER_END
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
CBUFFER_START(UnityPerDraw)
|
||||
#ifdef UNITY_USE_PREMULTIPLIED_MATRICES
|
||||
float4x4 glstate_matrix_mvp;
|
||||
float4x4 glstate_matrix_modelview0;
|
||||
float4x4 glstate_matrix_invtrans_modelview0;
|
||||
#endif
|
||||
|
||||
float4x4 unity_ObjectToWorld;
|
||||
float4x4 unity_WorldToObject;
|
||||
float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
|
||||
float4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms
|
||||
|
||||
float4 unity_LightmapST;
|
||||
float4 unity_DynamicLightmapST;
|
||||
|
||||
// SH lighting environment
|
||||
float4 unity_SHAr;
|
||||
float4 unity_SHAg;
|
||||
float4 unity_SHAb;
|
||||
float4 unity_SHBr;
|
||||
float4 unity_SHBg;
|
||||
float4 unity_SHBb;
|
||||
float4 unity_SHC;
|
||||
|
||||
// x = Disabled(0)/Enabled(1)
|
||||
// y = Computation are done in global space(0) or local space(1)
|
||||
// z = Texel size on U texture coordinate
|
||||
float4 unity_ProbeVolumeParams;
|
||||
float4x4 unity_ProbeVolumeWorldToObject;
|
||||
float3 unity_ProbeVolumeSizeInv;
|
||||
float3 unity_ProbeVolumeMin;
|
||||
|
||||
// This contain occlusion factor from 0 to 1 for dynamic objects (no SH here)
|
||||
float4 unity_ProbesOcclusion;
|
||||
|
||||
// HDR environment map decode instructions
|
||||
half4 unity_SpecCube0_HDR;
|
||||
CBUFFER_END
|
||||
|
||||
#if defined(USING_STEREO_MATRICES)
|
||||
CBUFFER_START(UnityStereoGlobals)
|
||||
float4x4 unity_StereoMatrixP[2];
|
||||
float4x4 unity_StereoMatrixV[2];
|
||||
float4x4 unity_StereoMatrixInvV[2];
|
||||
float4x4 unity_StereoMatrixVP[2];
|
||||
|
||||
float4x4 unity_StereoCameraProjection[2];
|
||||
float4x4 unity_StereoCameraInvProjection[2];
|
||||
float4x4 unity_StereoWorldToCamera[2];
|
||||
float4x4 unity_StereoCameraToWorld[2];
|
||||
|
||||
float3 unity_StereoWorldSpaceCameraPos[2];
|
||||
float4 unity_StereoScaleOffset[2];
|
||||
CBUFFER_END
|
||||
#endif
|
||||
|
||||
#if defined(UNITY_STEREO_MULTIVIEW_ENABLED) && defined(SHADER_STAGE_VERTEX)
|
||||
#define unity_StereoEyeIndex UNITY_VIEWID
|
||||
UNITY_DECLARE_MULTIVIEW(2);
|
||||
#elif defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
static uint unity_StereoEyeIndex;
|
||||
#elif defined(UNITY_SINGLE_PASS_STEREO)
|
||||
CBUFFER_START(UnityStereoEyeIndex)
|
||||
int unity_StereoEyeIndex;
|
||||
CBUFFER_END
|
||||
#endif
|
||||
|
||||
CBUFFER_START(UnityPerDrawRare)
|
||||
float4x4 glstate_matrix_transpose_modelview0;
|
||||
CBUFFER_END
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
CBUFFER_START(UnityPerFrame)
|
||||
float4 glstate_lightmodel_ambient;
|
||||
float4 unity_AmbientSky;
|
||||
float4 unity_AmbientEquator;
|
||||
float4 unity_AmbientGround;
|
||||
float4 unity_IndirectSpecColor;
|
||||
float4 unity_FogParams;
|
||||
half4 unity_FogColor;
|
||||
|
||||
#if !defined(USING_STEREO_MATRICES)
|
||||
float4x4 glstate_matrix_projection;
|
||||
float4x4 unity_MatrixV;
|
||||
float4x4 unity_MatrixInvV;
|
||||
float4x4 unity_MatrixVP;
|
||||
float4 unity_StereoScaleOffset;
|
||||
int unity_StereoEyeIndex;
|
||||
#endif
|
||||
|
||||
float3 unity_ShadowColor;
|
||||
uint _TaaFrameIndex; // [0, 7]
|
||||
CBUFFER_END
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// These are the samplers available in the HDRenderPipeline.
|
||||
// Avoid declaring extra samplers as they are 4x SGPR each on GCN.
|
||||
SAMPLER(s_linear_clamp_sampler);
|
||||
SAMPLER(s_trilinear_clamp_sampler);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TEXTURE2D(_MainDepthTexture);
|
||||
SAMPLER(sampler_MainDepthTexture);
|
||||
|
||||
// Main lightmap
|
||||
TEXTURE2D(unity_Lightmap);
|
||||
SAMPLER(samplerunity_Lightmap);
|
||||
TEXTURE2D_ARRAY(unity_Lightmaps);
|
||||
SAMPLER(samplerunity_Lightmaps);
|
||||
|
||||
// Dual or directional lightmap (always used with unity_Lightmap, so can share sampler)
|
||||
TEXTURE2D(unity_LightmapInd);
|
||||
TEXTURE2D_ARRAY(unity_LightmapsInd);
|
||||
|
||||
// Dynamic GI lightmap
|
||||
TEXTURE2D(unity_DynamicLightmap);
|
||||
SAMPLER(samplerunity_DynamicLightmap);
|
||||
|
||||
TEXTURE2D(unity_DynamicDirectionality);
|
||||
|
||||
// Default reflection probe
|
||||
TEXTURECUBE(unity_SpecCube0);
|
||||
SAMPLER(samplerunity_SpecCube0);
|
||||
|
||||
// We can have shadowMask only if we have lightmap, so no sampler
|
||||
TEXTURE2D(unity_ShadowMask);
|
||||
TEXTURE2D_ARRAY(unity_ShadowMasks);
|
||||
|
||||
// TODO: Change code here so probe volume use only one transform instead of all this parameters!
|
||||
TEXTURE3D(unity_ProbeVolumeSH);
|
||||
SAMPLER(samplerunity_ProbeVolumeSH);
|
||||
|
||||
CBUFFER_START(UnityVelocityPass)
|
||||
float4x4 unity_MatrixNonJitteredVP;
|
||||
float4x4 unity_MatrixPreviousVP;
|
||||
float4x4 unity_MatrixPreviousM;
|
||||
float4x4 unity_MatrixPreviousMI;
|
||||
//X : Use last frame positions (right now skinned meshes are the only objects that use this
|
||||
//Y : Force No Motion
|
||||
//Z : Z bias value
|
||||
float4 unity_MotionVectorsParams;
|
||||
CBUFFER_END
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// TODO: all affine matrices should be 3x4.
|
||||
// TODO: sort these vars by the frequency of use (descending), and put commonly used vars together.
|
||||
// Note: please use UNITY_MATRIX_X macros instead of referencing matrix variables directly.
|
||||
CBUFFER_START(UnityPerPass)
|
||||
float4x4 _PrevViewProjMatrix;
|
||||
float4x4 _ViewProjMatrix;
|
||||
float4x4 _NonJitteredViewProjMatrix;
|
||||
float4x4 _ViewMatrix;
|
||||
float4x4 _ProjMatrix;
|
||||
float4x4 _InvViewProjMatrix;
|
||||
float4x4 _InvViewMatrix;
|
||||
float4x4 _InvProjMatrix;
|
||||
float4 _InvProjParam;
|
||||
float4 _ScreenSize; // {w, h, 1/w, 1/h}
|
||||
float4 _FrustumPlanes[6]; // {(a, b, c) = N, d = -dot(N, P)} [L, R, T, B, N, F]
|
||||
CBUFFER_END
|
||||
|
||||
float4x4 OptimizeProjectionMatrix(float4x4 M)
|
||||
{
|
||||
// Matrix format (x = non-constant value).
|
||||
// Orthographic Perspective Combined(OR)
|
||||
// | x 0 0 x | | x 0 x 0 | | x 0 x x |
|
||||
// | 0 x 0 x | | 0 x x 0 | | 0 x x x |
|
||||
// | x x x x | | x x x x | | x x x x | <- oblique projection row
|
||||
// | 0 0 0 1 | | 0 0 x 0 | | 0 0 x x |
|
||||
// Notice that some values are always 0.
|
||||
// We can avoid loading and doing math with constants.
|
||||
M._21_41 = 0;
|
||||
M._12_42 = 0;
|
||||
return M;
|
||||
}
|
||||
|
||||
// For the shader graph node preview, we use the legacy unity matrices because they are pipeline agnostic.
|
||||
#include "ShaderVariablesMatrixDefsLegacyUnity.hlsl"
|
||||
|
||||
#include "ShaderVariablesFunctions.hlsl"
|
||||
|
||||
#endif // UNITY_SHADER_VARIABLES_INCLUDED
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2bc64066748469e48861ed835a8b806d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
#ifndef UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
|
||||
#define UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl"
|
||||
|
||||
// Note: '_WorldSpaceCameraPos' is set by the legacy Unity code.
|
||||
float3 GetPrimaryCameraPosition()
|
||||
{
|
||||
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
||||
return float3(0, 0, 0);
|
||||
#else
|
||||
return _WorldSpaceCameraPos;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Could be e.g. the position of a primary camera or a shadow-casting light.
|
||||
float3 GetCurrentViewPosition()
|
||||
{
|
||||
#if defined(SHADERPASS) && (SHADERPASS != SHADERPASS_SHADOWS)
|
||||
return GetPrimaryCameraPosition();
|
||||
#else
|
||||
// This is a generic solution.
|
||||
// However, for the primary camera, using '_WorldSpaceCameraPos' is better for cache locality,
|
||||
// and in case we enable camera-relative rendering, we can statically set the position is 0.
|
||||
return UNITY_MATRIX_I_V._14_24_34;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Returns the forward (central) direction of the current view in the world space.
|
||||
float3 GetViewForwardDir()
|
||||
{
|
||||
float4x4 viewMat = GetWorldToViewMatrix();
|
||||
return -viewMat[2].xyz;
|
||||
}
|
||||
|
||||
// Returns 'true' if the current view performs a perspective projection.
|
||||
bool IsPerspectiveProjection()
|
||||
{
|
||||
#if defined(SHADERPASS) && (SHADERPASS != SHADERPASS_SHADOWS)
|
||||
return (unity_OrthoParams.w == 0);
|
||||
#else
|
||||
// TODO: set 'unity_OrthoParams' during the shadow pass.
|
||||
return UNITY_MATRIX_P[3][3] == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Computes the world space view direction (pointing towards the viewer).
|
||||
float3 GetWorldSpaceNormalizeViewDir(float3 positionWS)
|
||||
{
|
||||
if (IsPerspectiveProjection())
|
||||
{
|
||||
// Perspective
|
||||
float3 V = GetCurrentViewPosition() - positionWS;
|
||||
return normalize(V);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Orthographic
|
||||
return -GetViewForwardDir();
|
||||
}
|
||||
}
|
||||
|
||||
// UNITY_MATRIX_V defines a right-handed view space with the Z axis pointing towards the viewer.
|
||||
// This function reverses the direction of the Z axis (so that it points forward),
|
||||
// making the view space coordinate system left-handed.
|
||||
void GetLeftHandedViewSpaceMatrices(out float4x4 viewMatrix, out float4x4 projMatrix)
|
||||
{
|
||||
viewMatrix = UNITY_MATRIX_V;
|
||||
viewMatrix._31_32_33_34 = -viewMatrix._31_32_33_34;
|
||||
|
||||
projMatrix = UNITY_MATRIX_P;
|
||||
projMatrix._13_23_33_43 = -projMatrix._13_23_33_43;
|
||||
}
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
#if (defined(SHADER_API_GLCORE) && !defined(SHADER_API_SWITCH)) || defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
|
||||
//GL with reversed z => z clip range is [near, -far] -> should remap in theory but dont do it in practice to save some perf (range is close enough)
|
||||
#define UNITY_Z_0_FAR_FROM_CLIPSPACE(coord) max(-(coord), 0)
|
||||
#else
|
||||
//D3d with reversed Z => z clip range is [near, 0] -> remapping to [0, far]
|
||||
//max is required to protect ourselves from near plane not being correct/meaningfull in case of oblique matrices.
|
||||
#define UNITY_Z_0_FAR_FROM_CLIPSPACE(coord) max(((1.0-(coord)/_ProjectionParams.y)*_ProjectionParams.z),0)
|
||||
#endif
|
||||
#elif UNITY_UV_STARTS_AT_TOP
|
||||
//D3d without reversed z => z clip range is [0, far] -> nothing to do
|
||||
#define UNITY_Z_0_FAR_FROM_CLIPSPACE(coord) (coord)
|
||||
#else
|
||||
//Opengl => z clip range is [-near, far] -> should remap in theory but dont do it in practice to save some perf (range is close enough)
|
||||
#define UNITY_Z_0_FAR_FROM_CLIPSPACE(coord) (coord)
|
||||
#endif
|
||||
|
||||
#endif // UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7084c0669cdb2af4ab8c669b3139e0df
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#ifdef UNITY_SHADER_VARIABLES_MATRIX_DEFS_HDCAMERA_INCLUDED
|
||||
#error Mixing HDCamera and legacy Unity matrix definitions
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED
|
||||
#define UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED
|
||||
|
||||
#define UNITY_MATRIX_M unity_ObjectToWorld
|
||||
#define UNITY_MATRIX_I_M unity_WorldToObject
|
||||
#define UNITY_MATRIX_V unity_MatrixV
|
||||
#define UNITY_MATRIX_I_V unity_MatrixInvV
|
||||
#define UNITY_MATRIX_P OptimizeProjectionMatrix(glstate_matrix_projection)
|
||||
#define UNITY_MATRIX_I_P _InvProjMatrix
|
||||
#define UNITY_MATRIX_VP unity_MatrixVP
|
||||
#define UNITY_MATRIX_I_VP _InvViewProjMatrix
|
||||
#define UNITY_MATRIX_MV mul(UNITY_MATRIX_V, UNITY_MATRIX_M)
|
||||
#define UNITY_MATRIX_T_MV transpose(UNITY_MATRIX_MV)
|
||||
#define UNITY_MATRIX_IT_MV transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V))
|
||||
#define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M)
|
||||
#define UNITY_PREV_MATRIX_M unity_MatrixPreviousM
|
||||
#define UNITY_PREV_MATRIX_I_M unity_MatrixPreviousMI
|
||||
|
||||
#endif // UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0d85288be460c884bba7ec9ef5c6684d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: de1079f91ae5b43499b7c7e4f1269884
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue