![]() ![]() If the z-component of lightDir is grater than 0.0, the the surface is lit from the back. Note, that the depth is decremented ( currentLayerDepth -= layerDepth) and the texture samples are taken in the opposite direction ( currentTexCoords += deltaTexCoords) in compare the the ParallaxMapping algorithm: while (currentLayerDepth 0.0)ĬurrentDepthMapValue = texture(heightMap, currentTexCoords).r įloat r = currentLayerDepth > currentDepthMapValue ? 0.0 : 1.0 īecause of the division by the z-component in ( P = lightDir.xy / lightDir.z), P and thus deltaTexCoords, points always to the light source (of course in the projection to the texture). The sampling has to be aborted if the maximum depth (minimum value of 0.0) is reached. Since the depth mao is an inverse depth map (1.0 is low), a fragment is in shadow if any layer depth ( currentLayerDepth) is less or equal the current height ( currentDepthMapValue). The initial height ( currentLayerDepth) is the height of the current fragment: float currentDepthMapValue = texture(heightMap, currentTexCoords).r įloat currentLayerDepth = currentDepthMapValue float shadow = dc > 0.0 ? ShadowCalc(currentTex, lightDir) : 0.0 To check if a fragment is in self-shadow, you have to track the ray to the light source from starting a the the "parallax" texel. Shadow = ShadowCalc(currentTex, lightDir) įragColor = shadow * dc * texture(diffuseMap, currentTex) įirst of all the direction of the light source to the fragment in texture space is: vec3 lightDir = TBN_norm * normalize(o_worldPos - light_pos) įloat dc = max(0.0, dot(-lightDir, normal)) If (currentTex.x > 1.0 || currentTex.y > 1.0 || currentTex.x 0) Vec2 currentTex = ParallaxMapping(o_texCoord, viewDir) Vec3 viewDir = TBN_norm * normalize(o_worldPos - viewPosition) Normalize(cross(world_normal, world_tangent)), Mat3 TBN_norm = transpose(mat3(normalize(world_tangent), While (currentLayerDepth currentLayerDepth ? 0.0 : 1.0 Vec2 P = viewDir.xy / viewDir.z * heightScale įloat currentDepthMapValue = texture(heightMap, currentTexCoords).r Vec2 ParallaxMapping (vec2 texCoord, vec3 viewDir)įloat numLayers = mix(maxLayers, minLayers, abs(dot(vec3(0.0, 0.0, 1.0), viewDir))) ![]() I've marked that parts I added to the original parallax tutorial code. Nothing changed from when it was just the parallax occlusion map. This is the result of the modified fragment shader. I tried modifying the fragment shader, but the shadows still don't show up. From what I understand, it's the same process as parallax occlusion mapping, but from the light's direction instead of the view direction. I've read a few papers on the topic, but I admit it's a bit advanced for me. I've implemented Parallax Occlusion Mapping through LearnOpengl, and now I want to add self-shadows so that the fragment extrusions throw shadows on the surface.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |