Ejemplo n.º 1
0
  private String getPrefixFragment(ProgramParameters parameters) {
    Log.debug("Called getPrefixFragment()");
    List<String> options = new ArrayList<String>();

    options.add("");

    options.add(SHADER_DEFINE.MAX_DIR_LIGHTS.getValue(parameters.maxDirLights));
    options.add(SHADER_DEFINE.MAX_POINT_LIGHTS.getValue(parameters.maxPointLights));
    options.add(SHADER_DEFINE.MAX_SPOT_LIGHTS.getValue(parameters.maxSpotLights));
    options.add(SHADER_DEFINE.MAX_HEMI_LIGHTS.getValue(parameters.maxHemiLights));

    options.add(SHADER_DEFINE.MAX_SHADOWS.getValue(parameters.maxShadows));

    if (parameters.alphaTest > 0)
      options.add(SHADER_DEFINE.ALPHATEST.getValue(parameters.alphaTest));

    if (parameters.gammaInput) options.add(SHADER_DEFINE.GAMMA_INPUT.getValue());
    if (parameters.gammaOutput) options.add(SHADER_DEFINE.GAMMA_OUTPUT.getValue());

    if (parameters.useFog) options.add(SHADER_DEFINE.USE_FOG.getValue());
    if (parameters.useFog2) options.add(SHADER_DEFINE.FOG_EXP2.getValue());

    if (parameters.map) options.add(SHADER_DEFINE.USE_MAP.getValue());
    if (parameters.envMap) options.add(SHADER_DEFINE.USE_ENVMAP.getValue());
    if (parameters.lightMap) options.add(SHADER_DEFINE.USE_LIGHTMAP.getValue());
    if (parameters.bumpMap) options.add(SHADER_DEFINE.USE_BUMPMAP.getValue());
    if (parameters.normalMap) options.add(SHADER_DEFINE.USE_NORMALMAP.getValue());
    if (parameters.specularMap) options.add(SHADER_DEFINE.USE_SPECULARMAP.getValue());
    if (parameters.alphaMap) options.add(SHADER_DEFINE.USE_ALPHAMAP.getValue());
    if (parameters.vertexColors) options.add(SHADER_DEFINE.USE_COLOR.getValue());

    if (parameters.metal) options.add(SHADER_DEFINE.METAL.getValue());
    if (parameters.wrapAround) options.add(SHADER_DEFINE.WRAP_AROUND.getValue());
    if (parameters.doubleSided) options.add(SHADER_DEFINE.DOUBLE_SIDED.getValue());
    if (parameters.flipSided) options.add(SHADER_DEFINE.FLIP_SIDED.getValue());

    if (parameters.shadowMapEnabled) {
      options.add(SHADER_DEFINE.USE_SHADOWMAP.getValue());
      if (parameters.shadowMapSoft) options.add(SHADER_DEFINE.SHADOWMAP_TYPE_PCF.getValue());
      else options.add(SHADER_DEFINE.SHADOWMAP_TYPE_BASIC.getValue());
    }

    if (parameters.shadowMapDebug) options.add(SHADER_DEFINE.SHADOWMAP_DEBUG.getValue());
    if (parameters.shadowMapCascade) options.add(SHADER_DEFINE.SHADOWMAP_CASCADE.getValue());

    if (parameters.logarithmicDepthBuffer) options.add(SHADER_DEFINE.USE_LOGDEPTHBUF.getValue());

    options.add("");
    String retval = "";
    for (String opt : options) retval += opt + "\n";

    List<String> extra = Arrays.asList("uniform mat4 viewMatrix;", "uniform vec3 cameraPosition;");

    for (String opt : extra) retval += opt + "\n";

    return retval;
  }
Ejemplo n.º 2
0
  public Shader getShader() {
    if (shader == null) {
      Log.debug("Called Material.setMaterialShaders()");

      this.shader = getAssociatedShader();
    }

    return this.shader;
  }
Ejemplo n.º 3
0
  private String getPrefixVertex(ProgramParameters parameters) {
    Log.debug("Called getPrefixVertex()");
    List<String> options = new ArrayList<String>();

    options.add("");

    if (parameters.supportsVertexTextures) options.add(SHADER_DEFINE.VERTEX_TEXTURES.getValue());

    if (parameters.gammaInput) options.add(SHADER_DEFINE.GAMMA_INPUT.getValue());

    if (parameters.gammaOutput) options.add(SHADER_DEFINE.GAMMA_OUTPUT.getValue());

    options.add(SHADER_DEFINE.MAX_DIR_LIGHTS.getValue(parameters.maxDirLights));
    options.add(SHADER_DEFINE.MAX_POINT_LIGHTS.getValue(parameters.maxPointLights));
    options.add(SHADER_DEFINE.MAX_SPOT_LIGHTS.getValue(parameters.maxSpotLights));
    options.add(SHADER_DEFINE.MAX_HEMI_LIGHTS.getValue(parameters.maxHemiLights));

    options.add(SHADER_DEFINE.MAX_SHADOWS.getValue(parameters.maxShadows));

    options.add(SHADER_DEFINE.MAX_BONES.getValue(parameters.maxBones));

    if (parameters.map) options.add(SHADER_DEFINE.USE_MAP.getValue());
    if (parameters.envMap) options.add(SHADER_DEFINE.USE_ENVMAP.getValue());
    if (parameters.lightMap) options.add(SHADER_DEFINE.USE_LIGHTMAP.getValue());
    if (parameters.bumpMap) options.add(SHADER_DEFINE.USE_BUMPMAP.getValue());
    if (parameters.normalMap) options.add(SHADER_DEFINE.USE_NORMALMAP.getValue());
    if (parameters.specularMap) options.add(SHADER_DEFINE.USE_SPECULARMAP.getValue());
    if (parameters.alphaMap) options.add(SHADER_DEFINE.USE_ALPHAMAP.getValue());
    if (parameters.vertexColors) options.add(SHADER_DEFINE.USE_COLOR.getValue());

    if (parameters.skinning) options.add(SHADER_DEFINE.USE_SKINNING.getValue());
    if (parameters.useVertexTexture) options.add(SHADER_DEFINE.BONE_TEXTURE.getValue());

    if (parameters.morphTargets) options.add(SHADER_DEFINE.USE_MORPHTARGETS.getValue());
    if (parameters.morphNormals) options.add(SHADER_DEFINE.USE_MORPHNORMALS.getValue());
    if (parameters.wrapAround) options.add(SHADER_DEFINE.WRAP_AROUND.getValue());
    if (parameters.doubleSided) options.add(SHADER_DEFINE.DOUBLE_SIDED.getValue());
    if (parameters.flipSided) options.add(SHADER_DEFINE.FLIP_SIDED.getValue());

    if (parameters.shadowMapEnabled) {
      options.add(SHADER_DEFINE.USE_SHADOWMAP.getValue());
      if (parameters.shadowMapSoft) options.add(SHADER_DEFINE.SHADOWMAP_TYPE_PCF.getValue());
      else options.add(SHADER_DEFINE.SHADOWMAP_TYPE_BASIC.getValue());
    }

    if (parameters.shadowMapDebug) options.add(SHADER_DEFINE.SHADOWMAP_DEBUG.getValue());
    if (parameters.shadowMapCascade) options.add(SHADER_DEFINE.SHADOWMAP_CASCADE.getValue());

    if (parameters.sizeAttenuation) options.add(SHADER_DEFINE.USE_SIZEATTENUATION.getValue());

    if (parameters.logarithmicDepthBuffer) options.add(SHADER_DEFINE.USE_LOGDEPTHBUF.getValue());

    options.add("");

    String retval = "";
    for (String opt : options) retval += opt + "\n";

    List<String> extra =
        Arrays.asList(
            "uniform mat4 modelMatrix;",
            "uniform mat4 modelViewMatrix;",
            "uniform mat4 projectionMatrix;",
            "uniform mat4 viewMatrix;",
            "uniform mat3 normalMatrix;",
            "uniform vec3 cameraPosition;",
            "attribute vec3 position;",
            "attribute vec3 normal;",
            "attribute vec2 uv;",
            "attribute vec2 uv2;",
            "#ifdef USE_COLOR",
            "	attribute vec3 color;",
            "#endif",
            "#ifdef USE_MORPHTARGETS",
            "	attribute vec3 morphTarget0;",
            "	attribute vec3 morphTarget1;",
            "	attribute vec3 morphTarget2;",
            "	attribute vec3 morphTarget3;",
            "	#ifdef USE_MORPHNORMALS",
            "		attribute vec3 morphNormal0;",
            "		attribute vec3 morphNormal1;",
            "		attribute vec3 morphNormal2;",
            "		attribute vec3 morphNormal3;",
            "	#else",
            "		attribute vec3 morphTarget4;",
            "		attribute vec3 morphTarget5;",
            "		attribute vec3 morphTarget6;",
            "		attribute vec3 morphTarget7;",
            "	#endif",
            "#endif",
            "#ifdef USE_SKINNING",
            "	attribute vec4 skinIndex;",
            "	attribute vec4 skinWeight;",
            "#endif");

    for (String opt : extra) retval += opt + "\n";

    return retval;
  }