Initial commit: Minecraft 光追着色器包(从零实现的 path tracing)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// MinecraftPT — Parallax Occlusion Mapping
|
||||
// Steep parallax mapping with PCF soft shadows.
|
||||
|
||||
#ifndef PARALLAX_GLSL
|
||||
#define PARALLAX_GLSL
|
||||
|
||||
// Steep parallax mapping
|
||||
vec2 ParallaxMapping(vec2 texcoord, vec3 viewDir){
|
||||
float height = texture(tex, texcoord).a;
|
||||
vec2 delta = viewDir.xy / viewDir.z * PARALLAX_DEPTH;
|
||||
|
||||
int numLayers = max(1, int(PARALLAX_QUALITY));
|
||||
float layerDepth = 1.0 / float(numLayers);
|
||||
float currentDepth = 0.0;
|
||||
vec2 currentCoord = texcoord;
|
||||
|
||||
for (int i = 0; i < numLayers; i++){
|
||||
currentCoord -= delta * layerDepth;
|
||||
height = texture(tex, currentCoord).a;
|
||||
currentDepth += layerDepth;
|
||||
if (height < currentDepth) break;
|
||||
}
|
||||
|
||||
// Parallax shadow
|
||||
float shadow = 1.0;
|
||||
#ifdef PARALLAX_SHADOW
|
||||
// PCF shadow
|
||||
for (int i = 0; i < PARALLAX_SHADOW_QUALITY; i++){
|
||||
vec2 shadowCoord = currentCoord + delta * float(i) / float(PARALLAX_SHADOW_QUALITY);
|
||||
shadow *= step(currentDepth - layerDepth * float(i) / float(PARALLAX_SHADOW_QUALITY), texture(tex, shadowCoord).a);
|
||||
}
|
||||
#endif
|
||||
|
||||
return currentCoord;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user