I have two DensityPlot3D objects where the opacity and coloring are both physically meaningful, and I'm looking for a way to overlap them so that the resulting opacity/color is visually combined in an intuitive way. Thus, I'm pretty sure that combining them into one DensityPlot3D is not an option.
For example, consider the eigenmodes in the following situation:
reg = DiscretizeRegion[
ImplicitRegion[-1 <= x <= 1 && -1 <= y <= 1 && -1 <= z <= 1, {x, y, z}]]
{vals, funcs} =
NDEigensystem[
{Laplacian[u[x, y, z], {x, y, z}], DirichletCondition[u[x, y, z] == 0, True]},
u, {x, y, z} ∈ reg, 4]
g1 = DensityPlot3D[funcs[[2]][x, y, z], {x, y, z} ∈ reg,
ColorFunction -> "SunsetColors", Boxed -> False, Axes -> False, ViewPoint -> {3, 2, 3}];
g2 = DensityPlot3D[funcs[[3]][x, y, z], {x, y, z} ∈ reg,
ColorFunction -> "RoseColors", Boxed -> False, Axes -> False, ViewPoint -> {3, 2, 3}];
What I want is to be able to combine these two graphics in such a way that in the regions where the densities overlap the combined color/opacity is somehow the sum or product or some other meaningful combination of the individual densities, but maintaining the different color schemes for the two modes (ie, not one unified DensityPlot3D with a common color function and opacity scaling).
I could see calculating an effective color and opacity value at discrete points in the region, but there does not seem to be a way to define a color function or opacity function that depend on position as well as "value".
EDIT: Things that don't work:
DensityPlot3D[funcs[[2]][x, y, z], {x, y, z} ∈ reg, ColorFunction -> Function[{x, y, z, f}, <anything>]]
(fails because ColorFunction doesn't work that way for DensityPlot3D)
DensityPlot3D[{funcs[[2]][x, y, z],funcs[[3]][x, y, z]}, {x, y, z} ∈ reg]
(displays nothing)
Show[g1, g2]
(only shows g1, because it rasterizes first)
Blend[{g1,g2}]
(rasterizes and then applies the same opacity at every pixel)
g1
andg2
appear identical to me in your code. Did you mean to select a different part offuncs
for one of them? Also, since your region is a simple axis-aligned cube, is it faster to usereg = Cuboid[{-1, -1, -1}, {1, 1, 1}]
? $\endgroup$ColorFunction
using both position and density values?ColorFunction -> Function[{x, y, z, f}, yourfunc[x,y,z,f]]
$\endgroup$Image3D
directly instead of usingDensityPlot3D
. Then I could produce RGB+alpha quadruplets manually and control how the colour is created. I would no longer need to compute the colour based on a single value: I could compute it based on two values (which is what you are asking). $\endgroup$