private Object readValue(final VarType type, final String value) throws IOException{ if (type.isTextureType()) { return parseTextureType(type, value); } else {
defaultValObj = readValue(type, defaultVal); if(type.isTextureType()){ materialDef.addMaterialParamTexture(type, name, colorSpace); }else{
private void readValueParam(String statement) throws IOException{ // Use limit=1 incase filename contains colons String[] split = statement.split(":", 2); if (split.length != 2){ throw new IOException("Value parameter statement syntax incorrect"); } String name = split[0].trim(); // parse value MatParam p = material.getMaterialDef().getMaterialParam(name); if (p == null){ throw new IOException("The material parameter: "+name+" is undefined."); } Object valueObj = readValue(p.getVarType(), split[1]); if (p.getVarType().isTextureType()){ material.setTextureParam(name, p.getVarType(), (Texture) valueObj); }else{ material.setParam(name, p.getVarType(), valueObj); } }
/** * Pass a parameter to the material shader. * * @param name the name of the parameter defined in the material definition (j3md) * @param type the type of the parameter {@link VarType} * @param value the value of the parameter */ public void setParam(String name, VarType type, Object value) { checkSetParam(type, name); if (type.isTextureType()) { setTextureParam(name, type, (Texture)value); } else { MatParam val = getParam(name); if (val == null) { MatParam paramDef = def.getMaterialParam(name); paramValues.put(name, new MatParam(type, name, value)); } else { val.setValue(value); } if (technique != null) { technique.notifyParamChanged(name, type, value); } } }
for (int i = 0; i < paramValues.size(); i++) { MatParam param = paramValues.getValue(i); if (!param.getVarType().isTextureType()) { continue;
private int applyOverrides(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> overrides, int unit) { for (MatParamOverride override : overrides.getArray()) { VarType type = override.getVarType(); MatParam paramDef = def.getMaterialParam(override.getName()); if (paramDef == null || paramDef.getVarType() != type || !override.isEnabled()) { continue; } Uniform uniform = shader.getUniform(override.getPrefixedName()); if (override.getValue() != null) { if (type.isTextureType()) { renderer.setTexture(unit, (Texture) override.getValue()); uniform.setValue(VarType.Int, unit); unit++; } else { uniform.setValue(type, override.getValue()); } } else { uniform.clearValue(); } } return unit; }
if (type.isTextureType()) { renderer.setTexture(unit, (Texture) param.getValue()); uniform.setValue(VarType.Int, unit);
private Object readValue(final VarType type, final String value) throws IOException{ if (type.isTextureType()) { return parseTextureType(type, value); } else {
defaultValObj = readValue(type, defaultVal); if(type.isTextureType()){ materialDef.addMaterialParamTexture(type, name, colorSpace); }else{
private Object readValue(VarType type, String value) throws IOException{ if (type.isTextureType()){
private void readValueParam(String statement) throws IOException{ // Use limit=1 incase filename contains colons String[] split = statement.split(":", 2); if (split.length != 2){ throw new IOException("Value parameter statement syntax incorrect"); } String name = split[0].trim(); // parse value MatParam p = material.getMaterialDef().getMaterialParam(name); if (p == null){ throw new IOException("The material parameter: "+name+" is undefined."); } Object valueObj = readValue(p.getVarType(), split[1]); if (p.getVarType().isTextureType()){ material.setTextureParam(name, p.getVarType(), (Texture) valueObj); }else{ material.setParam(name, p.getVarType(), valueObj); } }
private void readValueParam(String statement) throws IOException{ // Use limit=1 incase filename contains colons String[] split = statement.split(":", 2); if (split.length != 2){ throw new IOException("Value parameter statement syntax incorrect"); } String name = split[0].trim(); // parse value MatParam p = material.getMaterialDef().getMaterialParam(name); if (p == null){ throw new IOException("The material parameter: "+name+" is undefined."); } Object valueObj = readValue(p.getVarType(), split[1]); if (p.getVarType().isTextureType()){ material.setTextureParam(name, p.getVarType(), (Texture) valueObj); }else{ material.setParam(name, p.getVarType(), valueObj); } }
/** * Pass a parameter to the material shader. * * @param name the name of the parameter defined in the material definition (j3md) * @param type the type of the parameter {@link VarType} * @param value the value of the parameter */ public void setParam(String name, VarType type, Object value) { checkSetParam(type, name); if (type.isTextureType()) { setTextureParam(name, type, (Texture)value); } else { MatParam val = getParam(name); if (val == null) { MatParam paramDef = def.getMaterialParam(name); paramValues.put(name, new MatParam(type, name, value)); } else { val.setValue(value); } if (technique != null) { technique.notifyParamChanged(name, type, value); } } }
for (int i = 0; i < paramValues.size(); i++) { MatParam param = paramValues.getValue(i); if (!param.getVarType().isTextureType()) { continue;
private int updateShaderMaterialParameters(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> worldOverrides, SafeArrayList<MatParamOverride> forcedOverrides) { int unit = 0; if (worldOverrides != null) { unit = applyOverrides(renderer, shader, worldOverrides, unit); } if (forcedOverrides != null) { unit = applyOverrides(renderer, shader, forcedOverrides, unit); } for (int i = 0; i < paramValues.size(); i++) { MatParam param = paramValues.getValue(i); VarType type = param.getVarType(); Uniform uniform = shader.getUniform(param.getPrefixedName()); if (uniform.isSetByCurrentMaterial()) { continue; } if (type.isTextureType()) { renderer.setTexture(unit, (Texture) param.getValue()); uniform.setValue(VarType.Int, unit); unit++; } else { uniform.setValue(type, param.getValue()); } } //TODO HACKY HACK remove this when texture unit is handled by the uniform. return unit; }
private int applyOverrides(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> overrides, int unit) { for (MatParamOverride override : overrides.getArray()) { VarType type = override.getVarType(); MatParam paramDef = def.getMaterialParam(override.getName()); if (paramDef == null || paramDef.getVarType() != type || !override.isEnabled()) { continue; } Uniform uniform = shader.getUniform(override.getPrefixedName()); if (override.getValue() != null) { if (type.isTextureType()) { renderer.setTexture(unit, (Texture) override.getValue()); uniform.setValue(VarType.Int, unit); unit++; } else { uniform.setValue(type, override.getValue()); } } else { uniform.clearValue(); } } return unit; }