Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to allow the multiple declarations of the same style in a volume... #369

Merged
merged 1 commit into from Jun 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 32 additions & 34 deletions src/nodes/VolumeRendering/BlendedVolumeStyle.js
Expand Up @@ -141,32 +141,22 @@ x3dom.registerNodeType(
uniforms: function(){
var unis = [];
if (this._cf.voxels.node || this._cf.weightTransferFunction1.node || this._cf.weightTransferFunction2.node) {
//Lookup for the parent VolumeData
var volumeDataParent = this._parentNodes[0];
while(!x3dom.isa(volumeDataParent, x3dom.nodeTypes.X3DVolumeDataNode) || !x3dom.isa(volumeDataParent, x3dom.nodeTypes.X3DNode)){
volumeDataParent = volumeDataParent._parentNodes[0];
}
if(x3dom.isa(volumeDataParent, x3dom.nodeTypes.X3DVolumeDataNode) == false){
x3dom.debug.logError("[VolumeRendering][BlendVolumeStyle] Not VolumeData parent found!");
volumeDataParent = null;
}

this.uniformSampler2DVoxels._vf.name = 'uVolBlendData';
this.uniformSampler2DVoxels._vf.type = 'SFInt32';
this.uniformSampler2DVoxels._vf.value = volumeDataParent._textureID++;
this.uniformSampler2DVoxels._vf.value = this._volumeDataParent._textureID++;
unis.push(this.uniformSampler2DVoxels);

if(this._cf.weightTransferFunction1.node){
this.uniformSampler2DWeightTransferFunction1._vf.name = 'uWeightTransferFunctionA';
this.uniformSampler2DWeightTransferFunction1._vf.type = 'SFInt32';
this.uniformSampler2DWeightTransferFunction1._vf.value = volumeDataParent._textureID++;
this.uniformSampler2DWeightTransferFunction1._vf.value = this._volumeDataParent._textureID++;
unis.push(this.uniformSampler2DWeightTransferFunction1);
}

if(this._cf.weightTransferFunction2.node){
this.uniformSampler2DWeightTransferFunction2._vf.name = 'uWeightTransferFunctionB';
this.uniformSampler2DWeightTransferFunction2._vf.type = 'SFInt32';
this.uniformSampler2DWeightTransferFunction2._vf.value = volumeDataParent._textureID++;
this.uniformSampler2DWeightTransferFunction2._vf.value = this._volumeDataParent._textureID++;
unis.push(this.uniformSampler2DWeightTransferFunction2);
}
}
Expand Down Expand Up @@ -269,22 +259,7 @@ x3dom.registerNodeType(
}else{
inlineText += " vec4 blendGradEye = getNormalOnTheFly(uVolBlendData, ray_pos, "+ nSlices +", "+ xSlices +", "+ ySlices +");\n";
}
if (x3dom.nodeTypes.X3DLightNode.lightID>0){
inlineText += " vec4 blendGrad = vec4((modelViewMatrixInverse * vec4(blendGradEye.xyz, 0.0)).xyz, blendGradEye.a);\n";
}
for(var l=0; l<x3dom.nodeTypes.X3DLightNode.lightID; l++) {
inlineText += " lighting(light"+l+"_Type, " +
"light"+l+"_Location, " +
"light"+l+"_Direction, " +
"light"+l+"_Color, " +
"light"+l+"_Attenuation, " +
"light"+l+"_Radius, " +
"light"+l+"_Intensity, " +
"light"+l+"_AmbientIntensity, " +
"light"+l+"_BeamWidth, " +
"light"+l+"_CutOffAngle, " +
"blendGradEye.xyz, -positionE.xyz, ambientBlend, diffuseBlend, specularBlend);\n";
}
inlineText += " vec4 blendGrad = vec4((modelViewMatrixInverse * vec4(blendGradEye.xyz, 0.0)).xyz, blendGradEye.a);\n";
if(this._cf.renderStyle.node){
var tempText = this._cf.renderStyle.node.inlineStyleShaderText().replace(/value/gm, "blendValue").replace(/grad/gm, "blendGrad");
inlineText += tempText.replace(/ambient/gm, "ambientBlend").replace(/diffuse/gm, "diffuseBlend").replace(/specular/gm, "specularBlend");
Expand Down Expand Up @@ -341,16 +316,39 @@ x3dom.registerNodeType(
}
break;
}
if(x3dom.nodeTypes.X3DLightNode.lightID>0){
inlineText += " value.rgb = ambient*value.rgb + diffuse*value.rgb + specular;\n";
if(x3dom.nodeTypes.X3DLightNode.lightID == 0){
inlineText += " value.rgb = clamp(value.rgb * wA + blendValue.rgb * wB, 0.0, 1.0);\n"+
" value.a = clamp(value.a * wA + blendValue.a * wB, 0.0, 1.0);\n";
}
inlineText += " value.rgb = clamp(value.rgb * wA + blendValue.rgb * wB, 0.0, 1.0);\n"+
" value.a = clamp(value.a * wA + blendValue.a * wB, 0.0, 1.0);\n";
return inlineText;
},

lightAssigment: function(){
return ""; //previously computed, empty string
var inlineText = "";
if(x3dom.nodeTypes.X3DLightNode.lightID>0){
if(this._cf.renderStyle.node){
var tempText = this._cf.renderStyle.node.lightAssigment().replace(/value/gm, "blendValue").replace(/grad/gm, "blendGrad");
inlineText += tempText.replace(/ambient/gm, "ambientBlend").replace(/diffuse/gm, "diffuseBlend").replace(/specular/gm, "specularBlend");
}else{
for(var l=0; l<x3dom.nodeTypes.X3DLightNode.lightID; l++) {
inlineText += " lighting(light"+l+"_Type, " +
"light"+l+"_Location, " +
"light"+l+"_Direction, " +
"light"+l+"_Color, " +
"light"+l+"_Attenuation, " +
"light"+l+"_Radius, " +
"light"+l+"_Intensity, " +
"light"+l+"_AmbientIntensity, " +
"light"+l+"_BeamWidth, " +
"light"+l+"_CutOffAngle, " +
"blendGradEye.xyz, -positionE.xyz, ambientBlend, diffuseBlend, specularBlend);\n";
}
inlineText += " blendValue.rgb = ambientBlend*blendValue.rgb + diffuseBlend*blendValue.rgb + specularBlend;\n";
}
}
inlineText += " value.rgb = clamp(value.rgb * wA + blendValue.rgb * wB, 0.0, 1.0);\n"+
" value.a = clamp(value.a * wA + blendValue.a * wB, 0.0, 1.0);\n";
return inlineText; //previously computed, empty string
}
}
)
Expand Down
30 changes: 17 additions & 13 deletions src/nodes/VolumeRendering/BoundaryEnhancementVolumeStyle.js
Expand Up @@ -104,22 +104,22 @@ x3dom.registerNodeType(
unis.push(this.uniformSampler2DSurfaceNormals);
}

this.uniformFloatRetainedOpacity._vf.name = 'uRetainedOpacity';
this.uniformFloatRetainedOpacity._vf.name = 'uRetainedOpacity'+this._styleID;
this.uniformFloatRetainedOpacity._vf.type = 'SFFloat';
this.uniformFloatRetainedOpacity._vf.value = this._vf.retainedOpacity;
unis.push(this.uniformFloatRetainedOpacity);

this.uniformFloatBoundaryOpacity._vf.name = 'uBoundaryOpacity';
this.uniformFloatBoundaryOpacity._vf.name = 'uBoundaryOpacity'+this._styleID;
this.uniformFloatBoundaryOpacity._vf.type = 'SFFloat';
this.uniformFloatBoundaryOpacity._vf.value = this._vf.boundaryOpacity;
unis.push(this.uniformFloatBoundaryOpacity);

this.uniformFloatOpacityFactor._vf.name = 'uOpacityFactor';
this.uniformFloatOpacityFactor._vf.name = 'uOpacityFactor'+this._styleID;
this.uniformFloatOpacityFactor._vf.type = 'SFFloat';
this.uniformFloatOpacityFactor._vf.value = this._vf.opacityFactor;
unis.push(this.uniformFloatOpacityFactor);

this.uniformBoolEnableBoundary._vf.name = 'uEnableBoundary';
this.uniformBoolEnableBoundary._vf.name = 'uEnableBoundary'+this._styleID;
this.uniformBoolEnableBoundary._vf.type = 'SFBool';
this.uniformBoolEnableBoundary._vf.value = this._vf.enabled;
unis.push(this.uniformBoolEnableBoundary);
Expand All @@ -138,21 +138,25 @@ x3dom.registerNodeType(
},

styleUniformsShaderText: function(){
return "uniform float uRetainedOpacity;\n"+
"uniform float uBoundaryOpacity;\n"+
"uniform float uOpacityFactor;\n"+
"uniform bool uEnableBoundary;\n";
return "uniform float uRetainedOpacity"+this._styleID+";\n"+
"uniform float uBoundaryOpacity"+this._styleID+";\n"+
"uniform float uOpacityFactor"+this._styleID+";\n"+
"uniform bool uEnableBoundary"+this._styleID+";\n";
},

styleShaderText: function(){
return "void boundaryEnhancement(inout vec4 original_color, float gradientMagnitude){\n"+
" original_color.a = original_color.a * (uRetainedOpacity + (uBoundaryOpacity*pow(gradientMagnitude, uOpacityFactor)));\n"+
"}\n";
if (this._first){
return "void boundaryEnhancement(inout vec4 original_color, in float gradientMagnitude, in float retainedOpacity, in float boundaryOpacity, in float opacityFactor){\n"+
" original_color.a = original_color.a * (retainedOpacity + (boundaryOpacity * pow(gradientMagnitude, opacityFactor)));\n"+
"}\n";
}else{
return "";
}
},

inlineStyleShaderText: function(){
var inlineText = " if(uEnableBoundary){\n"+
" boundaryEnhancement(value, grad.w);\n"+
var inlineText = " if(uEnableBoundary"+this._styleID+"){\n"+
" boundaryEnhancement(value, grad.w, uRetainedOpacity"+this._styleID+", uBoundaryOpacity"+this._styleID+", uOpacityFactor"+this._styleID+");\n"+
"}\n";
return inlineText;
}
Expand Down