testss
This commit is contained in:
@@ -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,110 @@
|
||||
// UNITY_SHADER_NO_UPGRADE
|
||||
#ifndef UNITY_GRAPHFUNCTIONS_INCLUDED
|
||||
#define UNITY_GRAPHFUNCTIONS_INCLUDED
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Included in generated graph shaders
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool IsGammaSpace()
|
||||
{
|
||||
#ifdef UNITY_COLORSPACE_GAMMA
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#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,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,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,63 @@
|
||||
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_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
|
||||
|
||||
#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,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,290 @@
|
||||
// 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(USING_STEREO_MATRICES) && defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
CBUFFER_START(UnityStereoEyeIndices)
|
||||
float4 unity_StereoEyeIndices[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,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,21 @@
|
||||
#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)
|
||||
|
||||
#endif // UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED
|
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
Reference in New Issue
Block a user