I am making a 3d drawing program where I want to be able to "stamp" a small image on to a geometry. I don't know how to do this yet but I have outlined the problem and I have solved a few sub-problems. I could use some help filling in the holes. As I see it, the steps are:
- [done] use ray-trace picking to determine the object and the world position
- [done] add a new layer to that object's texture [done]
- [done] neither "multiply" nor "add" work here as a blend method. I need the alpha of the "stamp" to control how it's blended in with the base color and previous image texture layers. Locally I have added a new blend method to scenejs.js, "alpha". My patch is probably too simplistic but it works AFAIK. (Patch at end of post).
- current wrapS/T methods don't work for me either. I want a single copy of the stamp image. I am looking in to this now.
- how to convert picked object and world position to a texture layer offset? No idea.
Any help with the last two points and/or suggestions on how to achieve my custom blend mode with a custom shader would be appreciated. (Or, if an "alpha" blend mode makes general sense, maybe this should be added to scenejs? I don't care what you call it)
--------------------------------
"Alpha" blend method patch:
index 0210c21..baf0b77 100644
--- a/lib/scenejs.js
+++ b/lib/scenejs.js
@@ -9575,6 +9575,10 @@ var SceneJS_DrawList = new (function() {
if (layer.applyTo == "baseColor") {
if (layer.blendMode == "multiply") {
src.push("color = color * (SCENEJS_uLayer" + i + "BlendFactor * texture2D(SCENEJS_uSampler" + i + ", vec
+ } else if (layer.blendMode == "alpha") {
+ src.push("vec3 tColor = texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y))
+ src.push("float tAlpha = texture2D(SCENEJS_uSampler" + i + ", vec2(textureCoord.x, 1.0 - textureCoord.y)
+ src.push("color = ((1.0 - tAlpha) * color) + (tAlpha * tColor);");
} else {
src.push("color = ((1.0 - SCENEJS_uLayer" + i + "BlendFactor) * color) + (SCENEJS_uLayer" + i + "BlendFa
}
@@ -22837,7 +22841,7 @@ var SceneJS_textureModule = new (function() {
}
}
if (layerParam.blendMode) {
- if (layerParam.blendMode != "add" && layerParam.blendMode != "multiply") {
+ if (layerParam.blendMode != "add" && layerParam.blendMode != "multiply" && layerParam.blendMode != "alpha")
throw SceneJS_errorModule.fatalError(
SceneJS.errors.NODE_CONFIG_EXPECTED,
"texture layer " + i + " blendMode value is unsupported - " +