@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); }
public void refreshUniforms(Camera camera, boolean isGammaInput) { if (!(this instanceof HasMaterialMap)) return; Map<String, Uniform> uniforms = getShader().getUniforms(); uniforms.get("opacity").setValue(getOpacity()); if (this instanceof HasColor) { if (isGammaInput) ((Color) uniforms.get("diffuse").getValue()) .copyGammaToLinear(((HasColor) this).getColor()); else uniforms.get("diffuse").setValue(((HasColor) this).getColor()); } if (this instanceof HasMap) { uniforms.get("map").setValue(((HasMap) this).getMap()); } if (this instanceof HasLightMap) uniforms.get("lightMap").setValue(((HasLightMap) this).getLightMap()); if (this instanceof HasSpecularMap) { uniforms.get("specularMap").setValue(((HasSpecularMap) this).getSpecularMap()); } if (this instanceof HasAlphaMap) { uniforms.get("alphaMap").setValue(((HasAlphaMap) this).getAlphaMap()); } if (this instanceof HasBumpMap) { uniforms.get("bumpMap").setValue(((HasBumpMap) this).getBumpMap()); uniforms.get("bumpScale").setValue(((HasBumpMap) this).getBumpScale()); } if (this instanceof HasNormalMap) { uniforms.get("normalMap").setValue(((HasNormalMap) this).getNormalMap()); uniforms.get("normalScale").setValue(((HasNormalMap) this).getNormalScale()); } // uv repeat and offset setting priorities // 1. color map // 2. specular map // 3. normal map // 4. bump map // 5. alpha map Texture uvScaleMap = null; if (this instanceof HasMap) uvScaleMap = ((HasMap) this).getMap(); if (uvScaleMap == null && this instanceof HasSpecularMap) uvScaleMap = ((HasSpecularMap) this).getSpecularMap(); if (uvScaleMap == null && this instanceof HasNormalMap) uvScaleMap = ((HasNormalMap) this).getNormalMap(); if (uvScaleMap == null && this instanceof HasBumpMap) uvScaleMap = ((HasBumpMap) this).getBumpMap(); if (uvScaleMap == null && this instanceof HasAlphaMap) uvScaleMap = ((HasAlphaMap) this).getAlphaMap(); if (uvScaleMap != null) { ((Vector4) uniforms.get("offsetRepeat").getValue()) .set( uvScaleMap.getOffset().getX(), uvScaleMap.getOffset().getY(), uvScaleMap.getRepeat().getX(), uvScaleMap.getRepeat().getY()); } if (this instanceof HasEnvMap) { HasEnvMap envMapMaterial = (HasEnvMap) this; uniforms.get("envMap").setValue(envMapMaterial.getEnvMap()); uniforms .get("flipEnvMap") .setValue( (envMapMaterial.getEnvMap() != null && envMapMaterial.getEnvMap().getClass() == RenderTargetCubeTexture.class) ? 1.0 : -1.0); if (isGammaInput) uniforms.get("reflectivity").setValue(envMapMaterial.getReflectivity()); else uniforms.get("reflectivity").setValue(envMapMaterial.getReflectivity()); uniforms.get("refractionRatio").setValue(envMapMaterial.getRefractionRatio()); uniforms.get("combine").setValue(envMapMaterial.getCombine().getValue()); uniforms .get("useRefract") .setValue( (envMapMaterial.getEnvMap() != null && envMapMaterial.getEnvMap().getMapping() == Texture.MAPPING_MODE.CUBE_REFRACTION) ? 1 : 0); } }