浏览代码

Added GetCameraPositionWS(). Converted core functions to use real.

/main
Felipe Lira 7 年前
当前提交
2c1cc95d
共有 5 个文件被更改,包括 28 次插入27 次删除
  1. 43
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/CoreFunctions.hlsl
  2. 5
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Input.hlsl
  3. 3
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl
  4. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticles.shader
  5. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardTerrain.shader

43
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/CoreFunctions.hlsl


#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));
}

5
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Input.hlsl


#include "InputBuiltin.hlsl"
#include "CoreFunctions.hlsl"
float3 GetCameraPosition()
{
return _WorldSpaceCameraPos;
}
#endif

3
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl


o.posWS = TransformObjectToWorld(v.vertex.xyz);
o.clipPos = TransformWorldToHClip(o.posWS);
o.viewDir = SafeNormalize(_WorldSpaceCameraPos - o.posWS);
o.viewDir = SafeNormalize(GetCameraPositionWS() - o.posWS);
// initializes o.normal and if _NORMALMAP also o.tangent and o.binormal
OUTPUT_NORMAL(v, o);

half3 indirectDiffuse = SampleGI(IN.lightmapUVOrVertexSH, normalWS);
float fogFactor = IN.fogFactorAndVertexLight.x;
// viewDirection should be normalized here, but we avoid doing it as it's close enough and we save some ALU.
half4 color = LightweightFragmentPBR(IN.posWS.xyz, normalWS, IN.viewDir, indirectDiffuse, IN.fogFactorAndVertexLight.yzw, surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.occlusion, surfaceData.emission, surfaceData.alpha);
ApplyFog(color.rgb, fogFactor);
return color;

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticles.shader


InitializeSurfaceData(IN, surfaceData);
float3 positionWS = IN.posWS.xyz;
half3 viewDirWS = SafeNormalize(_WorldSpaceCameraPos - positionWS);
half3 viewDirWS = SafeNormalize(GetCameraPositionWS() - positionWS);
half fogFactor = IN.posWS.w;
#if _NORMALMAP

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardTerrain.shader


indirectDiffuse = SampleLightmap(IN.uvControlAndLM.zw, normalWS);
#endif
half3 viewDirectionWS = SafeNormalize(_WorldSpaceCameraPos - IN.positionWS);
half3 viewDirectionWS = SafeNormalize(GetCameraPositionWS() - IN.positionWS);
half fogFactor = IN.fogFactorAndVertexLight.x;
half4 color = LightweightFragmentPBR(IN.positionWS, normalWS, viewDirectionWS, indirectDiffuse,
IN.fogFactorAndVertexLight.yzw, albedo, metallic, specular, smoothness, /* occlusion */ 1.0, /* emission */ half3(0, 0, 0), alpha);

正在加载...
取消
保存