浏览代码

Addressed Sebastien and Alexandr PR feedbacks.

/main
Felipe Lira 7 年前
当前提交
cea04fcf
共有 9 个文件被更改,包括 57 次插入88 次删除
  1. 12
      ScriptableRenderPipeline/Core/ShaderLibrary/API/GLCore.hlsl
  2. 31
      ScriptableRenderPipeline/Core/ShaderLibrary/API/GLES2.hlsl
  3. 12
      ScriptableRenderPipeline/Core/ShaderLibrary/API/GLES3.hlsl
  4. 7
      ScriptableRenderPipeline/Core/ShaderLibrary/Common.hlsl
  5. 6
      ScriptableRenderPipeline/Core/ShaderLibrary/EntityLighting.hlsl
  6. 20
      ScriptableRenderPipeline/Core/ShaderLibrary/Packing.hlsl
  7. 34
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShaderLibrary/Core.hlsl
  8. 3
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShaderLibrary/InputSurface.hlsl
  9. 20
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShaderLibrary/Particles.hlsl

12
ScriptableRenderPipeline/Core/ShaderLibrary/API/GLCore.hlsl


// This file assume SHADER_API_GLCORE is defined
#ifndef SHADER_API_GLCORE
#error GLES.hlsl should not be included if SHADER_API_GLCORE is not defined
#endif
#define UNITY_UV_STARTS_AT_TOP 0
#define UNITY_REVERSED_Z 0

#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3)
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index))
#else
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2)
#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index)
#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) SAMPLE_TEXTURECUBE(textureName, samplerName, coord3)
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index)
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).rrrr
#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index).rrrr
#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) SAMPLE_TEXTURECUBE(textureName, samplerName, coord3).rrrr
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index).rrrr
#endif

31
ScriptableRenderPipeline/Core/ShaderLibrary/API/GLES2.hlsl


// This file assume SHADER_API_GLES is defined
#ifndef SHADER_API_GLES
#error GLES.hlsl should not be included if SHADER_API_GLES is not defined
#endif
#define UNITY_UV_STARTS_AT_TOP 0
#define UNITY_REVERSED_Z 0

#define SHADOW2D_TEXTURE_AND_SAMPLER sampler2DShadow
#define SHADOWCUBE_TEXTURE_AND_SAMPLER samplerCUBEShadow
#define SHADOW2D_SAMPLE(textureName, samplerName, coord3) shadow2D(textureName, coord3)
#define SHADOW3D_SAMPLE(textureName, samplerName, coord4) ((texCUBE(textureName,(coord4).xyz) < (coord4).w) ? 0.0 : 1.0)
#define SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) ((texCUBE(textureName,(coord4).xyz) < (coord4).w) ? 0.0 : 1.0)
#define SHADOW3D_SAMPLE(textureName, samplerName, coord4) ((texCUBE(textureName,(coord4).xyz).r < (coord4).w) ? 0.0 : 1.0)
#define SHADOWCUBE_SAMPLE(textureName, samplerName, coord4) ((texCUBE(textureName,(coord4).xyz).r < (coord4).w) ? 0.0 : 1.0)
#endif
// Texture util abstraction

#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) SHADOW2D_SAMPLE(textureName, samplerName, coord3)
#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, float4(coord3.xy, index, coord3.w))
#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOW3D_SAMPLE(textureName, samplerName, coord4)
#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) SHADOWCUBE_SAMPLE(textureName, samplerName, coord4)
#define LOAD_TEXTURE2D(textureName, unCoord2) ERROR_ON_UNSUPPORTED_FUNCTION(texelFetch)
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) ERROR_ON_UNSUPPORTED_FUNCTION(texelFetchLod)
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) ERROR_ON_UNSUPPORTED_FUNCTION(texelFetchBias)
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) ERROR_ON_UNSUPPORTED_FUNCTION(texelFetchArray)
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) ERROR_ON_UNSUPPORTED_FUNCTION(texelFetchLodArray)
#define LOAD_TEXTURE2D(textureName, unCoord2) half4(0, 0, 0, 0) // Not supported
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) half4(0, 0, 0, 0) // Not supported
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) half4(0, 0, 0, 0) // Not supported
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) half4(0, 0, 0, 0) // Not supported
#define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) half4(0, 0, 0, 0) // Not supported
// Gather not supported. Fallabck to regular texture sampling.
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2)
#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index)
#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) SAMPLE_TEXTURECUBE(textureName, samplerName, coord3)
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index)
// Gather not supported. Fallback to regular texture sampling.
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).rrrr
#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index).rrrr
#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) SAMPLE_TEXTURECUBE(textureName, samplerName, coord3).rrrr
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index).rrrr

12
ScriptableRenderPipeline/Core/ShaderLibrary/API/GLES3.hlsl


// This file assume SHADER_API_GLES3 is defined
#ifndef SHADER_API_GLES3
#error GLES.hlsl should not be included if SHADER_API_GLES3 is not defined
#endif
#define UNITY_UV_STARTS_AT_TOP 0
#define UNITY_REVERSED_Z 0

#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3)
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index))
#else
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2)
#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index)
#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) SAMPLE_TEXTURECUBE(textureName, samplerName, coord3)
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index)
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).rrrr
#define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index).rrrr
#define GATHER_TEXTURECUBE(textureName, samplerName, coord3) SAMPLE_TEXTURECUBE(textureName, samplerName, coord3).rrrr
#define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index).rrrr
#endif

7
ScriptableRenderPipeline/Core/ShaderLibrary/Common.hlsl


// Misc utilities
// ----------------------------------------------------------------------------
// Normalize that account for vectors with zero length
half3 SafeNormalize(half3 inVec)
{
half dp3 = max(1.e-4h, dot(inVec, inVec));
return inVec * rsqrt(dp3);
}
// Generates a triangle in homogeneous clip space, s.t.
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).
float2 GetFullScreenTriangleTexCoord(uint vertexID)

6
ScriptableRenderPipeline/Core/ShaderLibrary/EntityLighting.hlsl


return encodedColor.rgb * LIGHTMAP_DLDR_RANGE;
}
half3 DecodeHDRLightmap(half4 encodedIlluminance)
half3 DecodeLightmap(half4 encodedIlluminance)
{
#if defined(UNITY_LIGHTMAP_RGBM_ENCODING)
return UnpackLightmapRGBM(encodedIlluminance);

if (encodedLightmap)
{
half4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
illuminance = DecodeHDRLightmap(encodedIlluminance);
illuminance = DecodeLightmap(encodedIlluminance);
}
else
{

if (encodedLightmap)
{
half4 encodedIlluminance = SAMPLE_TEXTURE2D(lightmapTex, lightmapSampler, uv).rgba;
illuminance = DecodeHDRLightmap(encodedIlluminance);
illuminance = DecodeLightmap(encodedIlluminance);
}
else
{

20
ScriptableRenderPipeline/Core/ShaderLibrary/Packing.hlsl


#ifndef UNITY_PACKING_INCLUDED
#define UNITY_PACKING_INCLUDED
#if !defined(SHADER_API_GLES)
//-----------------------------------------------------------------------------
// Normal packing
//-----------------------------------------------------------------------------

}
// Unpack from normal map
float3 UnpackNormalRGB(float4 packedNormal, float scale = 1.0)
half3 UnpackNormalRGB(half4 packedNormal, half scale = 1.0)
float3 normal;
half3 normal;
float3 UnpackNormalAG(float4 packedNormal, float scale = 1.0)
half3 UnpackNormalAG(half4 packedNormal, half scale = 1.0)
float3 normal;
half3 normal;
normal.xy = packedNormal.wy * 2.0 - 1.0;
normal.xy *= scale;
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));

// Unpack normal as DXT5nm (1, y, 0, x) or BC5 (x, y, 0, 1)
float3 UnpackNormalmapRGorAG(float4 packedNormal, float scale = 1.0)
half3 UnpackNormalmapRGorAG(half4 packedNormal, half scale = 1.0)
{
// This do the trick
packedNormal.w *= packedNormal.x;

//-----------------------------------------------------------------------------
// HDR packing
//-----------------------------------------------------------------------------
// HDR Packing not defined in GLES2
#if !defined(SHADER_API_GLES)
// Ref: http://realtimecollisiondetection.net/blog/?p=15
float4 PackToLogLuv(float3 vRGB)

return float3(r, g, b);
}
#endif // SHADER_API_GLES
//-----------------------------------------------------------------------------
// Quaternion packing
//-----------------------------------------------------------------------------

return quat;
}
// Integer and Float packing not defined in GLES2
#if !defined(SHADER_API_GLES)
//-----------------------------------------------------------------------------
// Integer packing

34
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShaderLibrary/Core.hlsl


#define LIGHTWEIGHT_PIPELINE_CORE_INCLUDED
#include "ShaderLibrary/Common.hlsl"
#include "ShaderLibrary/Packing.hlsl"
#include "Input.hlsl"
#ifdef _NORMALMAP

return x * x * x * x;
}
half LerpOneTo(half b, half t)
{
half oneMinusT = 1 - t;
return oneMinusT + b * t;
}
}
half3 SafeNormalize(half3 inVec)
{
half dp3 = max(1.e-4h, dot(inVec, inVec));
return inVec * rsqrt(dp3);
}
// Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
// Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
half3 UnpackNormalmapRGorAG(half4 packedNormal, half bumpScale)
{
// This do the trick
packedNormal.x *= packedNormal.w;
half3 normal;
normal.xy = packedNormal.xy * 2 - 1;
normal.xy *= bumpScale;
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
return normal;
}
half3 UnpackNormalRGB(half4 packedNormal, half bumpScale)
{
half3 normal = packedNormal.xyz * 2 - 1;
normal.xy *= bumpScale;
return normal;
}
half3 UnpackNormal(half4 packedNormal)

3
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShaderLibrary/InputSurface.hlsl


#include "Core.hlsl"
#include "ShaderLibrary/Packing.hlsl"
#include "ShaderLibrary/CommonMaterial.hlsl"
#ifdef _SPECULAR_SETUP
#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_SpecGlossMap, sampler_SpecGlossMap, uv)

return SAMPLE_TEXTURE2D(_OcclusionMap, sampler_OcclusionMap, uv).g;
#else
half occ = SAMPLE_TEXTURE2D(_OcclusionMap, sampler_OcclusionMap, uv).g;
return LerpOneTo(occ, _OcclusionStrength);
return LerpWhiteTo(occ, _OcclusionStrength);
#endif
#else
return 1.0;

20
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShaderLibrary/Particles.hlsl


#include "Core.hlsl"
#include "InputSurface.hlsl"
#include "ShaderLibrary/Color.hlsl"
#endif
#if defined(_COLORCOLOR_ON)
half3 RGBtoHSV(half3 arg1)
{
half4 K = half4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
half4 P = lerp(half4(arg1.bg, K.wz), half4(arg1.gb, K.xy), step(arg1.b, arg1.g));
half4 Q = lerp(half4(P.xyw, arg1.r), half4(arg1.r, P.yzx), step(P.x, arg1.r));
half D = Q.x - min(Q.w, Q.y);
half E = 1e-10;
return half3(abs(Q.z + (Q.w - Q.y) / (6.0 * D + E)), D / (Q.x + E), Q.x);
}
half3 HSVtoRGB(half3 arg1)
{
half4 K = half4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
half3 P = abs(frac(arg1.xxx + K.xyz) * 6.0 - K.www);
return arg1.z * lerp(K.xxx, saturate(P - K.xxx), arg1.y);
}
#endif
// Color function

正在加载...
取消
保存