import java.awt.Color; import java.awt.color.ColorSpace; class cMaterial implements java.io.Serializable { static final long serialVersionUID = -5427703380996095054L; //static final long serialVersionUID = 3391777332676367102L; public cMaterial() { } public cMaterial(float val) { color = val; modulation = val; metalness = val; diffuse = val; specular = val; shininess = val; shift = val; ambient = val; lightarea = val; factor = val; velvet = val; sheen = val; subsurface = val; bump = val; aniso = val; anisoV = val; cameralight = val; diffuseness = val; shadow = val; texture = val; opacity = val; fakedepth = val; shadowbias = val; } public cMaterial(cMaterial mat) { this(); if (mat != null) { Set(mat); } } void Set(cMaterial mat) { color = mat.color; modulation = mat.modulation; metalness = mat.metalness; diffuse = mat.diffuse; specular = mat.specular; shininess = mat.shininess; shift = mat.shift; ambient = mat.ambient; lightarea = mat.lightarea; factor = mat.factor; velvet = mat.velvet; sheen = mat.sheen; subsurface = mat.subsurface; bump = mat.bump; aniso = mat.aniso; anisoV = mat.anisoV; cameralight = mat.cameralight; diffuseness = mat.diffuseness; shadow = mat.shadow; texture = mat.texture; opacity = mat.opacity; fakedepth = mat.fakedepth; shadowbias = mat.shadowbias; //Invariants(); } void UpdateMaterial(cMaterial anchor, cMaterial current) { color *= Factor(anchor.color, current.color); //if (anchor.saturation == 0) // anchor.saturation = 0.001f; if (anchor.modulation == 0) anchor.modulation = 0.001f; modulation *= Factor(anchor.modulation, current.modulation); metalness *= Factor(anchor.metalness, current.metalness); diffuse *= Factor(anchor.diffuse, current.diffuse); specular *= Factor(anchor.specular, current.specular); shininess *= Factor(anchor.shininess, current.shininess); shift *= Factor(anchor.shift, current.shift); ambient *= Factor(anchor.ambient, current.ambient); lightarea *= Factor(anchor.lightarea, current.lightarea); factor *= Factor(anchor.factor, current.factor); velvet *= Factor(anchor.velvet, current.velvet); sheen *= Factor(anchor.sheen, current.sheen); subsurface *= Factor(anchor.subsurface, current.subsurface); bump *= Factor(anchor.bump, current.bump); aniso *= Factor(anchor.aniso, current.aniso); anisoV *= Factor(anchor.anisoV, current.anisoV); cameralight *= Factor(anchor.cameralight, current.cameralight); diffuseness *= Factor(anchor.diffuseness, current.diffuseness); shadow *= Factor(anchor.shadow, current.shadow); texture *= Factor(anchor.texture, current.texture); opacity *= Factor(anchor.opacity, current.opacity); fakedepth *= Factor(anchor.fakedepth, current.fakedepth); shadowbias *= Factor(anchor.shadowbias, current.shadowbias); } float Factor(float anchor, float current) { if (anchor <= 0) { assert anchor > 0; } return current / anchor; } void Draw(CameraPane display, boolean selected) { //new Exception().printStackTrace(); if (display.IsFrozen() && !selected || display.ambientOcclusion) // || display.drawMode == display.SHADOW) { return; } javax.media.opengl.GL gl = display.GetGL(); //Color col = Color.getHSBColor(color,modulation,1); //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0); if (!multiply) { display.color = color; display.saturation = modulation; } else { display.color *= color*2; display.saturation *= modulation*2; } cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0); float[] colorV = GrafreeD.colorV; /**/ if (display.drawMode == display.DEFAULT) // && display.RENDERPROGRAM == 0) { colorV[0] = display.modelParams0[0] * diffuse; colorV[1] = display.modelParams0[1] * diffuse; colorV[2] = display.modelParams0[2] * diffuse; colorV[3] = opacity; gl.glColor4f(colorV[0], colorV[1], colorV[2], opacity); //System.out.println("Opacity = " + opacity); gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0); //color[0] /= 2; color[1] /= 2; color[2] /= 2; gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0); float amb = ambient; if (amb < cameralight) { amb = cameralight; } colorV[0] = display.modelParams0[0] * diffuse * amb; colorV[1] = display.modelParams0[1] * diffuse * amb; colorV[2] = display.modelParams0[2] * diffuse * amb; gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0); //color[0] /= 2; color[1] /= 2; color[2] /= 2; gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0); /**/ colorV[0] = ((1 - metalness) + display.modelParams0[0] * metalness) * specular; colorV[1] = ((1 - metalness) + display.modelParams0[1] * metalness) * specular; colorV[2] = ((1 - metalness) + display.modelParams0[2] * metalness) * specular; gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0); //color[0] /= 2; color[1] /= 2; color[2] /= 2; gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0); colorV[0] = 10 / shininess; // 1/0.005f; //System.out.println("shininess = " + colorV[0]); if (colorV[0] > 128) { colorV[0] = 128; } gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0); gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0); /**/ } /**/ //selected = false; selected = selected && display.flash; //display.modelParams0[0] = 0; // pigment.r; //display.modelParams0[1] = 0; // pigment.g; //display.modelParams0[2] = 0; // pigment.b; if (!multiply) { display.modelParams0[3] = metalness; display.modelParams1[0] = diffuse; display.modelParams1[1] = specular; display.modelParams1[2] = 1 / shininess; display.modelParams1[3] = shift; display.modelParams2[0] = ambient; display.modelParams2[1] = lightarea; //System.out.println("light area = " + lightarea); display.modelParams2[2] = 1 / factor; // diffuseness display.modelParams2[3] = velvet; display.modelParams3[0] = sheen; display.modelParams3[1] = subsurface; display.modelParams3[2] = bump; // backlit display.modelParams3[3] = aniso; display.modelParams4[0] = anisoV; display.modelParams4[1] = selected ? 100 : cameralight; //System.out.println("selected = " + selected); display.modelParams4[2] = diffuseness; display.modelParams4[3] = shadow; display.modelParams5[0] = texture; display.modelParams5[1] = opacity; display.modelParams5[2] = fakedepth; display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (shadowbias - 0.005f) / 10; } else { display.modelParams0[3] *= metalness*2; display.modelParams1[0] *= diffuse*2; display.modelParams1[1] *= specular*2; display.modelParams1[2] *= shininess*2; display.modelParams1[3] *= shift*2; display.modelParams2[0] *= ambient*2; display.modelParams2[1] *= lightarea*2; display.modelParams2[2] *= factor*2; display.modelParams2[3] *= velvet*2; display.modelParams3[0] *= sheen*2; display.modelParams3[1] *= subsurface*2; display.modelParams3[2] *= bump*2; display.modelParams3[3] *= aniso*2; display.modelParams4[0] *= anisoV*2; display.modelParams4[1] *= cameralight*2; //System.out.println("selected = " + selected); display.modelParams4[2] *= diffuseness*2; display.modelParams4[3] *= shadow*2; display.modelParams5[0] *= texture*2; display.modelParams5[1] *= opacity*2; display.modelParams5[2] *= fakedepth*2; display.modelParams5[3] *= shadowbias*2; } display.modelParams6[0] = 0; display.modelParams6[1] = 0; display.modelParams6[2] = 0; display.modelParams6[3] = 0; display.modelParams7[0] = 0; display.modelParams7[1] = 1000; display.modelParams7[2] = 0; display.modelParams7[3] = 0; display.modelParams6[0] = 100; // criss de bug de bump Object3D.cVector2[] extparams = display.vector2buffer; if (extparams != null && extparams.length > 0 && extparams[0] != null) { display.modelParams6[0] = extparams[0].x / 1000.0f; // bump display.modelParams6[1] = extparams[0].y / 1000.0f; // noise if (extparams.length > 1) { display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough if (extparams.length > 2) { display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power float x = extparams[2].y / 1000.0f; //if (x == 0) // x = 1f; display.modelParams7[1] = 1 / x / x / x / x / x / x / x / x / x / x / x / x / x; // (float)Math.pow(-Math.log((extparams[2].y+0.00) / 1000.0f), 1); // opacity power if (extparams[2].y > 0) { //System.out.println("extparams[1].y = " + extparams[1].y); //System.out.println("extparams[2].y = " + extparams[2].y); //System.out.println("opacity power = " + display.modelParams7[1]); } } } } //if (display.modelParams6[2] != 0) /* System.out.println("modelParams0[0] = " + display.modelParams0[0]); System.out.println("modelParams0[1] = " + display.modelParams0[1]); System.out.println("modelParams0[2] = " + display.modelParams0[2]); System.out.println("modelParams0[3] = " + display.modelParams0[3]); System.out.println("modelParams1[0] = " + display.modelParams1[0]); System.out.println("modelParams1[1] = " + display.modelParams1[1]); System.out.println("modelParams1[2] = " + display.modelParams1[2]); System.out.println("modelParams1[3] = " + display.modelParams1[3]); System.out.println("modelParams2[0] = " + display.modelParams2[0]); System.out.println("modelParams2[1] = " + display.modelParams2[1]); System.out.println("modelParams2[2] = " + display.modelParams2[2]); System.out.println("modelParams2[3] = " + display.modelParams2[3]); System.out.println("modelParams3[0] = " + display.modelParams3[0]); System.out.println("modelParams3[1] = " + display.modelParams3[1]); System.out.println("modelParams3[2] = " + display.modelParams3[2]); System.out.println("modelParams3[3] = " + display.modelParams3[3]); System.out.println("modelParams4[0] = " + display.modelParams4[0]); System.out.println("modelParams4[1] = " + display.modelParams4[1]); System.out.println("modelParams4[2] = " + display.modelParams4[2]); System.out.println("modelParams4[3] = " + display.modelParams4[3]); System.out.println("modelParams5[0] = " + display.modelParams5[0]); System.out.println("modelParams5[1] = " + display.modelParams5[1]); System.out.println("modelParams5[2] = " + display.modelParams5[2]); System.out.println("modelParams5[3] = " + display.modelParams5[3]); System.out.println("modelParams6[0] = " + display.modelParams6[0]); System.out.println("modelParams6[1] = " + display.modelParams6[1]); System.out.println("modelParams6[2] = " + display.modelParams6[2]); System.out.println("modelParams6[3] = " + display.modelParams6[3]); System.out.println("modelParams7[0] = " + display.modelParams7[0]); System.out.println("modelParams7[1] = " + display.modelParams7[1]); System.out.println("modelParams7[2] = " + display.modelParams7[2]); System.out.println("modelParams7[3] = " + display.modelParams7[3]); /**/ //assert (display.modelParams6[2] == 0); //System.out.println("noise power = " + display.modelParams7[0]); //System.out.println("shadowbias = " + shadowbias); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0); int mode = display.FP_SHADER; if (aniso != anisoV || aniso > 0.002) { mode |= display.FP_ANISO; } display.EnableProgram(mode); //System.out.println("opacity power = " + display.modelParams7[1]); if (!multiply) { if (display.drawMode == CameraPane.SHADOW) gl.glDepthMask(opacity >= 0.9 && display.modelParams7[1] > 0.1); else gl.glDepthMask(opacity >= 0.99); } } float color = 0.5f, modulation /*SATURATION*/ = 0.001f, metalness = 0.001f; float diffuse = 0.75f, specular = 0.25f, shininess = 0.75f, shift = 1; float ambient = 0.001f, lightarea = 0.025f, factor = 0.001f, velvet = 0.001f; float sheen = 1f, subsurface = 0.001f, bump = 0.75f, aniso = 0.001f, anisoV = 0.001f; float cameralight = 0.2f, diffuseness = 0.001f, shadow = 5f, texture = 1f, opacity = 1; float fakedepth = 0.5f, shadowbias = 0.01f; // 0.001f; boolean multiply; void Invariants() { assert (color > 0); assert (modulation > 0); assert (metalness > 0); assert (diffuse > 0); assert (specular > 0); assert (shininess > 0); assert (shift > 0); assert (ambient > 0); assert (lightarea > 0); assert (factor > 0); assert (velvet > 0); assert (sheen > 0); assert (subsurface > 0); assert (bump > 0); assert (aniso > 0); assert (anisoV > 0); assert (cameralight > 0); assert (diffuseness > 0); assert (shadow > 0); assert (texture > 0); assert (opacity > 0); assert (fakedepth > 0); assert (shadowbias > 0); } }