Пример #1
0
  Node createDebugGeometry() {
    Line l = new Line(from.getPlanet().getPosition(), to.getPlanet().getPosition());

    line = new Geometry("Line #" + from.getPlanet().getID() + " to #" + to.getPlanet().getID(), l);

    Material material =
        new Material(
            SolarWarsApplication.getInstance().getAssetManager(),
            "Common/MatDefs/Misc/Unshaded.j3md");

    Player p = from.getPlanet().getOwner();
    ColorRGBA c;
    if (p == null) {
      c = ColorRGBA.White.clone();
      c.a = 0.5f;
      material.setColor("Color", c);
    } else {
      c = p.getColor();
      c.a = 0.5f;
      material.setColor("Color", c);
    }
    material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    line.setMaterial(material);

    createLabel();
    Node lineNode = new Node(line.getName() + "_Node");
    lineNode.attachChild(line);
    lineNode.attachChild(label);
    //        Vector3f pos = to.getPlanet().getPosition().
    //                subtract(from.getPlanet().getPosition());
    //        lineNode.setLocalTranslation(pos.mult(0.5f));
    return lineNode;
  }
Пример #2
0
 private Material getMaterial(ColorRGBA color) {
   Material mat = new Material(main.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
   mat.setColor("Diffuse", color);
   ColorRGBA clone = color.clone();
   clone.multLocal(0.8f);
   clone.a = 1f;
   mat.setColor("Ambient", clone);
   mat.setBoolean("UseMaterialColors", true);
   return mat;
 }
Пример #3
0
 private ColorRGBA getAmbientColor(LightList lightList) {
   ambientLightColor.set(0, 0, 0, 1);
   for (int j = 0; j < lightList.size(); j++) {
     Light l = lightList.get(j);
     if (l instanceof AmbientLight) {
       ambientLightColor.addLocal(l.getColor());
     }
   }
   ambientLightColor.a = 1.0f;
   return ambientLightColor;
 }
Пример #4
0
 Range(int start, String colorStr) {
   this.start = start;
   this.color = new ColorRGBA();
   if (colorStr.length() >= 6) {
     color.set(
         Integer.parseInt(colorStr.subSequence(0, 2).toString(), 16) / 255f,
         Integer.parseInt(colorStr.subSequence(2, 4).toString(), 16) / 255f,
         Integer.parseInt(colorStr.subSequence(4, 6).toString(), 16) / 255f,
         1);
     if (colorStr.length() == 8) {
       color.a = Integer.parseInt(colorStr.subSequence(6, 8).toString(), 16) / 255f;
     }
   } else {
     color.set(
         Integer.parseInt(Character.toString(colorStr.charAt(0)), 16) / 15f,
         Integer.parseInt(Character.toString(colorStr.charAt(1)), 16) / 15f,
         Integer.parseInt(Character.toString(colorStr.charAt(2)), 16) / 15f,
         1);
     if (colorStr.length() == 4) {
       color.a = Integer.parseInt(Character.toString(colorStr.charAt(3)), 16) / 15f;
     }
   }
 }
Пример #5
0
  protected void createMaterial() {
    Material material;

    if (alpha < 1f && transparent) {
      diffuse.a = alpha;
    }

    if (shadeless) {
      material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
      material.setColor("Color", diffuse.clone());
      material.setTexture("ColorMap", diffuseMap);
      // TODO: Add handling for alpha map?
    } else {
      material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
      material.setBoolean("UseMaterialColors", true);
      material.setColor("Ambient", ambient.clone());
      material.setColor("Diffuse", diffuse.clone());
      material.setColor("Specular", specular.clone());
      material.setFloat("Shininess", shininess); // prevents "premature culling" bug

      if (diffuseMap != null) material.setTexture("DiffuseMap", diffuseMap);
      if (specularMap != null) material.setTexture("SpecularMap", specularMap);
      if (normalMap != null) material.setTexture("NormalMap", normalMap);
      if (alphaMap != null) material.setTexture("AlphaMap", alphaMap);
    }

    if (transparent) {
      material.setTransparent(true);
      material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
      material.getAdditionalRenderState().setAlphaTest(true);
      material.getAdditionalRenderState().setAlphaFallOff(0.01f);
    }

    material.setName(matName);
    matList.put(matName, material);
  }
Пример #6
0
  protected void renderMultipassLighting(Shader shader, Geometry g, RenderManager rm) {

    Renderer r = rm.getRenderer();
    LightList lightList = g.getWorldLightList();
    Uniform lightDir = shader.getUniform("g_LightDirection");
    Uniform lightColor = shader.getUniform("g_LightColor");
    Uniform lightPos = shader.getUniform("g_LightPosition");
    Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
    boolean isFirstLight = true;
    boolean isSecondLight = false;

    for (int i = 0; i < lightList.size(); i++) {
      Light l = lightList.get(i);
      if (l instanceof AmbientLight) {
        continue;
      }

      if (isFirstLight) {
        // set ambient color for first light only
        ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));
        isFirstLight = false;
        isSecondLight = true;
      } else if (isSecondLight) {
        ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
        // apply additive blending for 2nd and future lights
        r.applyRenderState(additiveLight);
        isSecondLight = false;
      }

      TempVars vars = TempVars.get();
      Quaternion tmpLightDirection = vars.quat1;
      Quaternion tmpLightPosition = vars.quat2;
      ColorRGBA tmpLightColor = vars.color;
      Vector4f tmpVec = vars.vect4f;

      ColorRGBA color = l.getColor();
      tmpLightColor.set(color);
      tmpLightColor.a = l.getType().getId();
      lightColor.setValue(VarType.Vector4, tmpLightColor);

      switch (l.getType()) {
        case Directional:
          DirectionalLight dl = (DirectionalLight) l;
          Vector3f dir = dl.getDirection();

          tmpLightPosition.set(dir.getX(), dir.getY(), dir.getZ(), -1);
          lightPos.setValue(VarType.Vector4, tmpLightPosition);
          tmpLightDirection.set(0, 0, 0, 0);
          lightDir.setValue(VarType.Vector4, tmpLightDirection);
          break;
        case Point:
          PointLight pl = (PointLight) l;
          Vector3f pos = pl.getPosition();
          float invRadius = pl.getInvRadius();

          tmpLightPosition.set(pos.getX(), pos.getY(), pos.getZ(), invRadius);
          lightPos.setValue(VarType.Vector4, tmpLightPosition);
          tmpLightDirection.set(0, 0, 0, 0);
          lightDir.setValue(VarType.Vector4, tmpLightDirection);
          break;
        case Spot:
          SpotLight sl = (SpotLight) l;
          Vector3f pos2 = sl.getPosition();
          Vector3f dir2 = sl.getDirection();
          float invRange = sl.getInvSpotRange();
          float spotAngleCos = sl.getPackedAngleCos();

          tmpLightPosition.set(pos2.getX(), pos2.getY(), pos2.getZ(), invRange);
          lightPos.setValue(VarType.Vector4, tmpLightPosition);

          // We transform the spot directoin in view space here to save 5 varying later in the
          // lighting shader
          // one vec4 less and a vec4 that becomes a vec3
          // the downside is that spotAngleCos decoding happen now in the frag shader.
          tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0);
          rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
          tmpLightDirection.set(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos);

          lightDir.setValue(VarType.Vector4, tmpLightDirection);

          break;
        default:
          throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
      }
      vars.release();
      r.setShader(shader);
      r.renderMesh(g.getMesh(), g.getLodLevel(), 1);
    }

    if (isFirstLight && lightList.size() > 0) {
      // There are only ambient lights in the scene. Render
      // a dummy "normal light" so we can see the ambient
      ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));
      lightColor.setValue(VarType.Vector4, ColorRGBA.BlackNoAlpha);
      lightPos.setValue(VarType.Vector4, nullDirLight);
      r.setShader(shader);
      r.renderMesh(g.getMesh(), g.getLodLevel(), 1);
    }
  }