@Override protected void onStart() { camera = new PerspectiveCamera(45, getRenderer().getAbsoluteAspectRation(), 1, 10000); camera.getPosition().setZ(300); this.attributes = new HashMap<String, Attribute>(); attributes.put("size", new Attribute(Attribute.TYPE.F, new ArrayList<Integer>())); attributes.put("ca", new Attribute(Attribute.TYPE.C, new ArrayList<Color>())); Map<String, Uniform> uniforms = new HashMap<String, Uniform>(); uniforms.put("amplitude", new Uniform(Uniform.TYPE.F, 1.0)); uniforms.put("color", new Uniform(Uniform.TYPE.C, new Color(0xffffff))); Texture texture = new Texture(image); texture.setWrapS(TextureWrapMode.REPEAT); texture.setWrapT(TextureWrapMode.REPEAT); uniforms.put("texture", new Uniform(Uniform.TYPE.T, texture)); ShaderMaterial shaderMaterial = new ShaderMaterial(Resources.INSTANCE); shaderMaterial.getShader().setAttributes(attributes); shaderMaterial.getShader().setUniforms(uniforms); shaderMaterial.setTransparent(true); int radius = 100, segments = 68, rings = 38; SphereGeometry geometry = new SphereGeometry(radius, segments, rings); this.vc1 = geometry.getVertices().size(); BoxGeometry geometry2 = new BoxGeometry(0.8 * radius, 0.8 * radius, 0.8 * radius, 10, 10, 10); geometry.merge(geometry2, null); this.sphere = new PointCloud(geometry, shaderMaterial); this.sphere.setSortParticles(true); List<Vector3> vertices = ((Geometry) sphere.getGeometry()).getVertices(); List<Double> values_size = (List<Double>) attributes.get("size").getValue(); List<Color> values_color = (List<Color>) attributes.get("ca").getValue(); for (int v = 0; v < vertices.size(); v++) { values_color.add(v, new Color(0xffffff)); if (v < vc1) { values_size.add(v, 10.0); values_color .get(v) .setHSL( 0.01 + 0.1 * (v / (double) vc1), 0.99, (vertices.get(v).getY() + radius) / (4.0 * radius)); } else { values_size.add(v, 40.0); values_color.get(v).setHSL(0.6, 0.75, 0.25 + vertices.get(v).getY() / (2.0 * radius)); } } getScene().add(sphere); }
private void createScene(Geometry geometry, double scale) { Texture mapHeight = new Texture(texture); mapHeight.setAnisotropy(4); mapHeight.getRepeat().set(0.998, 0.998); mapHeight.getOffset().set(0.001, 0.001); mapHeight.setWrapS(TextureWrapMode.REPEAT); mapHeight.setWrapT(TextureWrapMode.REPEAT); mapHeight.setFormat(PixelFormat.RGB); Texture mapSpecular = new Texture(textureSpec); mapSpecular.getRepeat().set(0.998, 0.998); mapSpecular.getOffset().set(0.001, 0.001); mapSpecular.setWrapS(TextureWrapMode.REPEAT); mapSpecular.setWrapT(TextureWrapMode.REPEAT); mapSpecular.setFormat(PixelFormat.RGB); Texture mapColor = new Texture(textureCol); mapColor.getRepeat().set(0.998, 0.998); mapColor.getOffset().set(0.001, 0.001); mapColor.setWrapS(TextureWrapMode.REPEAT); mapColor.setWrapT(TextureWrapMode.REPEAT); mapColor.setFormat(PixelFormat.RGB); SkinSimpleShader shader = new SkinSimpleShader(); Map<String, Uniform> uniforms = shader.getUniforms(); uniforms.get("enableBump").setValue(true); uniforms.get("enableSpecular").setValue(true); uniforms.get("tBeckmann").setValue(composerBeckmann.getRenderTarget1()); uniforms.get("tDiffuse").setValue(mapColor); uniforms.get("bumpMap").setValue(mapHeight); uniforms.get("specularMap").setValue(mapSpecular); ((Color) uniforms.get("ambient").getValue()).setHex(0xa0a0a0); ((Color) uniforms.get("diffuse").getValue()).setHex(0xa0a0a0); ((Color) uniforms.get("specular").getValue()).setHex(0xa0a0a0); uniforms.get("uRoughness").setValue(0.145); uniforms.get("uSpecularBrightness").setValue(0.75); uniforms.get("bumpScale").setValue(16.0); ((Vector4) uniforms.get("offsetRepeat").getValue()).set(0.001, 0.001, 0.998, 0.998); ShaderMaterial material = new ShaderMaterial(shader); material.setLights(true); mesh = new Mesh(geometry, material); mesh.getPosition().setY(-50); mesh.getScale().set(scale); mesh.setCastShadow(true); mesh.setReceiveShadow(true); getScene().add(mesh); }