Last updated on
Jul 13, 2023
- Substance 3D home
- Home
- Getting Started
- Getting Started overview
- Activation and licenses
- System requirements
- Project creation
- Export
- Export overview
- Export window
- Export presets
- Export overview
- Glossary
- Performance
- Getting Started overview
- Interface
- Assets
- Substance 3D Assets
- Color picker
- Display settings
- History
- Layer stack
- Main menu
- Project configuration
- Properties
- Settings
- Shader settings
- Texture Set
- Toolbars
- Viewport
- Miscellaneous
- Assets
- Painting
- Painting overview
- Tool list
- Straight line
- Lazy mouse
- Symmetry
- Fill projections
- Presets
- Presets overview
- Creating and saving presets
- Creating particles presets
- Photoshop brush presets (ABR)
- Dynamic strokes
- Advanced channel painting
- Vector graphic (.svg & .ai)
- Text resource
- Effects
- Baking
- Content
- Creating custom effects
- Importing assets
- Creating custom effects
- Features
- Automatic UV Unwrapping
- Physical size
- Smart Materials and Masks
- Subsurface Scattering
- Dynamic Material Layering
- UV Reprojection
- UV Tiles
- Color Management
- Post Processing
- Iray Renderer
- Plugins
- Sparse Virtual Textures
- Custom Shaders
- SpaceMouse® by 3Dconnexion
- Universal Scene Description (USD)
- Send to
- Technical Support
- Performance Guidelines
- Configuring Pens and Tablets
- Exporting the log file
- Exporting a DXDiag
- Technical issues
- GPU Issues
- Crash when working with overclocked GPU
- Forcing the external GPU on Mac OS
- GPU drivers compatibility
- GPU drivers crash with long computations (TDR crash)
- GPU has outdated drivers
- GPU is not recognized
- GPU is not recognized and is mentionned as GDI Generic
- Issues with Nvidia GPUs on recent Mac OS versions
- Multi/Bi-GPU
- Running on integrated GPU
- Painter doesn't start on the right GPU
- Startup Issues
- Rendering Issues
- Stability Issues
- Miscellaneous Issues
- GPU Issues
- Workflow Issues
- Export Issues
- Tools Issues
- Project Issues
- Library Issues
- Viewport Issues
- Plugins Issues
- License Issues
- Pipeline and integration
- Installation and preferences
- Configuration
- Resource management
- Scripting and development
- Scripts and plugins
- Shader API Reference
- Shader API overview
- Changelog - Shader API
- Libraries - Shader API
- Lib Alpha - Shader API
- Lib Bayer - Shader API
- Lib Defines - Shader API
- Lib Emissive - Shader API
- Lib Env - Shader API
- Lib Normal - Shader API
- Lib PBR - Shader API
- Lib PBR Aniso - Shader API
- Lib Pom - Shader API
- Lib Random - Shader API
- Lib Sampler - Shader API
- Lib Sparse - Shader API
- Lib SSS - Shader API
- Lib Utils - Shader API
- Lib Vectors - Shader API
- Parameters - Shader API
- Shaders - Shader API
- Release notes
- Release notes overview
- All Changes
- Version 10.1
- Version 10.0
- Version 9.1
- Old versions
- Version 9.0
- Version 8.3
- Version 8.2
- Version 8.1
- Version 7.4
- Version 7.3
- Version 7.2
- Version 2021.1 (7.1.0)
- Version 2020.2 (6.2.0)
- Version 2020.1 (6.1.0)
- Version 2019.3
- Version 2019.2
- Version 2019.1
- Version 2018.3
- Version 2018.2
- Version 2018.1
- Version 2017.4
- Version 2017.3
- Version 2017.2
- Version 2017.1
- Version 2.6
- Version 2.5
- Version 2.4
- Version 2.3
- Version 2.2
Lib Pom - Shader API
lib-pom.glsl
Public Functions: getParallaxOffset applyParallaxOffset
Import from library
import lib-sampler.glsl
Parallax occlusion mapping related uniforms
//: param auto is_2d_view uniform bool isTextureView; //: param auto channel_displacement uniform SamplerSparse displacement_tex; //: param custom { "label": "Enable", "default": false, "group": "Parallax Occlusion Mapping" } uniform bool usePOM; //: param custom { "label": "Strength", "default": 1.0, "min": 0.01, "max": 10.0, "group": "Parallax Occlusion Mapping" } uniform float pomStrength; //: param custom { "label": "Minimum samples", "default": 4, "min": 1, "max": 64, "group": "Parallax Occlusion Mapping" } uniform int minPOMSamples; //: param custom { "label": "Maximum samples", "default": 16, "min": 1, "max": 64, "group": "Parallax Occlusion Mapping" } uniform int maxPOMSamples;
Compute the offset of texture coordinates based on parallax
vec2 getParallaxOffset(SparseCoord coord, vec3 viewTS) { if (!usePOM || isTextureView || !displacement_tex.is_set) return vec2(0.0); vec2 dfdx,dfdy; textureSparseQueryGrad(dfdx, dfdy, displacement_tex, coord); // Convention: 1.0 is top, -1.0 is bottom - POM is always inward, no extrusion int nbSteps = int(mix(maxPOMSamples, minPOMSamples, viewTS.z)); float amplitude = 4.0 * pomStrength / (HEIGHT_FACTOR * abs(viewTS.z) * nbSteps); vec3 rayStep = vec3(-amplitude * viewTS.xy, -2.0 / nbSteps); // Raymarch until we cross the surface vec3 rayPos = vec3(coord.tex_coord, 1.0); float prevHeight; float currHeight = getDisplacement(textureGrad(displacement_tex.tex, rayPos.xy, dfdx, dfdy)); int i = 0; do { rayPos += rayStep; prevHeight = currHeight; currHeight = getDisplacement(textureGrad(displacement_tex.tex, rayPos.xy, dfdx, dfdy)); i++; } while (i < nbSteps && currHeight < rayPos.z); // Binary search with linear interpolation to refine intersection vec3 prevRayPos = rayPos - rayStep; vec3 newRayPos = prevRayPos; float newHeight = prevHeight; i = 0; while (i < 3 && abs(newHeight - newRayPos.z) > 1e-3) { float prevDelta = prevRayPos.z - prevHeight; float delta = currHeight - rayPos.z; newRayPos = (prevDelta * rayPos + delta * prevRayPos) / (prevDelta + delta); newHeight = getDisplacement(textureGrad(displacement_tex.tex, newRayPos.xy, dfdx, dfdy)); if (newHeight > newRayPos.z) { currHeight = newHeight; rayPos = newRayPos; } else { prevHeight = newHeight; prevRayPos = newRayPos; } i++; } return newRayPos.xy - coord.tex_coord; }
Update input texture coordinates with parallax offset
void applyParallaxOffset(inout V2F inputs, vec3 viewTS) { vec2 offset = getParallaxOffset(inputs.sparse_coord, viewTS); if (any(notEqual(offset,vec2(0.0)))) { inputs.tex_coord += offset; inputs.sparse_coord = getSparseCoord(inputs.tex_coord); } }