Dan
5 年前
当前提交
69e04488
共有 6 个文件被更改,包括 160 次插入 和 287 次删除
-
168Assets/Shaders/Shadows/BlurredShadowPlane.shadergraph
-
52Assets/Shaders/Shadows/BlurredShadowPlaneLighting.hlsl
-
1Assets/Shaders/Shadows/Materials/ShadowMat.mat
-
34Assets/Shaders/Shadows/PlaneContactShadows.hlsl
-
190Assets/Shaders/Shadows/Prefabs/ShadowObject.prefab
-
2ProjectSettings/ProjectSettings.asset
168
Assets/Shaders/Shadows/BlurredShadowPlane.shadergraph
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
void PlaneContactShadow_float(float rand, float3 Position, float dist, float depth, out float shadowAmount) |
|||
void PlaneContactShadow_float(float rand, float3 position, float dist, float depth, out float shadowAmount) |
|||
const int TOTAL_STEPS = 10; |
|||
float3 Direction = mainLight.direction; |
|||
float3 dirX = normalize(cross(Direction, float3(0, 1, 0))); |
|||
float3 dirY = cross(Direction, dirX); |
|||
for (int i = 0; i < 10; i++) |
|||
float3 direction = mainLight.direction; |
|||
float3 dirX = cross(direction, float3(0, 1, 0)); // Unit vector at right angle to light direction |
|||
dirX = length(dirX) == 0 ? float3(1, 0, 0) : normalize(dirX); //edge case incase the light direction is completely vertical |
|||
float3 dirY = cross(direction, dirX); // Unit vector at right angle to the light direction and dirX |
|||
for (int i = 0; i < TOTAL_STEPS; i++) |
|||
//float3 Normal = float3(cos(i * STAR_ANGLE + rand), 0, sin(i * STAR_ANGLE + rand)); |
|||
float3 Normal = -Direction + (cos(i * STAR_ANGLE + rand) * dirX + sin(i * STAR_ANGLE + rand) * dirY) * 0.3; |
|||
float3 posStep = Position - Normal * (i) * 0.1 * dist; |
|||
//"normal" is a vector that rotates STAR_ANGLE radians around the light direction every iteration; it faces opposite the light direction and |
|||
//is at a sharp angle with the light direction. This is to create the blurring effect. The starting orientation of the vector |
|||
//is randomized using the "rand" input. |
|||
float3 normal = -direction + (cos(i * STAR_ANGLE + rand) * dirX + sin(i * STAR_ANGLE + rand) * dirY) * 0.3; |
|||
//by multiplying the step distance by the number of iterations (i) pixels that are further from the object will also recieve shadow, but less. |
|||
float3 posStep = position - normal * i * 0.1 * dist; |
|||
// Get the XY position of the projected position to be checked against the depth texture |
|||
newPos += float4(0.5, 0.5, 0, 0); |
|||
newPos += float4(0.5, 0.5, 0, 0); |
|||
// Prevent the depth texture values from bleeding from one side to the other |
|||
newPos = clamp(newPos, 0, 0.999); |
|||
//Get the view space depth value of our projected point |
|||
newPos = clamp(newPos, 0, 0.999); |
|||
shadowAmount += 0.02 / dist * (10 - i) * saturate(dist - abs(-newPosView.z - LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(newPos.xy), _ZBufferParams))); |
|||
// Compare the view space depth of our projected point to the depth texture value at the same XY location |
|||
float depthCompare = saturate(dist - abs(-newPosView.z - LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(newPos.xy), _ZBufferParams))); |
|||
|
|||
//scale by 2 divided by the total number of steps squared, the total number of steps minus i, and scale inversely by dist |
|||
shadowAmount += 2.0 / (TOTAL_STEPS * TOTAL_STEPS) * (TOTAL_STEPS - i) * depthCompare / dist; |
|||
} |
|||
#endif |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue