use of maspack.render.Renderer.ColorInterpolation in project artisynth_core by artisynth.
the class MeshBase method setColorInterpolation.
/**
* Sets the interpolation method to be used for vertex-based coloring.
*
* @param interp new color interpolation method
* @return previous color interpolation method
*/
public ColorInterpolation setColorInterpolation(ColorInterpolation interp) {
ColorInterpolation prev = myColorInterp;
myColorInterp = interp;
return prev;
}
use of maspack.render.Renderer.ColorInterpolation in project artisynth_core by artisynth.
the class GLSLGenerator method buildVertexShaderMain.
private static void buildVertexShaderMain(StringBuilder mb, GLProgramInfo info) {
appendln(mb, "// main vertex shader");
appendln(mb, "void main() {");
appendln(mb);
appendln(mb, " vec3 position; // transformed vertex position");
if (info.hasVertexNormals() && info.getShading() != Shading.NONE) {
appendln(mb, " vec3 normal; // transformed vertex normal");
}
appendln(mb);
RenderingMode mode = info.getMode();
boolean computeNormals = !info.isSelecting() && info.hasVertexNormals() && info.getShading() != Shading.NONE;
// transform vertex using instance info
switch(mode) {
case INSTANCED_AFFINES:
appendln(mb, " // instance vertex, affine transform");
appendln(mb, " position = (instance_affine_matrix * vec4(instance_scale * vertex_position, 1.0) ).xyz;");
if (computeNormals) {
appendln(mb, " normal = (instance_normal_matrix * vec4(vertex_normal, 0.0) ).xyz;");
}
appendln(mb);
break;
case INSTANCED_FRAMES:
appendln(mb, " // instance vertex, scale-rotate-translate");
appendln(mb, " position = qrot(instance_orientation, (instance_scale * vertex_position)) + instance_position;");
if (computeNormals) {
appendln(mb, " normal = qrot(instance_orientation, vertex_normal);");
}
appendln(mb);
break;
case INSTANCED_LINES:
appendln(mb, " // instance vertex, scale radially, rotate/translate");
appendln(mb, " vec3 u = line_top_position-line_bottom_position;");
appendln(mb, " float line_length = length(u); // target length");
appendln(mb, " u = u/line_length; // target direction vector");
if (info.hasLineScaleOffset()) {
appendln(mb, " float line_rad = line_radius*mix(line_bottom_scale_offset.r, line_top_scale_offset.r, vertex_position.z); // adjust radius");
appendln(mb, " float line_offset = mix(line_bottom_scale_offset.y, line_length+line_bottom_scale_offset.z, line_bottom_scale_offset.w);");
appendln(mb, " float line_top = mix(line_top_scale_offset.y, line_length+line_top_scale_offset.z, line_top_scale_offset.w);");
appendln(mb, " line_length = line_top-line_offset;");
} else {
appendln(mb, " float line_rad = line_radius; // radius length");
}
appendln(mb);
appendln(mb, " // transform position");
appendln(mb, " position = vec3(line_rad*vertex_position.xy, line_length*vertex_position.z);");
appendln(mb, " position = line_bottom_position + zrot(u, position);");
if (info.hasLineScaleOffset()) {
appendln(mb, " position = position + line_offset*u;");
}
if (computeNormals) {
appendln(mb, " // transform normal");
appendln(mb, " normal = vec3( vertex_normal.xy*line_length, vertex_normal.z*line_radius);");
appendln(mb, " normal = zrot(u, normal);");
if (info.hasLineScaleOffset()) {
appendln(mb, " float rdiff = line_bottom_scale_offset.r-line_top_scale_offset.r;");
appendln(mb, " float cost = 1.0/sqrt(rdiff*rdiff+1);");
appendln(mb, " float sint = rdiff*cost;");
appendln(mb, " vec3 trot = vec3(vertex_position.y, -vertex_position.x, 0);");
appendln(mb, " normal = rodrigues(normal, trot, sint, cost);");
}
}
appendln(mb);
break;
case INSTANCED_POINTS:
appendln(mb, " // instance vertex, scale-translate");
appendln(mb, " position = instance_scale * vertex_position + instance_position;");
if (!info.isSelecting() && info.hasVertexNormals() && info.getShading() != Shading.NONE) {
appendln(mb, " normal = vertex_normal;");
}
break;
case DEFAULT:
case POINTS:
appendln(mb, " position = vertex_position;");
if (computeNormals) {
appendln(mb, " normal = vertex_normal;");
}
break;
}
// at this point, position and normal should be correct, compute output position
appendln(mb, " // vertex output");
appendln(mb, " gl_Position = pvm_matrix * vec4(position, 1.0);");
appendln(mb);
// vertex colors
ColorInterpolation cinterp = info.getColorInterpolation();
if (!info.isSelecting() && info.getVertexColorMixing() != ColorMixing.NONE) {
switch(mode) {
case INSTANCED_POINTS:
case INSTANCED_FRAMES:
case INSTANCED_AFFINES:
if (info.hasInstanceColors()) {
if (cinterp == ColorInterpolation.HSV) {
appendln(mb, " colorOut.diffuse = rgba2hsva(instance_color);");
} else {
appendln(mb, " colorOut.diffuse = instance_color;");
}
appendln(mb);
} else if (info.hasVertexColors()) {
if (cinterp == ColorInterpolation.HSV) {
appendln(mb, " colorOut.diffuse = rgba2hsva(vertex_color);");
} else {
appendln(mb, " colorOut.diffuse = vertex_color;");
}
appendln(mb);
}
break;
case INSTANCED_LINES:
if (info.hasLineColors()) {
appendln(mb, " // interpolate color based on line");
appendln(mb, " float cz = vertex_position.z;");
if (info.hasLineScaleOffset()) {
appendln(mb, " // interpolate as fraction of bottom-to-top");
appendln(mb, " cz = (cz*line_length+line_offset)/(line_length+line_offset);");
}
if (cinterp == ColorInterpolation.HSV) {
appendln(mb, " colorOut.diffuse = mix(rgba2hsva(line_bottom_color), rgba2hsva(line_top_color), cz);");
} else {
appendln(mb, " colorOut.diffuse = mix(line_bottom_color, line_top_color, cz);");
}
appendln(mb);
} else if (info.hasVertexColors()) {
if (cinterp == ColorInterpolation.HSV) {
appendln(mb, " colorOut.diffuse = rgba2hsva(vertex_color);");
} else {
appendln(mb, " colorOut.diffuse = vertex_color;");
}
appendln(mb);
}
break;
case DEFAULT:
case POINTS:
if (info.hasVertexColors()) {
if (cinterp == ColorInterpolation.HSV) {
appendln(mb, " colorOut.diffuse = rgba2hsva(vertex_color);");
} else {
appendln(mb, " colorOut.diffuse = vertex_color;");
}
appendln(mb);
}
break;
}
}
// do lighting computations
if (!info.isSelecting()) {
switch(info.getShading()) {
case FLAT:
// case GOURAUD:
if (info.numLights() > 0) {
appendln(mb, " // per-vertex lighting computations");
appendln(mb, " // compute camera position/normal");
appendln(mb, " vec4 camera_position = vm_matrix * vec4(position, 1.0);");
if (info.hasVertexNormals()) {
appendln(mb, " vec4 camera_normal = normal_matrix * vec4(normal, 0.0);");
} else {
appendln(mb, " vec4 camera_normal = -camera_position; // assume pointed at camera");
}
appendln(mb, " vec3 nfront = normalize(camera_normal.xyz);");
appendln(mb, " vec3 nback = -nfront;");
appendln(mb, " vec3 eye = normalize(-camera_position.xyz);");
appendln(mb, " ");
appendln(mb, " // accumulated light colors");
appendln(mb, " vec3 fldiff = vec3(0.0); // front");
appendln(mb, " vec3 flambi = vec3(0.0);");
appendln(mb, " vec3 flspec = vec3(0.0);");
appendln(mb, " vec3 bldiff = vec3(0.0); // back");
appendln(mb, " vec3 blambi = vec3(0.0);");
appendln(mb, " vec3 blspec = vec3(0.0);");
appendln(mb, " ");
appendln(mb, " // lights");
appendln(mb, " for (int i=0; i<" + info.numLights() + "; ++i) {");
appendln(mb, " vec3 light_to_vertex = camera_position.xyz-light[i].position.xyz;");
appendln(mb, " float lightdist = length(light_to_vertex);");
appendln(mb, " light_to_vertex = light_to_vertex/lightdist;");
appendln(mb, " vec3 light_direction = normalize(light[i].direction.xyz);");
appendln(mb, " ");
appendln(mb, " float spotatt = 1.0; // spot attentuation initially zero if non-spotlight");
appendln(mb, " float coslimit = light[i].direction.w;");
appendln(mb, " if (coslimit > 0) {");
appendln(mb, " // check angle");
appendln(mb, " float coslight = dot(light_direction, light_to_vertex);");
appendln(mb, " if (coslight < coslimit) {");
appendln(mb, " spotatt = 0;");
appendln(mb, " } else {");
appendln(mb, " spotatt = pow(coslight, light[i].attenuation.w);");
appendln(mb, " }");
appendln(mb, " }");
appendln(mb, " ");
appendln(mb, " // distance attenuation doesn't affect directional lights");
appendln(mb, " float att = mix(1.0, 1.0 / (light[i].attenuation.x + light[i].attenuation.y*lightdist +");
appendln(mb, " light[i].attenuation.z*lightdist*lightdist), light[i].position.w);");
appendln(mb, " att *= spotatt; // combine into a single attenuation parameter");
appendln(mb, " ");
appendln(mb, " // determine direction either from point or direction using direction indicator");
appendln(mb, " light_direction = mix(light_direction, light_to_vertex, light[i].position.w);");
appendln(mb, " vec2 ds = blinnPhongCoeffs( nfront, -light_direction, eye, front_material.specular.a);");
appendln(mb, " flambi += intensity_scale*light[i].ambient.rgb;");
appendln(mb, " fldiff += intensity_scale*att*ds.x*light[i].diffuse.rgb;");
appendln(mb, " flspec += intensity_scale*att*ds.y*light[i].specular.rgb;");
appendln(mb);
appendln(mb, " ds = blinnPhongCoeffs( nback, -light_direction, eye, back_material.specular.a);");
appendln(mb, " blambi += intensity_scale*light[i].ambient.rgb;");
appendln(mb, " bldiff += intensity_scale*att*ds.x*light[i].diffuse.rgb;");
appendln(mb, " blspec += intensity_scale*att*ds.y*light[i].specular.rgb;");
appendln(mb, " }");
appendln(mb, " ");
appendln(mb, " // accumulate");
appendln(mb, " lightOut.front_ambient = flambi;");
appendln(mb, " lightOut.front_diffuse = fldiff;");
appendln(mb, " lightOut.front_specular = flspec;");
appendln(mb, " lightOut.back_ambient = blambi;");
appendln(mb, " lightOut.back_diffuse = bldiff;");
appendln(mb, " lightOut.back_specular = blspec;");
appendln(mb);
}
break;
case SMOOTH:
case METAL:
// forward along direction information for vertices
if (info.numLights() > 0) {
appendln(mb, " // per-fragment lighting info, vertex normal and eye directions");
appendln(mb, " vec4 camera_position = vm_matrix * vec4(position, 1.0);");
if (info.hasVertexNormals()) {
appendln(mb, " vec4 camera_normal = normal_matrix * vec4(normal, 0.0);");
} else {
appendln(mb, " vec4 camera_normal = -camera_position; // assume pointed at camera");
}
appendln(mb, " surfOut.normal = normalize(camera_normal.xyz);");
appendln(mb, " surfOut.to_eye = -camera_position.xyz;");
appendln(mb, "");
}
break;
case NONE:
break;
}
}
// textures
boolean hasTextures = hasTextures(info);
if (hasTextures) {
appendln(mb, " // forward vertex texture coordinates");
appendln(mb, " textureOut.texcoord = (texture_matrix*vec4(vertex_texcoord, 0, 1)).xy;");
appendln(mb);
}
if (info.numClipPlanes() > 0) {
appendln(mb, " // clipping planes, in world coordinates");
appendln(mb, " vec4 world_position = m_matrix * vec4(position, 1.0);");
appendln(mb, " for (int i=0; i<" + info.numClipPlanes() + "; ++i) {");
appendln(mb, " gl_ClipDistance[i] = dot(world_position, clip_plane[i].plane);");
appendln(mb, " }");
appendln(mb);
}
appendln(mb, "}");
}
use of maspack.render.Renderer.ColorInterpolation in project artisynth_core by artisynth.
the class GLSLGenerator method buildFragmentShaderMain.
private static void buildFragmentShaderMain(StringBuilder mb, GLProgramInfo info) {
RenderingMode mode = info.getMode();
ColorInterpolation cinterp = info.getColorInterpolation();
boolean hasTextures = hasTextures(info);
appendln(mb, "// main fragment shader");
appendln(mb, "void main() {");
appendln(mb, "");
// points
if (mode == RenderingMode.POINTS && info.hasRoundPoints()) {
appendln(mb, " vec2 point_texcoord = 2.0*gl_PointCoord-1.0;");
appendln(mb, " float point_dist = dot(point_texcoord, point_texcoord);");
appendln(mb, " if ( point_dist > 1) {");
appendln(mb, " discard;");
appendln(mb, " }");
}
// do lighting computations
boolean lights = false;
if (!info.isSelecting()) {
if (info.getShading() != Shading.NONE && info.numLights() > 0) {
lights = true;
appendln(mb, " vec3 ambient = vec3(0.0);");
appendln(mb, " vec3 diffuse = vec3(0.0);");
appendln(mb, " vec3 specular = vec3(0.0);");
appendln(mb, " vec3 emission = vec3(0.0);");
appendln(mb, " Material material;");
switch(info.getShading()) {
case FLAT:
// case GOURAUD:
appendln(mb, " // imported per-vertex lighting");
appendln(mb, " if( gl_FrontFacing ) {");
appendln(mb, " ambient = lightIn.front_ambient;");
appendln(mb, " diffuse = lightIn.front_diffuse;");
appendln(mb, " specular = lightIn.front_specular;");
appendln(mb, " material = front_material;");
appendln(mb, " } else {");
appendln(mb, " diffuse = lightIn.back_diffuse;");
appendln(mb, " ambient = lightIn.back_ambient;");
appendln(mb, " specular = lightIn.back_specular;");
appendln(mb, " material = back_material;");
appendln(mb, " }");
appendln(mb);
break;
case SMOOTH:
case METAL:
appendln(mb, " // fragment normal and eye location for lighting");
if (!info.hasVertexNormals()) {
appendln(mb, " // compute normal using derivatives");
appendln(mb, " vec3 deyedx = dFdx(surfIn.to_eye);");
appendln(mb, " vec3 deyedy = dFdy(surfIn.to_eye);");
appendln(mb, " vec3 normal = normalize( cross( deyedx, deyedy ) );");
} else {
appendln(mb, " vec3 normal = normalize(surfIn.normal);");
}
appendln(mb, " vec3 eye = normalize(surfIn.to_eye);");
appendln(mb, " ");
if (hasTextures) {
if (info.hasNormalMap()) {
appendln(mb, " // normal-map purturbation");
appendln(mb, " normal = perturbNormal(-surfIn.to_eye, normal);");
appendln(mb, " ");
}
if (info.hasBumpMap()) {
appendln(mb, " // bump-map normal purturbation");
appendln(mb, " normal = perturbNormalBump(-surfIn.to_eye, normal, computedHdxy());");
appendln(mb, " ");
}
}
appendln(mb, " // choose material based on face orientation");
appendln(mb, " if (gl_FrontFacing) {");
appendln(mb, " material = front_material;");
appendln(mb, " } else {");
appendln(mb, " material = back_material;");
appendln(mb, " normal = -normal; // flip fragment normal");
appendln(mb, " }");
appendln(mb, " ");
appendln(mb, " // per-fragment lighting computations");
appendln(mb, " for (int i=0; i<" + info.numLights() + "; ++i) {");
appendln(mb, " vec3 light_to_vertex = -surfIn.to_eye-light[i].position.xyz;");
appendln(mb, " float lightdist = length(light_to_vertex);");
appendln(mb, " light_to_vertex = normalize(light_to_vertex);");
appendln(mb, " // determine direction either from point or direction using direction indicator");
appendln(mb, " vec3 light_direction = normalize(light[i].direction.xyz);");
appendln(mb, " ");
appendln(mb, " float spotatt = 1.0; // spot attentuation initially zero if non-spotlight");
appendln(mb, " float coslimit = light[i].direction.w;");
appendln(mb, " if (coslimit > 0) {");
appendln(mb, " // check angle");
appendln(mb, " float coslight = dot(light_direction, light_to_vertex);");
appendln(mb, " if (coslight < coslimit) {");
appendln(mb, " spotatt = 0;");
appendln(mb, " } else {");
appendln(mb, " spotatt = pow(coslight, light[i].attenuation.w);");
appendln(mb, " }");
appendln(mb, " }");
appendln(mb, " ");
appendln(mb, " // distance attenuation doesn't affect directional lights");
appendln(mb, " float att = mix(1.0, 1.0 / (light[i].attenuation.x + light[i].attenuation.y*lightdist +");
appendln(mb, " light[i].attenuation.z*lightdist*lightdist), light[i].position.w);");
appendln(mb, " att *= spotatt; // combine into a single attenuation parameter");
appendln(mb, " ");
appendln(mb, " // position vs directional light");
appendln(mb, " light_direction = mix(light_direction, light_to_vertex, light[i].position.w);");
appendln(mb, " vec2 ds = blinnPhongCoeffs( normal, -light_direction, eye, material.specular.a);");
appendln(mb, " ambient += intensity_scale*light[i].ambient.rgb;");
appendln(mb, " diffuse += intensity_scale*att*ds.x*light[i].diffuse.rgb;");
appendln(mb, " specular += intensity_scale*att*ds.y*light[i].specular.rgb;");
appendln(mb, " ");
appendln(mb, " }");
appendln(mb, " ");
break;
case NONE:
// never here
break;
}
} else {
appendln(mb, " // material to use;");
appendln(mb, " Material material;");
appendln(mb, " if( gl_FrontFacing ) {");
appendln(mb, " material = front_material;");
appendln(mb, " } else {");
appendln(mb, " material = back_material;");
appendln(mb, " }");
}
// combine colors
boolean hasFragmentColors = (info.getVertexColorMixing() != ColorMixing.NONE) && (info.hasVertexColors() || ((mode == RenderingMode.INSTANCED_POINTS || mode == RenderingMode.INSTANCED_FRAMES || mode == RenderingMode.INSTANCED_AFFINES) && info.hasInstanceColors()) || (mode == RenderingMode.INSTANCED_LINES && info.hasLineColors()));
appendln(mb, " // compute final color, starting with material");
appendln(mb, " vec4 fdiffuse = material.diffuse;");
appendln(mb, " vec3 fspecular = material.specular.rgb;");
appendln(mb, " vec3 femission = material.emission.rgb;");
appendln(mb);
if (hasFragmentColors) {
// mix colors
appendln(mb, " // incoming vertex color");
if (cinterp == ColorInterpolation.HSV) {
appendln(mb, " vec4 vcolor = hsva2rgba(colorIn.diffuse);");
} else {
appendln(mb, " vec4 vcolor = colorIn.diffuse;");
}
appendln(mb, " // mix");
ColorMixing cmix = info.getVertexColorMixing();
switch(cmix) {
case DECAL:
if (info.isMixVertexColorDiffuse()) {
appendln(mb, " fdiffuse = vec4(mix(fdiffuse.rgb,vcolor.rgb,vcolor.a), fdiffuse.a); // decal");
}
if (info.isMixVertexColorSpecular()) {
appendln(mb, " fspecular = mix(fspecular,vcolor.rgb,vcolor.a); // decal");
}
if (info.isMixVertexColorEmission()) {
appendln(mb, " femission = mix(femission,vcolor.rgb,vcolor.a); // decal");
}
break;
case MODULATE:
if (info.isMixVertexColorDiffuse()) {
appendln(mb, " fdiffuse = fdiffuse*vcolor; // modulate");
}
if (info.isMixVertexColorSpecular()) {
appendln(mb, " fspecular = fspecular*vcolor.rgb; // modulate");
}
if (info.isMixVertexColorEmission()) {
appendln(mb, " femission = femission*vcolor.rgb; // modulate");
}
break;
case REPLACE:
if (info.isMixVertexColorDiffuse()) {
appendln(mb, " fdiffuse = vcolor; // replace");
}
if (info.isMixVertexColorSpecular()) {
appendln(mb, " fspecular = vcolor.rgb; // replace");
}
if (info.isMixVertexColorEmission()) {
appendln(mb, " femission = vcolor.rgb; // replace");
}
break;
case NONE:
appendln(mb, " // vcolor ignored");
default:
}
}
if (hasTextures && info.hasColorMap()) {
appendln(mb, " // grab texture color and mix");
appendln(mb, " vec4 texture_color = texture( color_map, textureIn.texcoord );");
ColorMixing cmix = info.getTextureColorMixing();
switch(cmix) {
case DECAL:
if (info.isMixTextureColorDiffuse()) {
appendln(mb, " fdiffuse = vec4(mix(fdiffuse.rgb,texture_color.rgb,texture_color.a), fdiffuse.a); // decal");
}
if (info.isMixTextureColorSpecular()) {
appendln(mb, " fspecular = mix(fspecular,texture_color.rgb,texture_color.a); // decal");
}
if (info.isMixTextureColorEmission()) {
appendln(mb, " femission = mix(femission,texture_color.rgb,texture_color.a); // decal");
}
break;
case MODULATE:
if (info.isMixTextureColorDiffuse()) {
appendln(mb, " fdiffuse = fdiffuse*texture_color; // modulate");
}
if (info.isMixTextureColorSpecular()) {
appendln(mb, " fspecular = fspecular*texture_color.rgb; // modulate");
}
if (info.isMixTextureColorEmission()) {
appendln(mb, " femission = femission*texture_color.rgb; // modulate");
}
break;
case REPLACE:
if (info.isMixTextureColorDiffuse()) {
appendln(mb, " fdiffuse = texture_color; // replace");
}
if (info.isMixTextureColorSpecular()) {
appendln(mb, " fspecular = texture_color.rgb; // replace");
}
if (info.isMixTextureColorEmission()) {
appendln(mb, " femission = texture_color.rgb; // replace");
}
break;
case NONE:
appendln(mb, " // texture_color ignored");
break;
default:
}
appendln(mb);
}
}
// lighting
if (info.isSelecting()) {
appendln(mb, " fragment_color = selection_color;");
} else if (lights) {
appendln(mb, " // apply lighting");
appendln(mb, " ambient = fdiffuse.rgb*ambient*material.power.x;");
appendln(mb, " diffuse = fdiffuse.rgb*diffuse*material.power.y;");
appendln(mb, " specular = fspecular*specular*material.power.z;");
appendln(mb, " emission = femission*material.power.w; // emission only material-related");
appendln(mb, " fragment_color = vec4(max(diffuse+specular+emission, ambient), fdiffuse.a);");
} else {
appendln(mb, " fragment_color = fdiffuse;");
}
appendln(mb);
// appendln(mb, " // gamma correction");
// appendln(mb, " vec3 gamma = vec3(1.0/2.2);");
// appendln(mb, " fragment_color = vec4(pow(fragment_color.rgb, gamma), fragment_color.a);");
appendln(mb, "}");
}
use of maspack.render.Renderer.ColorInterpolation in project artisynth_core by artisynth.
the class PolygonalMeshRenderer method drawFaces.
private void drawFaces(Renderer renderer, RenderProps props, boolean highlight, RenderObject robj, FeatureIndexArray features, boolean featureSelection) {
boolean useTextures = robj.hasTextureCoords();
Renderer.FaceStyle savedFaceStyle = renderer.getFaceStyle();
Shading savedShadeModel = renderer.getShading();
Shading shading = props.getShading();
if (!robj.hasNormals() && shading != Shading.FLAT) {
shading = Shading.NONE;
}
renderer.setShading(shading);
renderer.setFaceColoring(props, highlight);
// XXX always front and back when selecting?
if (renderer.isSelecting()) {
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
} else {
renderer.setFaceStyle(props.getFaceStyle());
}
// int i = 0; // i is index of face
ColorInterpolation savedColorInterp = null;
if (usingHSV(getMesh())) {
savedColorInterp = renderer.setColorInterpolation(ColorInterpolation.HSV);
}
if (props.getDrawEdges()) {
renderer.setDepthOffset(-1);
}
ColorMapProps oldtprops = null;
NormalMapProps oldnprops = null;
BumpMapProps oldbprops = null;
if (useTextures) {
ColorMapProps dtprops = props.getColorMap();
oldtprops = renderer.setColorMap(dtprops);
NormalMapProps ntprops = props.getNormalMap();
oldnprops = renderer.setNormalMap(ntprops);
BumpMapProps btprops = props.getBumpMap();
oldbprops = renderer.setBumpMap(btprops);
}
if (renderer.isSelecting() && featureSelection) {
for (int i = 0; i < features.numFeatures(); ++i) {
renderer.beginSelectionQuery(features.getFeature(i));
renderer.drawVertices(robj, features.getVertices(), features.getFeatureOffset(i), features.getFeatureLength(i), DrawMode.TRIANGLES);
renderer.endSelectionQuery();
}
} else {
renderer.drawVertices(robj, features.getVertices(), DrawMode.TRIANGLES);
}
if (useTextures) {
// restore diffuse texture properties
renderer.setColorMap(oldtprops);
renderer.setNormalMap(oldnprops);
renderer.setBumpMap(oldbprops);
}
if (props.getDrawEdges()) {
renderer.setDepthOffset(0);
}
if (savedColorInterp != null) {
renderer.setColorInterpolation(savedColorInterp);
}
renderer.setFaceStyle(savedFaceStyle);
renderer.setShading(savedShadeModel);
}
use of maspack.render.Renderer.ColorInterpolation in project artisynth_core by artisynth.
the class PolygonalMeshRenderer method drawEdges.
/**
* Draws the edges associated with this mesh. Edge drawing is done using
* edgeWidth and edgeColor (or LineColor if edgeColor is undefined), according
* to the following rules:
*
* <p>If faces <i>are</i> also being drawn and there <i>is</i> vertex
* coloring, then edges should render using the edge color, with whatever
* shading is selected, and should respond to highlighting.
*
* <p>If faces <i>are</i> also being drawn and there <i>is no</i> vertex
* coloring, then (a) edges should not respond to highlighting (the faces
* will instead), and (b) edges should be rendered with whatever shading is
* selected, <i>unless</i> the edge color is the same as the face color, in
* which case shading is turned off so that the edges can be seen.
*
* <p>If faces <i>are not</i> also being drawn and there <i>is</i> vertex
* coloring, then edges should render using the vertex coloring, with
* whatever shading is selected, unless the mesh being highlighted, in which
* case it should they should be rendered with the highlight color.
*
* <p>If faces <i>are not</i> also being drawn and there <i>is no</i> vertex
* coloring, then edges should be rendered with whatever shading is
* selected, and should respond to highlighting.
*/
private void drawEdges(Renderer renderer, RenderProps props, boolean highlight, boolean alsoDrawingFaces, RenderObject robj, FeatureIndexArray features, boolean featureSelection) {
float savedLineWidth = renderer.getLineWidth();
Shading savedShadeModel = renderer.getShading();
boolean disableColors = false;
renderer.setLineWidth(props.getEdgeWidth());
Shading shading = props.getShading();
if (!robj.hasNormals() && shading != Shading.FLAT) {
shading = Shading.NONE;
}
float[] edgeColor = getEffectiveEdgeColor(props);
if (alsoDrawingFaces) {
highlight = false;
if (robj.hasColors()) {
disableColors = true;
} else {
if (colorsEqual(edgeColor, props.getFaceColorF())) {
// turn off shading so we can see edges
shading = Shading.NONE;
}
}
} else {
if (robj.hasColors()) {
if (highlight) {
disableColors = true;
}
}
}
renderer.setEdgeColoring(props, highlight);
renderer.setShading(shading);
ColorInterpolation savedColorInterp = null;
if (usingHSV(getMesh())) {
savedColorInterp = renderer.setColorInterpolation(ColorInterpolation.HSV);
}
ColorMixing savedColorMixing = null;
if (disableColors) {
savedColorMixing = renderer.getVertexColorMixing();
renderer.setVertexColorMixing(ColorMixing.NONE);
}
if (renderer.isSelecting() && featureSelection) {
for (int i = 0; i < features.numFeatures(); ++i) {
renderer.beginSelectionQuery(features.getFeature(i));
renderer.drawVertices(robj, features.getVertices(), features.getFeatureOffset(i), features.getFeatureLength(i), DrawMode.LINES);
renderer.endSelectionQuery();
}
} else {
renderer.drawVertices(robj, features.getVertices(), DrawMode.LINES);
}
if (savedColorInterp != null) {
renderer.setColorInterpolation(savedColorInterp);
}
if (disableColors) {
renderer.setVertexColorMixing(savedColorMixing);
}
renderer.setLineWidth(savedLineWidth);
renderer.setShading(savedShadeModel);
}
Aggregations