浏览代码

Merge branch 'LightCookies'

/main
Evgenii Golubev 8 年前
当前提交
4bf4a5aa
共有 6 个文件被更改,包括 42 次插入49 次删除
  1. 14
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 13
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightDefinition.cs
  3. 16
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightDefinition.cs.hlsl
  4. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.hlsl
  5. 41
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl
  6. 3
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl

14
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


// Light direction for directional and is opposite to the forward direction
directionalLightData.direction = -light.light.transform.forward;
directionalLightData.up = -light.light.transform.up;
directionalLightData.right = -light.light.transform.right;
directionalLightData.positionWS = light.light.transform.position;
directionalLightData.color = new Vector3(lightColorR, lightColorG, lightColorB);
directionalLightData.diffuseScale = additionalData.affectDiffuse ? 1.0f : 0.0f;

directionalLightData.cosAngle = 0.0f;
directionalLightData.sinAngle = 0.0f;
directionalLightData.shadowIndex = -1;
directionalLightData.cookieIndex = Int32.MinValue;
directionalLightData.cookieIndex = -1;
if (light.light.cookie.dimension == TextureDimension.Tex2D)
{
directionalLightData.cookieIndex = m_CookieTexArray.FetchSlice(light.light.cookie);
}
else // Cube
{
// Note the bitwise (one's) complement operator which flips the bits.
directionalLightData.cookieIndex = ~m_CubeCookieTexArray.FetchSlice(light.light.cookie);
}
directionalLightData.tileCookie = (light.light.cookie.wrapMode == TextureWrapMode.Repeat);
directionalLightData.cookieIndex = m_CookieTexArray.FetchSlice(light.light.cookie);
}
bool hasDirectionalShadows = light.light.shadows != LightShadows.None && shadowOutput.GetShadowSliceCountLightIndex(lightIndex) != 0;

13
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightDefinition.cs


public struct DirectionalLightData
{
public Vector3 direction;
public float diffuseScale;
public float diffuseScale;
public float invScaleX;
public float invScaleY;
public Vector3 right;
public float invScaleX;
public float invScaleY;
public bool tileCookie;
public float specularScale;
public float specularScale;
public int cookieIndex; // INT_MIN if unused; (i >= 0) ? (i2D = i) : (iCube = ~i)
public int cookieIndex; // -1 if unused
};

16
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightDefinition.cs.hlsl


float3 direction;
float diffuseScale;
float3 up;
float invScaleY;
float3 right;
float invScaleY;
bool tileCookie;
float3 color;
float specularScale;
float cosAngle;

{
return value.up;
}
float GetInvScaleY(DirectionalLightData value)
{
return value.invScaleY;
}
float3 GetRight(DirectionalLightData value)
{
return value.right;
}
float GetInvScaleX(DirectionalLightData value)
{
return value.invScaleX;

return value.positionWS;
}
float GetInvScaleY(DirectionalLightData value)
bool GetTileCookie(DirectionalLightData value)
return value.invScaleY;
return value.tileCookie;
}
float3 GetColor(DirectionalLightData value)
{

4
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.hlsl


TEXTURE2D_ARRAY(_CookieTextures);
SAMPLER2D(sampler_CookieTextures);
// Used by directional and point lights
// Used by point lights
TEXTURECUBE_ARRAY(_CookieCubeTextures);
SAMPLERCUBE(sampler_CookieCubeTextures);

#define SINGLE_PASS_CONTEXT_SAMPLE_COOKIE_CUBE_TEXTURES 0
// Used by directional and point lights.
// Used by point lights.
// Returns the color in the RGB components, and the transparency (lack of occlusion) in A.
float4 SampleCookieCube(LightLoopContext lightLoopContext, float3 coord, int index)
{

41
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl


illuminance *= shadowAttenuation;
}
[branch] if (lightData.cookieIndex != INT_MIN && illuminance > 0.0)
[branch] if (lightData.cookieIndex >= 0 && illuminance > 0.0)
float4 cookie;
float3 unL = positionWS - lightData.positionWS;
[branch] if (lightData.cookieIndex >= 0)
{
// The cookie is a 2D texture.
float3 unL = positionWS - lightData.positionWS;
// Project 'unL' onto the light's axes.
float3 right = cross(lightData.up, lightData.direction);
float2 coord = float2(dot(unL, right), dot(unL, lightData.up));
// Project 'unL' onto the light's axes.
float3 right = cross(lightData.up, lightData.direction);
float2 coord = float2(dot(unL, right), dot(unL, lightData.up));
// Rescale the texture.
coord.x *= lightData.invScaleX;
coord.y *= lightData.invScaleY;
// Rescale the texture.
coord.x *= lightData.invScaleX;
coord.y *= lightData.invScaleY;
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2.
coord = coord * 0.5 + 0.5;
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2.
coord = coord * 0.5 + 0.5;
// Tile the texture via wrapping. TODO: the sampler should do this for us.
cookie = SampleCookie2D(lightLoopContext, frac(coord), lightData.cookieIndex);
}
else
{
// The cookie is a cubemap. We flip the bits to get the real index.
lightData.cookieIndex = ~lightData.cookieIndex;
// Tile the texture if the 'repeat' wrap mode is enabled.
if (lightData.tileCookie) coord = frac(coord);
cookie = SampleCookieCube(lightLoopContext, L, lightData.cookieIndex);
}
float4 cookie = SampleCookie2D(lightLoopContext, coord, lightData.cookieIndex);
cookieColor = cookie.rgb;
illuminance *= cookie.a;

{
BSDF(V, L, positionWS, preLightData, bsdfData, diffuseLighting, specularLighting);
diffuseLighting *= lightData.color * illuminance * lightData.diffuseScale;
specularLighting *= lightData.color * illuminance * lightData.specularScale;
diffuseLighting *= (cookieColor * lightData.color) * (illuminance * lightData.diffuseScale);
specularLighting *= (cookieColor * lightData.color) * (illuminance * lightData.specularScale);
}
}

3
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


#define FLT_EPSILON 1.192092896e-07 // Smallest positive number, such that 1.0 + FLT_EPSILON != 1.0
#define FLT_MAX 3.402823466e+38 // Maximum representable floating-point number
#define INT_MIN -2147483648 // Minimum (signed) int value
#define INT_MAX 2147483647 // Maximum (signed) int value
#define MERGE_NAME(X, Y) X##Y
float DegToRad(float deg)

正在加载...
取消
保存