Last active
August 23, 2023 14:05
-
-
Save NathoSteveo/fba45d8d2035eb83df726be24efb7025 to your computer and use it in GitHub Desktop.
[ Shadow Coord and Shadow Sobel files for Custom Functions in Shader Graph ]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
███╗░░██╗░█████╗░████████╗██╗░░██╗░█████╗░ ░██████╗████████╗███████╗██╗░░░██╗███████╗░█████╗░ | |
████╗░██║██╔══██╗╚══██╔══╝██║░░██║██╔══██╗ ██╔════╝╚══██╔══╝██╔════╝██║░░░██║██╔════╝██╔══██╗ | |
██╔██╗██║███████║░░░██║░░░███████║██║░░██║ ╚█████╗░░░░██║░░░█████╗░░╚██╗░██╔╝█████╗░░██║░░██║ | |
██║╚████║██╔══██║░░░██║░░░██╔══██║██║░░██║ ░╚═══██╗░░░██║░░░██╔══╝░░░╚████╔╝░██╔══╝░░██║░░██║ | |
██║░╚███║██║░░██║░░░██║░░░██║░░██║╚█████╔╝ ██████╔╝░░░██║░░░███████╗░░╚██╔╝░░███████╗╚█████╔╝ | |
╚═╝░░╚══╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░░╚═╝░╚════╝░ ╚═════╝░░░░╚═╝░░░╚══════╝░░░╚═╝░░░╚══════╝░╚════╝░ | |
*/ | |
//-------------------------------------------------------------------------------[ OPEN WORLD ] | |
#ifndef SHADOWCOORD_INCLUDED | |
#define SHADOWCOORD_INCLUDED | |
void ShadowCoordOut_float(float3 PosWS, inout float4 ShadowCoordOut) | |
{ | |
float4 shadowCoordOut = 1; | |
#ifndef SHADERGRAPH_PREVIEW | |
shadowCoordOut = TransformWorldToShadowCoord(PosWS); | |
#endif | |
ShadowCoordOut = shadowCoordOut; | |
} | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
███╗░░██╗░█████╗░████████╗██╗░░██╗░█████╗░ ░██████╗████████╗███████╗██╗░░░██╗███████╗░█████╗░ | |
████╗░██║██╔══██╗╚══██╔══╝██║░░██║██╔══██╗ ██╔════╝╚══██╔══╝██╔════╝██║░░░██║██╔════╝██╔══██╗ | |
██╔██╗██║███████║░░░██║░░░███████║██║░░██║ ╚█████╗░░░░██║░░░█████╗░░╚██╗░██╔╝█████╗░░██║░░██║ | |
██║╚████║██╔══██║░░░██║░░░██╔══██║██║░░██║ ░╚═══██╗░░░██║░░░██╔══╝░░░╚████╔╝░██╔══╝░░██║░░██║ | |
██║░╚███║██║░░██║░░░██║░░░██║░░██║╚█████╔╝ ██████╔╝░░░██║░░░███████╗░░╚██╔╝░░███████╗╚█████╔╝ | |
╚═╝░░╚══╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░░╚═╝░╚════╝░ ╚═════╝░░░░╚═╝░░░╚══════╝░░░╚═╝░░░╚══════╝░╚════╝░ | |
*/ | |
//-------------------------------------------------------------------------------[ OPEN WORLD ] | |
#ifndef SHADOWSOBEL_INCLUDED | |
#define SHADOWSOBEL_INCLUDED | |
static float2 sobelSamplePoints[9] = | |
{ | |
float2(-1, 1), float2(0, 1), float2(1, 1), | |
float2(-1, 0), float2(0, 0), float2(1, 0), | |
float2(-1, -1), float2(0, -1), float2(1, -1) | |
}; | |
static float sobelXKernel[9] = | |
{ | |
1, 0, -1, | |
2, 0, -2, | |
1, 0, -1 | |
}; | |
static float sobelYKernel[9] = | |
{ | |
1, 2, 1, | |
0, 0, 0, | |
-1, -2, -1 | |
}; | |
void ShadowSobelOperator_float(float4 shadowCoord, float dilation, inout float Out, inout float ShadowMap) | |
{ | |
#ifndef SHADERGRAPH_PREVIEW | |
ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData(); | |
float4 shadowMap_TexelSize = shadowSamplingData.shadowmapSize; | |
#endif | |
float sobelX = 0; | |
float sobelY = 0; | |
float shadowMap = 0; | |
#ifndef SHADERGRAPH_PREVIEW | |
[unroll] for (int i = 0; i < 9; i++) | |
{ | |
float shadowImage = MainLightRealtimeShadow(float4(shadowCoord.xy + sobelSamplePoints[i] * dilation * shadowMap_TexelSize.xy, shadowCoord.zw)); | |
sobelX += shadowImage * sobelXKernel[i]; | |
sobelY += shadowImage * sobelYKernel[i]; | |
} | |
shadowMap = MainLightRealtimeShadow(shadowCoord); | |
#endif | |
Out = sqrt(sobelX * sobelX + sobelY * sobelY); | |
ShadowMap = shadowMap; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment