sebastienlagarde
8 年前
当前提交
76f890ea
共有 13 个文件被更改,包括 287 次插入 和 39 次删除
-
2Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
-
29Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
-
23Assets/ScriptableRenderLoop/UnityStandard/Shaders/Material/Material.hlsl
-
59Assets/ScriptableRenderLoop/UnityStandard/Shaders/ShaderVariables.hlsl
-
53Assets/ScriptableRenderLoop/UnityStandard/Shaders/UnityStandard.shader
-
4Assets/ScriptableRenderLoop/UnityStandard/UnityStandardRenderLoop.cs
-
60Assets/ScriptableRenderLoop/ShaderLibrary/Filtering.hlsl
-
8Assets/ScriptableRenderLoop/ShaderLibrary/Filtering.hlsl.meta
-
13Assets/ScriptableRenderLoop/UnityStandard/UnityStandardRenderLoop.asset
-
8Assets/ScriptableRenderLoop/UnityStandard/UnityStandardRenderLoop.asset.meta
-
59Assets/ScriptableRenderLoop/UnityStandard/Shaders/Lighting/Lighting.hlsl
-
8Assets/ScriptableRenderLoop/UnityStandard/Shaders/Lighting/Lighting.hlsl.meta
|
|||
// Ref: https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1 from MJP |
|||
// Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16. |
|||
// See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details |
|||
float4 SampleTextureCatmullRom(in Texture2D<float4> tex, in SamplerState linearSampler, in float2 uv, in float2 texSize) |
|||
{ |
|||
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding |
|||
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at |
|||
// location [1, 1] in the grid, where [0, 0] is the top left corner. |
|||
float2 samplePos = uv * texSize; |
|||
float2 texPos1 = floor(samplePos - 0.5f) + 0.5f; |
|||
|
|||
// Compute the fractional offset from our starting texel to our original sample location, which we'll |
|||
// feed into the Catmull-Rom spline function to get our filter weights. |
|||
float2 f = samplePos - texPos1; |
|||
float2 f2 = f * f; |
|||
float2 f3 = f2 * f; |
|||
|
|||
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier. |
|||
// These equations are pre-expanded based on our knowledge of where the texels will be located, |
|||
// which lets us avoid having to evaluate a piece-wise function. |
|||
float2 w0 = (1.0f / 6.0f) * (-3.0f * f3 + 6.0f * f2 - 3.0f * f); |
|||
float2 w1 = (1.0f / 6.0f) * (9.0f * f3 - 15.0f * f2 + 6.0f); |
|||
float2 w2 = (1.0f / 6.0f) * (-9.0f * f3 + 12.0f * f2 + 3.0f * f); |
|||
float2 w3 = (1.0f / 6.0f) * (3.0f * f3 - 3.0f * f2); |
|||
|
|||
// Otim by Vlad, to test |
|||
// float2 w0 = (1.0 / 2.0) * f * (-1.0 + f * (2.0 - f)); |
|||
// float2 w1 = (1.0 / 6.0) * f2 * (-15.0 + 9.0 * f)) + 1.0; |
|||
// float2 w2 = (1.0 / 6.0) * f * (3.0 + f * (12.0 - f * 9.0)); |
|||
// float2 w3 = (1.0 / 2.0) * f2 * (f - 1.0); |
|||
|
|||
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to |
|||
// simultaneously evaluate the middle 2 samples from the 4x4 grid. |
|||
float2 w12 = w1 + w2; |
|||
float2 offset12 = w2 / (w1 + w2); |
|||
|
|||
// Compute the final UV coordinates we'll use for sampling the texture |
|||
float2 texPos0 = texPos1 - 1; |
|||
float2 texPos3 = texPos1 + 2; |
|||
float2 texPos12 = texPos1 + offset12; |
|||
|
|||
texPos0 /= texSize; |
|||
texPos3 /= texSize; |
|||
texPos12 /= texSize; |
|||
|
|||
float4 result = 0.0f; |
|||
result += tex.SampleLevel(linearSampler, float2(texPos0.x, texPos0.y), 0.0f) * w0.x * w0.y; |
|||
result += tex.SampleLevel(linearSampler, float2(texPos12.x, texPos0.y), 0.0f) * w12.x * w0.y; |
|||
result += tex.SampleLevel(linearSampler, float2(texPos3.x, texPos0.y), 0.0f) * w3.x * w0.y; |
|||
|
|||
result += tex.SampleLevel(linearSampler, float2(texPos0.x, texPos12.y), 0.0f) * w0.x * w12.y; |
|||
result += tex.SampleLevel(linearSampler, float2(texPos12.x, texPos12.y), 0.0f) * w12.x * w12.y; |
|||
result += tex.SampleLevel(linearSampler, float2(texPos3.x, texPos12.y), 0.0f) * w3.x * w12.y; |
|||
|
|||
result += tex.SampleLevel(linearSampler, float2(texPos0.x, texPos3.y), 0.0f) * w0.x * w3.y; |
|||
result += tex.SampleLevel(linearSampler, float2(texPos12.x, texPos3.y), 0.0f) * w12.x * w3.y; |
|||
result += tex.SampleLevel(linearSampler, float2(texPos3.x, texPos3.y), 0.0f) * w3.x * w3.y; |
|||
|
|||
return result; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dac42c6a533d53b41b931e02431564fa |
|||
timeCreated: 1474355143 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: e5c35d625d1d6324a845b5d88af0ae92, type: 3} |
|||
m_Name: UnityStandardRenderLoop |
|||
m_EditorClassIdentifier: |
|
|||
fileFormatVersion: 2 |
|||
guid: bbb9d949788aad640a70f108f114474d |
|||
timeCreated: 1474382158 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_LIGHTING_INCLUDED |
|||
#define UNITY_LIGHTING_INCLUDED |
|||
|
|||
struct PunctualLightData |
|||
{ |
|||
float3 positionWS; |
|||
float invSqrAttenuationRadius; |
|||
float3 color; |
|||
float unused; |
|||
|
|||
float3 forward; |
|||
float diffuseScale; |
|||
|
|||
float3 up; |
|||
float specularScale; |
|||
|
|||
float3 right; |
|||
float shadowDimmer; |
|||
|
|||
float angleScale; |
|||
float angleOffset; |
|||
float2 unused2; |
|||
}; |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Attenuation functions |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// Ref: Moving Frostbite to PBR |
|||
float SmoothDistanceAttenuation(float squaredDistance, float invSqrAttenuationRadius) |
|||
{ |
|||
float factor = squaredDistance * invSqrAttenuationRadius; |
|||
float smoothFactor = saturate(1.0f - factor * factor); |
|||
return smoothFactor * smoothFactor; |
|||
} |
|||
|
|||
#define PUNCTUAL_LIGHT_THRESHOLD 0.01 // 1cm (in Unity 1 is 1m) |
|||
|
|||
float GetDistanceAttenuation(float3 unL, float invSqrAttenuationRadius) |
|||
{ |
|||
float sqrDist = dot(unL, unL); |
|||
float attenuation = 1.0f / (max(PUNCTUAL_LIGHT_THRESHOLD * PUNCTUAL_LIGHT_THRESHOLD, sqrDist)); |
|||
// Non physically based hack to limit light influence to attenuationRadius. |
|||
attenuation *= SmoothDistanceAttenuation(sqrDist, invSqrAttenuationRadius); |
|||
|
|||
return attenuation; |
|||
} |
|||
|
|||
float GetAngleAttenuation(float3 L, float3 lightDir, float lightAngleScale, float lightAngleOffset) |
|||
{ |
|||
float cd = dot(lightDir, L); |
|||
float attenuation = saturate(cd * lightAngleScale + lightAngleOffset); |
|||
// smooth the transition |
|||
attenuation *= attenuation; |
|||
|
|||
return attenuation; |
|||
} |
|||
|
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: 5b115c7d70db5004ab39a1cfbead4db7 |
|||
timeCreated: 1474359714 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue