mirror of https://github.com/teverse/teverse
one file
This commit is contained in:
parent
75d3631741
commit
a828a079cb
shaders/lighting/directional
|
@ -6,7 +6,61 @@ $input v_texcoord0, lightDirection, lightColour
|
|||
//
|
||||
|
||||
#include <teverse.sh>
|
||||
#include <../../instancedGeometry/lighting.sh>
|
||||
#define PI 3.1415926535f
|
||||
|
||||
float toClipSpaceDepth(float _depthTextureZ)
|
||||
{
|
||||
#if GLSL
|
||||
return _depthTextureZ * 2.0 - 1.0;
|
||||
#else
|
||||
return _depthTextureZ;
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 clipToWorld(mat4 _invViewProj, vec3 _clipPos)
|
||||
{
|
||||
vec4 wpos = mul(_invViewProj, vec4(_clipPos, 1.0) );
|
||||
return wpos.xyz / wpos.w;
|
||||
}
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float num = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return NdotH2;
|
||||
}
|
||||
|
||||
float GeometrySchlickGGX(float NdotV, float roughness)
|
||||
{
|
||||
float r = (roughness + 1.0);
|
||||
float k = (r*r) / 8.0;
|
||||
|
||||
float num = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return num / denom;
|
||||
}
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
||||
{
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
|
||||
vec3 fresnelSchlick(float cosTheta, vec3 F0)
|
||||
{
|
||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||
}
|
||||
|
||||
SAMPLER2D(sColour, 0);
|
||||
SAMPLER2D(sNormal, 1);
|
||||
|
|
Loading…
Reference in New Issue