|
|
|
|
|
|
#ifndef UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED |
|
|
|
#define UNITY_SHADER_VARIABLES_FUNCTIONS_INCLUDED |
|
|
|
|
|
|
|
float3 GetCameraPositionWS() |
|
|
|
{ |
|
|
|
return _WorldSpaceCameraPos; |
|
|
|
} |
|
|
|
|
|
|
|
float4x4 GetWorldToViewMatrix() |
|
|
|
{ |
|
|
|
return UNITY_MATRIX_V; |
|
|
|
|
|
|
return UNITY_MATRIX_VP; |
|
|
|
} |
|
|
|
|
|
|
|
float GetOddNegativeScale() |
|
|
|
real GetOddNegativeScale() |
|
|
|
{ |
|
|
|
return unity_WorldTransformParams.w; |
|
|
|
} |
|
|
|
|
|
|
return mul(GetWorldToViewMatrix(), float4(positionWS, 1.0)).xyz; |
|
|
|
return mul(GetWorldToViewMatrix(), real4(positionWS, 1.0)).xyz; |
|
|
|
return mul(GetObjectToWorldMatrix(), float4(positionOS, 1.0)).xyz; |
|
|
|
return mul(GetObjectToWorldMatrix(), real4(positionOS, 1.0)).xyz; |
|
|
|
} |
|
|
|
|
|
|
|
float3 TransformWorldToObject(float3 positionWS) |
|
|
|
|
|
|
|
|
|
|
float3 TransformObjectToWorldDir(float3 dirOS) |
|
|
|
real3 TransformObjectToWorldDir(real3 dirOS) |
|
|
|
return normalize(mul((float3x3)GetObjectToWorldMatrix(), dirOS)); |
|
|
|
return normalize(mul((real3x3)GetObjectToWorldMatrix(), dirOS)); |
|
|
|
float3 TransformWorldToObjectDir(float3 dirWS) |
|
|
|
real3 TransformWorldToObjectDir(real3 dirWS) |
|
|
|
return normalize(mul((float3x3)GetWorldToObjectMatrix(), dirWS)); |
|
|
|
return normalize(mul((real3x3)GetWorldToObjectMatrix(), dirWS)); |
|
|
|
float3 TransformObjectToWorldNormal(float3 normalOS) |
|
|
|
real3 TransformObjectToWorldNormal(real3 normalOS) |
|
|
|
{ |
|
|
|
#ifdef UNITY_ASSUME_UNIFORM_SCALING |
|
|
|
return UnityObjectToWorldDir(normalOS); |
|
|
|
|
|
|
return normalize(mul(normalOS, (float3x3)GetWorldToObjectMatrix())); |
|
|
|
return normalize(mul(normalOS, (real3x3)GetWorldToObjectMatrix())); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
return mul(GetWorldToHClipMatrix(), float4(positionWS, 1.0)); |
|
|
|
} |
|
|
|
|
|
|
|
float3x3 CreateWorldToTangent(float3 normal, float3 tangent, float flipSign) |
|
|
|
real3x3 CreateWorldToTangent(real3 normal, real3 tangent, real flipSign) |
|
|
|
float sgn = flipSign * GetOddNegativeScale(); |
|
|
|
float3 bitangent = cross(normal, tangent) * sgn; |
|
|
|
real sgn = flipSign * GetOddNegativeScale(); |
|
|
|
real3 bitangent = cross(normal, tangent) * sgn; |
|
|
|
return float3x3(tangent, bitangent, normal); |
|
|
|
return real3x3(tangent, bitangent, normal); |
|
|
|
float3 TransformTangentToWorld(float3 dirTS, float3x3 worldToTangent) |
|
|
|
real3 TransformTangentToWorld(real3 dirTS, real3x3 worldToTangent) |
|
|
|
float3 TransformWorldToTangent(float3 dirWS, float3x3 worldToTangent) |
|
|
|
real3 TransformWorldToTangent(real3 dirWS, real3x3 worldToTangent) |
|
|
|
float3 TransformTangentToObject(float3 dirTS, float3x3 worldToTangent) |
|
|
|
real3 TransformTangentToObject(real3 dirTS, real3x3 worldToTangent) |
|
|
|
float3 normalWS = mul(dirTS, worldToTangent); |
|
|
|
return mul((float3x3)GetWorldToObjectMatrix(), normalWS); |
|
|
|
real3 normalWS = mul(dirTS, worldToTangent); |
|
|
|
return mul((real3x3)GetWorldToObjectMatrix(), normalWS); |
|
|
|
float3 TransformObjectToTangent(float3 dirOS, float3x3 worldToTangent) |
|
|
|
real3 TransformObjectToTangent(real3 dirOS, real3x3 worldToTangent) |
|
|
|
{ |
|
|
|
return mul(worldToTangent, TransformObjectToWorldDir(dirOS)); |
|
|
|
} |