https://github.com/riccardobl/jme-shader-occlusionparallaxmapping
OcclusionParallaxMapping for jMonkeyEngine
https://github.com/riccardobl/jme-shader-occlusionparallaxmapping
glsl jmonkeyengine occlusion parallax shader
Last synced: about 2 months ago
JSON representation
OcclusionParallaxMapping for jMonkeyEngine
- Host: GitHub
- URL: https://github.com/riccardobl/jme-shader-occlusionparallaxmapping
- Owner: riccardobl
- License: unlicense
- Created: 2019-09-09T10:12:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-09T13:27:44.000Z (over 5 years ago)
- Last Synced: 2024-10-06T05:21:15.716Z (8 months ago)
- Topics: glsl, jmonkeyengine, occlusion, parallax, shader
- Language: GLSL
- Homepage: https://jmonkeystore.com/571e75d2-d9c6-4f3f-8b99-3c717bbf42bd
- Size: 16.6 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OcclusionParallaxMapping for jMonkeyEngine
Usage.
```glsl
//Fragment shader
// Define which channel of the texture is used to store height data (rgba)
#define HEIGHT_MAP R_COMPONENT
// #define HEIGHT_MAP G_COMPONENT
// #define HEIGHT_MAP B_COMPONENT
// #define HEIGHT_MAP A_COMPONENT
// If the texture contains DEPTH, define the channel using DEPTH_MAP instead of HEIGHT_MAP// Override texture sampling function
// #define Texture_sample myTextureSample// Import OcclusionParallax
#import "Shaders/OcclusionParallax.glsllib"uniform vec3 g_CameraPosition; // camera position in world space
uniform sampler2D m_ParallaxMap; // gray scale height/depth mapin vec3 WPos; // fragment position in world space
in vec3 WNorm; // fragment normal in world space
in vec3 WTang; // fragment tangent in world space
in vec2 TexCoord;out vec4 outFragColor;
//....
void main(){
//...
mat3 tbnMat = mat3(WTang.xyz, WTang.w * cross(wNorm, WTang.xyz), wNorm);
vec3 viewDir = normalize(g_CameraPosition - WPos);
vec3 vViewDir = viewDir * tbnMat;float m_ParallaxHeight=0.3;
Parallax_initFor(vViewDir,m_ParallaxHeight);
//...
vec2 newTexCoord=TexCoord; // Coordinates to be displaced by the parallax
Parallax_displaceCoords(newTexCoord,m_ParallaxMap);//...
// Displace other coordinates, no need to call Parallax_initFor again.
// vec2 newTexCoord2=TexCoord2; // Coordinates to be displaced by the parallax
// Parallax_displaceCoords(newTexCoord2,m_ParallaxMap);
//...outFragColor=texture(m_DiffuseMap,newTexCoord);
}
```Example implementation in PBRLighting
https://github.com/riccardobl/jme-shader-OcclusionParallaxMapping/tree/master/Materials/OcclusionParallax