first commit
This commit is contained in:
commit
0f859671ea
308 files changed
+18617
No files matched your search
@@ -0,0 +1,25 @@
|
||||
mat3 GetLightmapTBN(vec3 viewPos) {
|
||||
mat3 lightmapTBN = mat3(normalize(dFdx(viewPos)), normalize(dFdy(viewPos)), vec3(0.0));
|
||||
lightmapTBN[2] = cross(lightmapTBN[0], lightmapTBN[1]);
|
||||
|
||||
return lightmapTBN;
|
||||
}
|
||||
|
||||
float DirectionalLightmap(float lightmap, float lightmapRaw, vec3 normal, mat3 lightmapTBN) {
|
||||
if (lightmap < 0.001) return lightmap;
|
||||
|
||||
vec2 deriv = vec2(dFdx(lightmapRaw), dFdy(lightmapRaw)) * 256.0;
|
||||
vec3 dir = normalize(vec3(
|
||||
deriv.x * lightmapTBN[0] +
|
||||
0.0005 * lightmapTBN[2] +
|
||||
deriv.y * lightmapTBN[1]
|
||||
));
|
||||
|
||||
float pwr = clamp(dot(normal, dir), -1.0, 1.0);
|
||||
if (abs(pwr) > 0.0)
|
||||
pwr = pow(abs(pwr), DIRECTIONAL_LIGHTMAP_STRENGTH) * sign(pwr) * lightmap;
|
||||
if (length(deriv) > 0.001)
|
||||
lightmap = pow(lightmap, max(1.0 - pwr, 0.001));
|
||||
|
||||
return lightmap;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
const float normalThreshold = GENERATED_NORMAL_THRESHOLD;
|
||||
const float normalClamp = GENERATED_NORMAL_CLAMP;
|
||||
const float packSizeGN = GENERATED_NORMAL_RESOLUTION;
|
||||
|
||||
#ifndef GBUFFERS_HAND
|
||||
const float normalMult = GENERATED_NORMAL_MULT * 0.05;
|
||||
#else
|
||||
const float normalMult = GENERATED_NORMAL_MULT * 0.03;
|
||||
#endif
|
||||
|
||||
float GetDif(float lOriginalAlbedo, vec2 offsetCoord) {
|
||||
#ifndef GBUFFERS_WATER
|
||||
float lNearbyAlbedo = length(texture2D(texture, offsetCoord).rgb);
|
||||
#else
|
||||
vec4 textureSample = texture2D(texture, offsetCoord);
|
||||
float lNearbyAlbedo = length(textureSample.rgb * textureSample.a * 1);
|
||||
#endif
|
||||
|
||||
#ifdef GBUFFERS_ENTITIES
|
||||
lOriginalAlbedo = abs(lOriginalAlbedo - 1.0);
|
||||
lNearbyAlbedo = abs(lNearbyAlbedo - 1.0);
|
||||
#endif
|
||||
|
||||
float dif = lOriginalAlbedo - lNearbyAlbedo;
|
||||
|
||||
#ifdef GBUFFERS_ENTITIES
|
||||
dif = -dif;
|
||||
#endif
|
||||
|
||||
#ifndef GBUFFERS_WATER
|
||||
if (dif > 0.0) dif = max(dif - normalThreshold, 0.0);
|
||||
else dif = min(dif + normalThreshold, 0.0);
|
||||
#endif
|
||||
|
||||
return clamp(dif, -normalClamp, normalClamp);
|
||||
}
|
||||
|
||||
void GenerateNormals(inout vec3 normal, vec3 color) {
|
||||
#ifndef ENTITY_GN_AND_CT
|
||||
#if defined GBUFFERS_ENTITIES || defined GBUFFERS_HAND
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
vec2 absMidCoordPos2 = absMidCoordPos * 4.0;
|
||||
float lOriginalAlbedo = length(color.rgb);
|
||||
|
||||
float normalMult = max0(1 - mipDelta) * normalMult;
|
||||
|
||||
#ifndef SAFER_GENERATED_NORMALS
|
||||
vec2 offsetR = 16.0 / atlasSizeM;
|
||||
#else
|
||||
vec2 offsetR = max(absMidCoordPos2.x, absMidCoordPos2.y) * vec2(float(atlasSizeM.y) / float(atlasSizeM.x), 1);
|
||||
#endif
|
||||
offsetR /= packSizeGN;
|
||||
|
||||
vec2 midCoord = texCoord - midCoordPos;
|
||||
vec2 maxOffsetCoord = midCoord + absMidCoordPos;
|
||||
vec2 minOffsetCoord = midCoord - absMidCoordPos;
|
||||
if (normalMult > 0.0) {
|
||||
vec3 normalMap = vec3(0.0, 0.0, 1.0);
|
||||
|
||||
vec2 offsetCoord = texCoord + vec2( 0.0, offsetR.y);
|
||||
if (offsetCoord.y < maxOffsetCoord.y)
|
||||
normalMap.y += GetDif(lOriginalAlbedo, offsetCoord);
|
||||
|
||||
offsetCoord = texCoord + vec2( offsetR.x, 0.0);
|
||||
if (offsetCoord.x < maxOffsetCoord.x)
|
||||
normalMap.x += GetDif(lOriginalAlbedo, offsetCoord);
|
||||
|
||||
offsetCoord = texCoord + vec2( 0.0,-offsetR.y);
|
||||
if (offsetCoord.y > minOffsetCoord.y)
|
||||
normalMap.y -= GetDif(lOriginalAlbedo, offsetCoord);
|
||||
|
||||
offsetCoord = texCoord + vec2(-offsetR.x, 0.0);
|
||||
if (offsetCoord.x > minOffsetCoord.x)
|
||||
normalMap.x -= GetDif(lOriginalAlbedo, offsetCoord);
|
||||
|
||||
normalMap.xy *= normalMult;
|
||||
normalMap.xy = clamp(normalMap.xy, vec2(-1.0), vec2(1.0));
|
||||
|
||||
if (normalMap.xy != vec2(0.0, 0.0))
|
||||
normal = clamp(normalize(normalMap * tbnMatrix), vec3(-1.0), vec3(1.0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
//GGX area light approximation from Decima Engine: Advances in Lighting and AA presentation
|
||||
float GetNoHSquared(float radiusTan, float NoL, float NoV, float VoL) {
|
||||
float radiusCos = 1.0 / sqrt(1.0 + radiusTan * radiusTan);
|
||||
|
||||
float RoL = 2.0 * NoL * NoV - VoL;
|
||||
if (RoL >= radiusCos)
|
||||
return 1.0;
|
||||
|
||||
float rOverLengthT = radiusCos * radiusTan / sqrt(1.0 - RoL * RoL);
|
||||
float NoTr = rOverLengthT * (NoV - RoL * NoL);
|
||||
float VoTr = rOverLengthT * (2.0 * NoV * NoV - 1.0 - RoL * VoL);
|
||||
|
||||
float triple = sqrt(clamp(1.0 - NoL * NoL - NoV * NoV - VoL * VoL + 2.0 * NoL * NoV * VoL, 0.0, 1.0));
|
||||
|
||||
float NoBr = rOverLengthT * triple, VoBr = rOverLengthT * (2.0 * triple * NoV);
|
||||
float NoLVTr = NoL * radiusCos + NoV + NoTr, VoLVTr = VoL * radiusCos + 1.0 + VoTr;
|
||||
float p = NoBr * VoLVTr, q = NoLVTr * VoLVTr, s = VoBr * NoLVTr;
|
||||
float xNum = q * (-0.5 * p + 0.25 * VoBr * NoLVTr);
|
||||
float xDenom = p * p + s * ((s - 2.0 * p)) + NoLVTr * ((NoL * radiusCos + NoV) * VoLVTr * VoLVTr +
|
||||
q * (-0.5 * (VoLVTr + VoL * radiusCos) - 0.5));
|
||||
float twoX1 = 2.0 * xNum / (xDenom * xDenom + xNum * xNum);
|
||||
float sinTheta = twoX1 * xDenom;
|
||||
float cosTheta = 1.0 - twoX1 * xNum;
|
||||
NoTr = cosTheta * NoTr + sinTheta * NoBr;
|
||||
VoTr = cosTheta * VoTr + sinTheta * VoBr;
|
||||
|
||||
float newNoL = NoL * radiusCos + NoTr;
|
||||
float newVoL = VoL * radiusCos + VoTr;
|
||||
float NoH = NoV + newNoL;
|
||||
float HoH = 2.0 * newVoL + 2.0;
|
||||
return clamp(NoH * NoH / HoH, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float GGXTrowbridgeReitz(float NoHsqr, float roughness){
|
||||
float roughnessSqr = roughness * roughness;
|
||||
float distr = NoHsqr * (roughnessSqr - 1.0) + 1.0;
|
||||
return roughnessSqr / (3.14159 * distr * distr);
|
||||
}
|
||||
|
||||
float SchlickGGX(float NoL, float NoV, float roughness){
|
||||
float k = roughness * 0.5;
|
||||
|
||||
float smithL = 0.5 / (NoL * (1.0 - k) + k);
|
||||
float smithV = 0.5 / (NoV * (1.0 - k) + k);
|
||||
|
||||
return smithL * smithV;
|
||||
}
|
||||
|
||||
vec3 SphericalGaussianFresnel(float HoL, vec3 baseReflectance){
|
||||
float fresnel = exp2(((-5.55473 * HoL) - 6.98316) * HoL);
|
||||
return fresnel * (1.0 - baseReflectance) + baseReflectance;
|
||||
}
|
||||
|
||||
vec3 GGX(vec3 normal, vec3 viewPos, float smoothness, vec3 baseReflectance, float sunSize) {
|
||||
float roughness = max(1.0 - smoothness, 0.025); roughness *= roughness;
|
||||
viewPos = -viewPos;
|
||||
|
||||
vec3 halfVec = normalize(lightVec + viewPos);
|
||||
|
||||
float HoL = clamp(dot(halfVec, lightVec), 0.0, 1.0);
|
||||
float NoL = clamp(dot(normal, lightVec), 0.0, 1.0);
|
||||
float NoV = clamp(dot(normal, viewPos), -1.0, 1.0);
|
||||
float VoL = dot(lightVec, viewPos);
|
||||
|
||||
float NoHsqr = GetNoHSquared(sunSize, NoL, NoV, VoL);
|
||||
if (NoV < 0.0){
|
||||
NoHsqr = dot(normal, halfVec);
|
||||
NoHsqr *= NoHsqr;
|
||||
}
|
||||
NoV = max(NoV, 0.0);
|
||||
|
||||
float D = GGXTrowbridgeReitz(NoHsqr, roughness);
|
||||
vec3 F = SphericalGaussianFresnel(HoL, baseReflectance);
|
||||
float G = SchlickGGX(NoL, NoV, roughness);
|
||||
|
||||
float Fl = max(length(F), 0.001);
|
||||
vec3 Fn = F / Fl;
|
||||
|
||||
float specular = D * Fl * G;
|
||||
vec3 specular3 = specular / (1.0 + 0.03125 / 4.0 * specular) * Fn * NoL;
|
||||
|
||||
#ifndef SPECULAR_HIGHLIGHT_ROUGH
|
||||
specular3 *= 1.0 - roughness * roughness;
|
||||
#endif
|
||||
|
||||
return specular3;
|
||||
}
|
||||
|
||||
vec3 GetSpecularHighlight(vec3 normal, vec3 viewPos, float smoothness, vec3 baseReflectance,
|
||||
vec3 specularColor, vec3 shadow, float smoothLighting) {
|
||||
if (dot(shadow, shadow) < 0.00001) return vec3(0.0);
|
||||
#ifndef SPECULAR_HIGHLIGHT_ROUGH
|
||||
if (smoothness < 0.00002) return vec3(0.0);
|
||||
#endif
|
||||
|
||||
smoothLighting *= smoothLighting;
|
||||
|
||||
#ifdef END
|
||||
smoothness *= 0.75;
|
||||
#endif
|
||||
|
||||
vec3 specular = GGX(normal, normalize(viewPos), smoothness, baseReflectance,
|
||||
(0.025 * sunVisibility + 0.05) * ROUND_SUN_MOON_SIZE);
|
||||
specular *= shadow * shadowFade * smoothLighting;
|
||||
specular *= (1.0 - rainStrength) * (1.0 - rainStrength);
|
||||
|
||||
return specular * specularColor;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
void GetMaterials(out float smoothness, out float skyOcclusion, out vec3 normal, out vec3 fresnel3,
|
||||
vec2 coord) {
|
||||
vec3 specularData = texture2D(colortex3, coord).rgb;
|
||||
|
||||
smoothness = specularData.r;
|
||||
smoothness *= smoothness;
|
||||
smoothness /= 2.0 - smoothness;
|
||||
|
||||
skyOcclusion = specularData.g;
|
||||
#if REFLECTION_SKY_FALLOFF > 1
|
||||
skyOcclusion = clamp(1.0 - (1.0 - skyOcclusion) * REFLECTION_SKY_FALLOFF, 0.0, 1.0);
|
||||
#endif
|
||||
skyOcclusion *= skyOcclusion;
|
||||
|
||||
normal = DecodeNormal(texture2D(colortex6, coord).xy);
|
||||
|
||||
fresnel3 = texture2D(colortex7, coord).rgb * smoothness;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
void GetMaterials(out float smoothness, out float metalness, out float f0, inout float emission,
|
||||
inout float subsurface, out float porosity, out float ao, out vec3 normalMap,
|
||||
vec2 newCoord, vec2 dcdx, vec2 dcdy)
|
||||
{
|
||||
float emissionMat = 0.0;
|
||||
|
||||
|
||||
|
||||
#if MATERIAL_FORMAT == 0
|
||||
#ifdef PARALLAX
|
||||
vec4 specularMap = texture2DGradARB(specular, newCoord, dcdx, dcdy);
|
||||
#else
|
||||
vec4 specularMap = texture2D(specular, texCoord);
|
||||
#endif
|
||||
|
||||
smoothness = specularMap.r;
|
||||
|
||||
f0 = 0.04;
|
||||
metalness = specularMap.g;
|
||||
|
||||
emissionMat = specularMap.b * specularMap.b;
|
||||
|
||||
porosity = 0.5 - 0.5 * smoothness;
|
||||
subsurface = specularMap.a > 0.0 ? 1.0 - specularMap.a : 0.0;
|
||||
|
||||
#ifdef PARALLAX
|
||||
normalMap = texture2DGradARB(normals, newCoord, dcdx, dcdy).xyz * 2.0 - 1.0;
|
||||
#else
|
||||
normalMap = texture2D(normals, texCoord).xyz * 2.0 - 1.0;
|
||||
#endif
|
||||
ao = 1.0;
|
||||
|
||||
if (normalMap.x + normalMap.y < -1.999) normalMap = vec3(0.0, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
#if MATERIAL_FORMAT == 1
|
||||
vec4 specularMap = texture2DLod(specular, newCoord, 0);
|
||||
smoothness = specularMap.r;
|
||||
|
||||
f0 = specularMap.g;
|
||||
metalness = f0 >= 0.9 ? 1.0 : 0.0;
|
||||
|
||||
emissionMat = specularMap.a < 1.0 ? clamp(specularMap.a * 1.004 - 0.004, 0.0, 1.0) : 0.0;
|
||||
emissionMat *= emissionMat;
|
||||
|
||||
porosity = specularMap.b <= 0.251 ? specularMap.b * 3.984 : 0.0;
|
||||
subsurface = specularMap.b > 0.251 ? clamp(specularMap.b * 1.335 - 0.355, 0.0, 1.0) : 0.0;
|
||||
|
||||
#ifdef PARALLAX
|
||||
normalMap = vec3(texture2DGradARB(normals, newCoord, dcdx, dcdy).xy, 0.0) * 2.0 - 1.0;
|
||||
ao = texture2DGradARB(normals, newCoord, dcdx, dcdy).z;
|
||||
#else
|
||||
normalMap = vec3(texture2D(normals, texCoord).xy, 0.0) * 2.0 - 1.0;
|
||||
ao = texture2D(normals, texCoord).z;
|
||||
#endif
|
||||
|
||||
if (normalMap.x + normalMap.y > -1.999) {
|
||||
if (length(normalMap.xy) > 1.0) normalMap.xy = normalize(normalMap.xy);
|
||||
normalMap.z = sqrt(1.0 - dot(normalMap.xy, normalMap.xy));
|
||||
normalMap = normalize(clamp(normalMap, vec3(-1.0), vec3(1.0)));
|
||||
}else{
|
||||
normalMap = vec3(0.0, 0.0, 1.0);
|
||||
ao = 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if EMISSIVE == 2
|
||||
emission = mix(emissionMat, 1.0, emission);
|
||||
#else
|
||||
emission = emissionMat;
|
||||
#endif
|
||||
|
||||
#ifdef NORMAL_DAMPENING
|
||||
mipx = dcdx * atlasSize;
|
||||
mipy = dcdy * atlasSize;
|
||||
mipDelta = max(dot(mipx, mipx), dot(mipy, mipy));
|
||||
miplevel = max(0.25 * log2(mipDelta), 0.0);
|
||||
|
||||
normalMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalMap, 1.0 / exp2(miplevel)));
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if MATERIAL_FORMAT == 2
|
||||
vec4 specularMap = texture2DLod(specular, newCoord, 0);
|
||||
smoothness = specularMap.r;
|
||||
|
||||
f0 = specularMap.g;
|
||||
metalness = f0 >= 0.9 ? 1.0 : 0.0;
|
||||
|
||||
emissionMat = specularMap.a < 1.0 ? clamp(specularMap.a * 1.004 - 0.004, 0.0, 1.0) : 0.0;
|
||||
emissionMat *= emissionMat;
|
||||
|
||||
porosity = specularMap.b <= 0.251 ? specularMap.b * 3.984 : 0.0;
|
||||
subsurface = specularMap.b > 0.251 ? clamp(specularMap.b * 1.335 - 0.355, 0.0, 1.0) : 0.0;
|
||||
|
||||
#ifdef PARALLAX
|
||||
normalMap = vec3(texture2DGradARB(normals, newCoord, dcdx, dcdy).xy, 0.0) * 2.0 - 1.0;
|
||||
ao = texture2DGradARB(normals, newCoord, dcdx, dcdy).z;
|
||||
#else
|
||||
normalMap = vec3(texture2D(normals, texCoord).xy, 0.0) * 2.0 - 1.0;
|
||||
ao = texture2D(normals, texCoord).z;
|
||||
#endif
|
||||
|
||||
if (normalMap.x + normalMap.y > -1.999) {
|
||||
if (length(normalMap.xy) > 1.0) normalMap.xy = normalize(normalMap.xy);
|
||||
normalMap.z = sqrt(1.0 - dot(normalMap.xy, normalMap.xy));
|
||||
normalMap = normalize(clamp(normalMap, vec3(-1.0), vec3(1.0)));
|
||||
}else{
|
||||
normalMap = vec3(0.0, 0.0, 1.0);
|
||||
ao = 1.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if EMISSIVE == 2
|
||||
emission = mix(emissionMat, 1.0, emission);
|
||||
#else
|
||||
emission = emissionMat;
|
||||
#endif
|
||||
|
||||
#ifdef NORMAL_DAMPENING
|
||||
mipx = dcdx * atlasSize;
|
||||
mipy = dcdy * atlasSize;
|
||||
mipDelta = max(dot(mipx, mipx), dot(mipy, mipy));
|
||||
miplevel = max(0.25 * log2(mipDelta), 0.0);
|
||||
|
||||
normalMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalMap, 1.0 / exp2(miplevel)));
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
// if (blockEntityId < 60028) {
|
||||
// if (blockEntityId < 60012) {
|
||||
// if (blockEntityId < 60004) {
|
||||
// if (blockEntityId == 10548) { // Enchanting Table:Book
|
||||
// smoothnessG = pow2(color.g) * 0.35;
|
||||
|
||||
// if (color.b < 0.0001 && color.r > color.g) {
|
||||
// emission = color.g * 4.0;
|
||||
// }
|
||||
// } else if (blockEntityId == 60000) { //
|
||||
|
||||
// }
|
||||
// } else {
|
||||
// if (blockEntityId == 60004) { // Signs
|
||||
// noSmoothLighting = true;
|
||||
|
||||
// if (glColor.r + glColor.g + glColor.b <= 2.99 || lmCoord.x > 0.999) { // Sign Text
|
||||
// #include "/lib/materials/specificMaterials/others/signText.glsl"
|
||||
// }
|
||||
|
||||
// #ifdef COATED_TEXTURES
|
||||
// noiseFactor = 0.66;
|
||||
// #endif
|
||||
// } else /*if (blockEntityId == 60008)*/ { // Chest
|
||||
// noSmoothLighting = true;
|
||||
|
||||
// smoothnessG = pow2(color.g);
|
||||
|
||||
// #ifdef COATED_TEXTURES
|
||||
// noiseFactor = 0.66;
|
||||
// #endif
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (blockEntityId < 60020) {
|
||||
// if (blockEntityId == 60012) { // Ender Chest
|
||||
// noSmoothLighting = true;
|
||||
|
||||
// float factor = min(pow2(color.g), 0.25);
|
||||
// smoothnessG = factor * 2.0;
|
||||
|
||||
// if (color.g > color.r || color.b > color.g)
|
||||
// emission = pow2(factor) * 20.0;
|
||||
// emission += 0.35;
|
||||
|
||||
// #ifdef COATED_TEXTURES
|
||||
// noiseFactor = 0.66;
|
||||
// #endif
|
||||
// } else /*if (blockEntityId == 60016)*/ { // Shulker Box+, Banner+, Head+, Bed+
|
||||
// noSmoothLighting = true;
|
||||
// #ifdef COATED_TEXTURES
|
||||
// noiseFactor = 0.2;
|
||||
// #endif
|
||||
// }
|
||||
// } else {
|
||||
// if (blockEntityId == 60020) { // Conduit
|
||||
// noSmoothLighting = true;
|
||||
// lmCoordM.x = 0.9;
|
||||
|
||||
// if (color.b > color.r) { // Conduit:Wind, Conduit:Blue Pixels of The Eye
|
||||
// emission = color.r * 16.0;
|
||||
// } else if (color.r > color.b * 2.5) { // Conduit:Red Pixels of The Eye
|
||||
// emission = 20.0;
|
||||
// color.rgb *= vec3(1.0, 0.25, 0.1);
|
||||
// }
|
||||
// } else /*if (blockEntityId == 60024)*/ { // End Portal, End Gateway
|
||||
// #include "/lib/materials/specificMaterials/others/endPortalEffect.glsl"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (blockEntityId < 60044) {
|
||||
// if (blockEntityId < 60036) {
|
||||
// if (blockEntityId == 60028) { //
|
||||
|
||||
// } else /*if (blockEntityId == 60032)*/ { // Bell
|
||||
// if (color.r + color.g > color.b + 0.5) { // Bell:Golden Part
|
||||
// #include "/lib/materials/specificMaterials/terrain/goldBlock.glsl"
|
||||
// } else {
|
||||
// #include "/lib/materials/specificMaterials/terrain/stone.glsl"
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (blockEntityId == 60036) { //
|
||||
|
||||
// } else /*if (blockEntityId == 60040)*/ { //
|
||||
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (blockEntityId < 60052) {
|
||||
// if (blockEntityId == 60044) { //
|
||||
|
||||
// } else /*if (blockEntityId == 60048)*/ { //
|
||||
|
||||
// }
|
||||
// } else {
|
||||
// if (blockEntityId == 60052) { //
|
||||
|
||||
// } else if (blockEntityId == 60056) { //
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,76 @@
|
||||
vec4 ReadNormal(vec2 coord) {
|
||||
coord = fract(coord) * vTexCoordAM.pq + vTexCoordAM.st;
|
||||
return texture2DGradARB(normals, coord, dcdx, dcdy);
|
||||
}
|
||||
|
||||
vec2 GetParallaxCoord(vec2 texCoord, float parallaxFade, out float surfaceDepth) {
|
||||
vec2 coord = vTexCoord.st;
|
||||
surfaceDepth = 1.0;
|
||||
|
||||
if (viewVector != viewVector) {
|
||||
return texCoord;
|
||||
}
|
||||
|
||||
float sampleStep = 1.0 / PARALLAX_QUALITY;
|
||||
float currentStep = 1.0;
|
||||
|
||||
vec2 scaledDir = viewVector.xy * PARALLAX_DEPTH / -viewVector.z;
|
||||
vec2 stepDir = scaledDir * sampleStep * (1.0 - parallaxFade);
|
||||
|
||||
vec3 normalMap = ReadNormal(coord).xyz * 2.0 - 1.0;
|
||||
float normalCheck = normalMap.x + normalMap.y;
|
||||
if (parallaxFade >= 1.0 || normalCheck < -1.999) return texCoord;
|
||||
|
||||
float depth = ReadNormal(coord).a;
|
||||
|
||||
for(int i = 0; i < PARALLAX_QUALITY; i++){
|
||||
if (currentStep <= depth) break;
|
||||
coord += stepDir;
|
||||
depth = ReadNormal(coord).a;
|
||||
currentStep -= sampleStep;
|
||||
}
|
||||
|
||||
coord = fract(coord.st) * vTexCoordAM.pq + vTexCoordAM.st;
|
||||
surfaceDepth = currentStep;
|
||||
|
||||
return coord;
|
||||
}
|
||||
|
||||
float GetParallaxShadow(float surfaceDepth, float parallaxFade, vec2 coord, vec3 lightVec,
|
||||
mat3 tbn) {
|
||||
float parallaxshadow = 1.0;
|
||||
if(parallaxFade >= 1.0) return 1.0;
|
||||
|
||||
float height = surfaceDepth;
|
||||
if(height > 1.0 - 0.5 / PARALLAX_QUALITY) return 1.0;
|
||||
|
||||
vec3 parallaxdir = tbn * lightVec;
|
||||
parallaxdir.xy *= PARALLAX_DEPTH * SELF_SHADOW_ANGLE;
|
||||
vec2 newvTexCoord = (coord - vTexCoordAM.st) / vTexCoordAM.pq;
|
||||
float sampleStep = 0.32 / SELF_SHADOW_QUALITY;
|
||||
|
||||
vec2 ptexCoord = fract(newvTexCoord + parallaxdir.xy * sampleStep) *
|
||||
vTexCoordAM.pq + vTexCoordAM.st;
|
||||
|
||||
float texHeight = texture2DGradARB(normals, coord, dcdx, dcdy).a;
|
||||
float texHeightOffset = texture2DGradARB(normals, ptexCoord, dcdx, dcdy).a;
|
||||
|
||||
float texFactor = clamp((height - texHeightOffset) / sampleStep + 1.0, 0.0, 1.0);
|
||||
|
||||
height = mix(height, texHeight, texFactor);
|
||||
|
||||
for(int i = 0; i < SELF_SHADOW_QUALITY; i++) {
|
||||
float currentHeight = height + parallaxdir.z * sampleStep * i;
|
||||
vec2 parallaxCoord = fract(newvTexCoord + parallaxdir.xy * i * sampleStep) *
|
||||
vTexCoordAM.pq + vTexCoordAM.st;
|
||||
float offsetHeight = texture2DGradARB(normals, parallaxCoord, dcdx, dcdy).a;
|
||||
float sampleShadow = clamp(1.0 - (offsetHeight - currentHeight) * SELF_SHADOW_STRENGTH, 0.0, 1.0);
|
||||
parallaxshadow = min(parallaxshadow, sampleShadow);
|
||||
if (parallaxshadow < 0.01) break;
|
||||
}
|
||||
parallaxshadow *= parallaxshadow;
|
||||
|
||||
parallaxshadow = mix(parallaxshadow, 1.0, parallaxFade);
|
||||
|
||||
return parallaxshadow;
|
||||
}
|
||||
Reference in new issue
Block a user