140 lines
4.7 KiB
HLSL
140 lines
4.7 KiB
HLSL
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ImageBasedLighting.hlsl"
|
|
inline half Pow5(half x)
|
|
{
|
|
return x*x * x*x *x;
|
|
}
|
|
|
|
float3 AOMultiBounce( float3 BaseColor, float AO )
|
|
{
|
|
float3 a = 2.0404 * BaseColor - 0.3324;
|
|
float3 b = -4.7951 * BaseColor + 0.6417;
|
|
float3 c = 2.7552 * BaseColor + 0.6903;
|
|
return max( AO, ( ( AO * a + b ) * AO + c ) * AO );
|
|
}
|
|
|
|
half3 GlossyEnvironmentReflection_revert(half3 reflectVector, half perceptualRoughness, half occlusion)
|
|
{
|
|
#if defined(_ENVIRONMENTREFLECTIONS_OFF)
|
|
half3 irradiance;
|
|
half mip = PerceptualRoughnessToMipmapLevel(perceptualRoughness);
|
|
half4 encodedIrradiance = half4(SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectVector, mip));
|
|
|
|
irradiance = DecodeHDREnvironment(encodedIrradiance, unity_SpecCube0_HDR);
|
|
|
|
return irradiance * occlusion;
|
|
#else
|
|
|
|
return _GlossyEnvironmentColor.rgb * occlusion;
|
|
#endif // _ENVIRONMENTREFLECTIONS_OFF
|
|
}
|
|
|
|
half3 EnvBRDFApprox( half3 SpecularColor, half Roughness, half NoV )
|
|
{
|
|
// [ Lazarov 2013, "Getting More Physical in Call of Duty: Black Ops II" ]
|
|
// Adaptation to fit our G term.
|
|
const half4 c0 = { -1, -0.0275, -0.572, 0.022 };
|
|
const half4 c1 = { 1, 0.0425, 1.04, -0.04 };
|
|
half4 r = Roughness * c0 + c1;
|
|
half a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y;
|
|
half2 AB = half2( -1.04, 1.04 ) * a004 + r.zw;
|
|
|
|
// Anything less than 2% is physically impossible and is instead considered to be shadowing
|
|
// Note: this is needed for the 'specular' show flag to work, since it uses a SpecularColor of 0
|
|
AB.y *= saturate( 50.0 * SpecularColor.g );
|
|
|
|
return SpecularColor * AB.x + AB.y;
|
|
}
|
|
|
|
float GetSpecularOcclusion(float NoV, float RoughnessSq, float AO)
|
|
{
|
|
return saturate( pow( saturate(NoV + AO), RoughnessSq ) - 1 + AO );
|
|
}
|
|
|
|
float3 Diffuse_Lambert( float3 DiffuseColor )
|
|
{
|
|
return DiffuseColor * (1 / PI);
|
|
}
|
|
|
|
float D_GGX_UE4( float a2, float NoH )
|
|
{
|
|
float d = ( NoH * a2 - NoH ) * NoH + 1; // 2 mad
|
|
return a2 / ( PI*d*d ); // 4 mul, 1 rcp
|
|
}
|
|
|
|
float Vis_SmithJointApprox( float a2, float NoV, float NoL )
|
|
{
|
|
float a = sqrt(a2);
|
|
float Vis_SmithV = NoL * ( NoV * ( 1 - a ) + a );
|
|
float Vis_SmithL = NoV * ( NoL * ( 1 - a ) + a );
|
|
return 0.5 * rcp( Vis_SmithV + Vis_SmithL );
|
|
}
|
|
|
|
float3 F_Schlick_UE4( float3 SpecularColor, float VoH )
|
|
{
|
|
float Fc = Pow5( 1 - VoH ); // 1 sub, 3 mul
|
|
//return Fc + (1 - Fc) * SpecularColor; // 1 add, 3 mad
|
|
|
|
// Anything less than 2% is physically impossible and is instead considered to be shadowing
|
|
return saturate( 50.0 * SpecularColor.g ) * Fc + (1 - Fc) * SpecularColor;
|
|
|
|
}
|
|
|
|
void GetPivotPainterData_float(float2 uv3,float2 uv4,float4 vertexColor,out float customAlpha,out float RandomPerElement,out float3 Xvector,out float3 PivotPosit)
|
|
{
|
|
float3 vertColor = vertexColor.xyz * 2 - 1 ;
|
|
//#if defined(_ZAXIS)
|
|
Xvector = float3(-vertColor.x,-vertColor.y,vertColor.z);
|
|
//#else
|
|
Xvector = float3(-vertColor.x,vertColor.z,vertColor.y);
|
|
//#endif
|
|
customAlpha = vertexColor.w;
|
|
#if defined(_ZAXIS)
|
|
//PivotPosit = float3(-uv3.x,uv3.y,uv4.x);
|
|
PivotPosit = float3(-uv3.x,uv4.x,-uv3.y)*0.01;
|
|
#else
|
|
PivotPosit = float3(-uv3.x,uv4.x,-uv3.y);
|
|
#endif
|
|
RandomPerElement = uv4.y;
|
|
|
|
}
|
|
|
|
float RandomRange( float2 Seed,float Min,float Max )
|
|
{
|
|
float output =lerp(0,1,frac(sin(dot(Seed,float2(12.98,78.23))) * 43758.55 ));
|
|
return output;
|
|
}
|
|
|
|
float3 lerp3(float3 input1,float3 input2,float3 input3,float inputA)
|
|
{
|
|
float3 lerp1 = lerp(input1,input2,clamp(inputA * 2,0,1));
|
|
float3 lerp2 = lerp(lerp1,input3,clamp(inputA * 2 - 1,0,1));
|
|
return lerp2;
|
|
}
|
|
|
|
float3 RotateAroundAxis_Flus (float3 Vertex,float3 PivotPos,float3 Axis,float Angle)
|
|
{
|
|
float3 VertextToPivot = Vertex - PivotPos;
|
|
float AngleRadians = radians(Angle) * 0.5;
|
|
float3 sinAxis = normalize(Axis) * sin(AngleRadians);
|
|
float3 R = cross(sinAxis,VertextToPivot) + VertextToPivot * cos(AngleRadians);
|
|
return cross(sinAxis,R) * 2 + PivotPos + VertextToPivot;
|
|
}
|
|
float3 RotateAroundAxis( float3 Vertex, float3 PivotPos, float3 u, float Angle )
|
|
{
|
|
Vertex -= PivotPos;
|
|
float C = cos( Angle );
|
|
float S = sin( Angle );
|
|
float t = 1 - C;
|
|
float m00 = t * u.x * u.x + C;
|
|
float m01 = t * u.x * u.y - S * u.z;
|
|
float m02 = t * u.x * u.z + S * u.y;
|
|
float m10 = t * u.x * u.y + S * u.z;
|
|
float m11 = t * u.y * u.y + C;
|
|
float m12 = t * u.y * u.z - S * u.x;
|
|
float m20 = t * u.x * u.z - S * u.y;
|
|
float m21 = t * u.y * u.z + S * u.x;
|
|
float m22 = t * u.z * u.z + C;
|
|
float3x3 finalMatrix = float3x3( m00, m01, m02, m10, m11, m12, m20, m21, m22 );
|
|
return mul( finalMatrix, Vertex ) + PivotPos;
|
|
} |