浏览代码

enable colored cookies and fix clamp on default spot cookie texture

/main
Filip Iliescu 8 年前
当前提交
863c9a52
共有 3 个文件被更改,包括 25 次插入26 次删除
  1. 3
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/ClassicDeferredPipeline.cs
  2. 44
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/LightingTemplate.hlsl
  3. 4
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/Soft.psd.meta

3
Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/ClassicDeferredPipeline.cs


var lightToWorld = light.localToWorld;
var worldToLight = lightToWorld.inverse;
cmd.SetGlobalMatrix ("unity_WorldToLight", lightToWorld.inverse);
props.SetMatrix ("_WorldToLight", lightToWorld.inverse);
float lightShadowNDXOrNot = (light.light.shadows != LightShadows.None) ? (float)lightNum : -1.0f;
props.SetFloat ("_LightIndexForShadowMatrixArray", lightShadowNDXOrNot);

44
Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/LightingTemplate.hlsl


outWPos = wpos;
}
static half4 debugLighting;
static float4 debugLighting;
int _LightIndexForShadowMatrixArray;

out half3 outLightDir,
out float outAtten,
out float outFadeDist,
out float4 outCookieColor,
float depth
)
{

float4 colorCookie = float4(1, 1, 1, 1);
OnChipDeferredFragSetup(i, uv, vpos, wpos, depth);
// needed? old shadow code is commented out, we switched to new shadow code .. aka sampleShadow()

half3 lightDir = normalize (tolight);
float4 uvCookie = mul (unity_WorldToLight, float4(wpos,1));
// negative bias because http://aras-p.info/blog/2010/01/07/screenspace-vs-mip-mapping/
float atten = tex2Dbias (_LightTexture0, float4(uvCookie.xy / uvCookie.w, 0, -8)).w;
colorCookie = tex2Dlod (_LightTexture0, float4(uvCookie.xy / uvCookie.w, 0, 0));
float atten = colorCookie.w;
// debug code to set a programmatic cookie
//float d0 = 0.65;
//float2 d1 = 2*(uvCookie.xy / uvCookie.w)-1;
//debugLighting = half4(d1, 0.0, 1.0);
//debugLighting = half4(frac(wpos), 1.0);
//float angularAtt = smoothstep(0.0, 1.0-d0, 1.0-length(d1));
//atten *= angularAtt;
//atten *= UnityDeferredComputeShadow (wpos, fadeDist, uv);
if (_LightIndexForShadowMatrixArray >= 0)
atten *= SampleShadow(SPOT_LIGHT, wpos, 0, _LightIndexForShadowMatrixArray);

float atten = 1.0;
//atten *= UnityDeferredComputeShadow (wpos, fadeDist, uv);
atten *= tex2Dbias (_LightTexture0, float4(mul(unity_WorldToLight, half4(wpos,1)).xy, 0, -8)).w;
colorCookie = tex2Dlod (_LightTexture0, float4(mul(unity_WorldToLight, half4(wpos,1)).xy, 0, 0));
atten *= colorCookie.w;
#endif //DIRECTIONAL_COOKIE
// point light case

float att = dot(tolight, tolight) * _LightPos.w;
float atten = tex2D (_LightTextureB0, att.rr).UNITY_ATTEN_CHANNEL;
// atten *= UnityDeferredComputeShadow (tolight, fadeDist, uv);
atten *= texCUBEbias(_LightTexture0, float4(mul(unity_WorldToLight, half4(wpos,1)).xyz, -8)).w;
colorCookie = texCUBElod(_LightTexture0, float4(mul(unity_WorldToLight, float4(wpos,1)).xyz, 0));
atten *= colorCookie.w;
#endif //POINT_COOKIE
#else
half3 lightDir = 0;

outLightDir = lightDir;
outAtten = atten;
outFadeDist = fadeDist;
outCookieColor = colorCookie;
}
#ifdef UNITY_FRAMEBUFFER_FETCH_AVAILABLE

float3 wpos;
float2 uv;
float atten, fadeDist;
float4 colorCookie = float4(1, 1, 1, 1);
//debugLighting = half4(0.0, 0.0, 0.0, 0.0);
//debugLighting = float4(0.0, 0.0, 0.0, 0.0);
OnChipDeferredCalculateLightParams (i, wpos, uv, light.dir, atten, fadeDist, vpDepth);
OnChipDeferredCalculateLightParams (i, wpos, uv, light.dir, atten, fadeDist, colorCookie, vpDepth);
OnChipDeferredCalculateLightParams (i, wpos, uv, light.dir, atten, fadeDist, 0.0);
OnChipDeferredCalculateLightParams (i, wpos, uv, light.dir, atten, fadeDist, colorCookie, 0.0);
light.color = _LightColor.rgb * atten;
#if defined (POINT_COOKIE) || defined (DIRECTIONAL_COOKIE) || defined (SPOT)
light.color = _LightColor.rgb * colorCookie.rgb * atten;
#else
light.color = _LightColor.rgb * atten;
#endif
#ifndef UNITY_FRAMEBUFFER_FETCH_AVAILABLE
// unpack Gbuffer

4
Assets/ScriptableRenderPipeline/MobileRenderPipeline/ClassicDeferred/Soft.psd.meta


textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
aniso: 0
mipBias: -1
wrapU: 1
wrapV: 1

alphaUsage: 2
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 4
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0

正在加载...
取消
保存