You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

glsl-parallax-occlusion-mapping

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glsl-parallax-occlusion-mapping

glslify module implementing parallax occlusion mapping.

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
6
500%
Maintainers
1
Weekly downloads
 
Created
Source

glsl-parallax-occlusion-mapping

glslify module implementing parallax occlusion mapping.

Installation

glslify is required for importing.

yarn add glsl-parallax-occlusion-mapping
npm i glsl-parallax-occlusion-mapping --save

Usage

When requiring, you must specify the number of layers to use.

#pragma glslify: pom = require('glsl-parallax-occlusion-mapping', layers=8)
vec2 pom( sampler2D depthMap, vec2 uv, vec2 displacement, float pivot )

The function accepts 4 arguments:

  • depthMap is your depth/displacement map. Only the red channel is used.
  • uv are your regular texture coordinates for depthMap.
  • displacement is the direction in which to shift the texture. Usually this is the xy component of your view direction multiplied by a depth scalar.
  • pivot (optional) describes the elevation from which to pivot the displacement (where 0.0 is the highest and 1.0 is the lowest elevation). Defaults to 0.0.

It returns the new texture coordinates.

Example

#pragma glslify: pom = require('glsl-parallax-occlusion-mapping', layers=8)

uniform sampler2D tDiffuse;
uniform sampler2D tDepth;

varying vec2 vUv;

void main() {
  vec2 newUv = pom( tDepth, vUv, viewDirection.xy * .1 );
  
  gl_FragColor = texture2D( tDiffuse, newUv );
}	

Credits

This implementation is based on this great article.

Keywords

glsl

FAQs

Package last updated on 09 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts