Skip to content

Instantly share code, notes, and snippets.

@michaliskambi
Created October 5, 2023 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaliskambi/2e36aa749f7d3ec7bd86c374d6bb23f3 to your computer and use it in GitHub Desktop.
Save michaliskambi/2e36aa749f7d3ec7bd86c374d6bb23f3 to your computer and use it in GitHub Desktop.
Shader adding a mask over another texture, modifed Kagamma example
#X3D V4.0 utf8
PROFILE Interchange
Shape {
appearance Appearance {
material UnlitMaterial {
}
texture ImageTexture {
url "texture.png"
textureProperties TextureProperties {
magnificationFilter "NEAREST_PIXEL"
minificationFilter "NEAREST_PIXEL"
}
}
effects Effect {
language "GLSL"
initializeOnly SFNode mask_texture ImageTexture {
url "mask.png"
textureProperties TextureProperties {
magnificationFilter "NEAREST_PIXEL"
minificationFilter "NEAREST_PIXEL"
}
}
parts EffectPart {
type "FRAGMENT"
url "data:text/plain,
uniform sampler2D mask_texture;
void PLUG_texture_color(inout vec4 texture_color, const in sampler2D texture_in, const in vec4 tex_coord) {
float alpha = texture2D(mask_texture, tex_coord.st).r; // r=g=b so pick one...
texture_color = vec4(texture_color.xyz, alpha);
}"
}
}
}
geometry IndexedFaceSet {
solid FALSE
coord Coordinate { point [ -0.5 -0.5 0, 0.5 -0.5 0, 0.5 0.5 0, -0.5 0.5 0 ] }
texCoord TextureCoordinate { point [ 0 0, 1 0, 1 1, 0 1 ] }
coordIndex [ 0 1 2 3 ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment