assert uniform.getName() != null; assert shader.getId() > 0; int loc = uniform.getLocation(); if (loc == -1) { return; if (uniform.getLocation() == -1) { uniform.clearUpdateNeeded(); return; loc = uniform.getLocation(); if (uniform.getVarType() == null) { return; // value not set yet.. uniform.clearUpdateNeeded(); FloatBuffer fb; IntBuffer ib; switch (uniform.getVarType()) { case Float: Float f = (Float) uniform.getValue(); gl.glUniform1f(loc, f.floatValue()); break; case Vector2: Vector2f v2 = (Vector2f) uniform.getValue(); gl.glUniform2f(loc, v2.getX(), v2.getY()); break;
protected void resetUniformLocations(Shader shader) { ListMap<String, Uniform> uniforms = shader.getUniformMap(); for (int i = 0; i < uniforms.size(); i++) { Uniform uniform = uniforms.getValue(i); uniform.reset(); // e.g check location again } }
/*********************************************************************\ |* Shaders *| \*********************************************************************/ protected void updateUniformLocation(Shader shader, Uniform uniform) { int loc = gl.glGetUniformLocation(shader.getId(), uniform.getName()); if (loc < 0) { uniform.setLocation(-1); // uniform is not declared in shader logger.log(Level.FINE, "Uniform {0} is not declared in shader {1}.", new Object[]{uniform.getName(), shader.getSources()}); } else { uniform.setLocation(loc); } }
/** * Resets all uniforms that do not have the "set-by-current-material" flag * to their default value (usually all zeroes or false). * When a uniform is modified, that flag is set, to remove the flag, * use {@link #clearUniformsSetByCurrentFlag() }. */ public void resetUniformsNotSetByCurrent() { int size = uniforms.size(); for (int i = 0; i < size; i++) { Uniform u = uniforms.getValue(i); if (!u.isSetByCurrentMaterial()) { u.clearValue(); } } }
private void updateLightListUniforms(Matrix4f viewMatrix, Shader shader, LightList lights) { Uniform ambientColor = shader.getUniform("g_AmbientLightColor"); ambientColor.setValue(VarType.Vector4, getAmbientColor(lights, true, ambientLightColor)); + tempPointLights.size() * 2 + tempSpotLights.size() * 3; lightData.setVector4Length(totalSize); tempDirection.set(light.getDirection()); transformDirection(viewMatrix, tempDirection); lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++); lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, 1f, index++); float invRadius = light.getInvRadius(); transformPosition(viewMatrix, tempPosition); lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++); lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRadius, index++); lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++); lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRange, index++); lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, spotAngleCos, index++);
private void resetUniformsNotSetByCurrent(Shader shader) { ListMap<String, Uniform> uniforms = shader.getUniformMap(); int size = uniforms.size(); for (int i = 0; i < size; i++) { Uniform u = uniforms.getValue(i); if (!u.isSetByCurrentMaterial()) { if (u.getName().charAt(0) != 'g') { // Don't reset world globals! // The benefits gained from this are very minimal // and cause lots of matrix -> FloatBuffer conversions. u.clearValue(); } } } }
for (int i = 0; i < params.size(); i++) { Uniform u = params.get(i); switch (u.getBinding()) { case WorldMatrix: u.setValue(VarType.Matrix4, worldMatrix); break; case ViewMatrix: u.setValue(VarType.Matrix4, viewMatrix); break; case ProjectionMatrix: u.setValue(VarType.Matrix4, projMatrix); break; case ViewProjectionMatrix: u.setValue(VarType.Matrix4, viewProjMatrix); break; case WorldViewMatrix: worldViewMatrix.set(viewMatrix); worldViewMatrix.multLocal(worldMatrix); u.setValue(VarType.Matrix4, worldViewMatrix); break; case NormalMatrix: normalMatrix.invertLocal(); normalMatrix.transposeLocal(); u.setValue(VarType.Matrix3, normalMatrix); break; case WorldNormalMatrix: worldNormalMatrix.invertLocal();
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 (uniform.isSetByCurrentMaterial()) { continue; uniform.setValue(VarType.Int, unit); unit++; } else { uniform.setValue(type, param.getValue());
private int setProbeData(RenderManager rm, int lastTexUnit, Uniform lightProbeData, Uniform shCoeffs, Uniform lightProbePemMap, LightProbe lightProbe) { lightProbeData.setValue(VarType.Matrix4, lightProbe.getUniformMatrix()); //setVector4InArray(lightProbe.getPosition().x, lightProbe.getPosition().y, lightProbe.getPosition().z, 1f / area.getRadius() + lightProbe.getNbMipMaps(), 0); shCoeffs.setValue(VarType.Vector3Array, lightProbe.getShCoeffs()); //assigning new texture indexes int pemUnit = lastTexUnit++; rm.getRenderer().setTexture(pemUnit, lightProbe.getPrefilteredEnvMap()); lightProbePemMap.setValue(VarType.Int, pemUnit); return lastTexUnit; }
public Uniform getUniform(String name){ assert name.startsWith("m_") || name.startsWith("g_"); Uniform uniform = uniforms.get(name); if (uniform == null){ uniform = new Uniform(); uniform.name = name; uniforms.put(name, uniform); } return uniform; }
private void outUniforms(Uniform... uniforms) { if (!evaluated) { evaluateTechniqueDef(); } HashSet<Uniform> actualUniforms = new HashSet<>(); for (Uniform uniform : usedShader.getUniformMap().values()) { if (uniform.getName().startsWith("m_") && !IGNORED_UNIFORMS.contains(uniform.getName())) { actualUniforms.add(uniform); } } HashSet<Uniform> expectedUniforms = new HashSet<>(Arrays.asList(uniforms)); if (!expectedUniforms.equals(actualUniforms)) { Assert.fail("Uniform lists must match: " + expectedUniforms + " != " + actualUniforms); } } }
/** * Removes the "set-by-current-material" flag from all uniforms. * When a uniform is modified after this call, the flag shall * become "set-by-current-material". * A call to {@link #resetUniformsNotSetByCurrent() } will reset * all uniforms that do not have the "set-by-current-material" flag * to their default value (usually all zeroes or false). */ public void clearUniformsSetByCurrentFlag() { int size = uniforms.size(); for (int i = 0; i < size; i++) { Uniform u = uniforms.getValue(i); u.clearSetByCurrentMaterial(); } }
lightData.setVector4Length(numLights * 3);//8 lights * max 3 Uniform ambientColor = shader.getUniform("g_AmbientLightColor"); ambientColor.setValue(VarType.Vector4, ColorRGBA.Black); }else{ extractIndirectLights(lightList,true); ambientColor.setValue(VarType.Vector4, ambientLightColor); lightProbeData.setValue(VarType.Matrix4, LightProbe.FALLBACK_MATRIX); lightData.setVector4InArray(color.getRed(), color.getGreen(), color.getBlue(), lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex); lightDataIndex++; lightData.setVector4InArray(0,0,0,0, lightDataIndex); lightDataIndex++; break; lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex); lightDataIndex++; lightData.setVector4InArray(0,0,0,0, lightDataIndex); lightDataIndex++; break; lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
private void resetUniformsNotSetByCurrent(Shader shader) { ListMap<String, Uniform> uniforms = shader.getUniformMap(); int size = uniforms.size(); for (int i = 0; i < size; i++) { Uniform u = uniforms.getValue(i); if (!u.isSetByCurrentMaterial()) { if (u.getName().charAt(0) != 'g') { // Don't reset world globals! // The benefits gained from this are very minimal // and cause lots of matrix -> FloatBuffer conversions. u.clearValue(); } } } }
/*********************************************************************\ |* Shaders *| \*********************************************************************/ protected void updateUniformLocation(Shader shader, Uniform uniform) { int loc = gl.glGetUniformLocation(shader.getId(), uniform.getName()); if (loc < 0) { uniform.setLocation(-1); // uniform is not declared in shader logger.log(Level.FINE, "Uniform {0} is not declared in shader {1}.", new Object[]{uniform.getName(), shader.getSources()}); } else { uniform.setLocation(loc); } }
switch (u.getBinding()) { case WorldMatrix: u.setValue(VarType.Matrix4, worldMatrixBuf); break; case ViewMatrix: u.setValue(VarType.Matrix4, viewMatrix); break; case ProjectionMatrix: u.setValue(VarType.Matrix4, projMatrixBuf); break; case ViewProjectionMatrix: u.setValue(VarType.Matrix4, viewProjMatrixBuf); break; case WorldViewMatrix: u.setValue(VarType.Matrix4, getWorldViewMatrixBuf()); break; case NormalMatrix: tempMat3.invertLocal(); tempMat3.transposeLocal(); u.setValue(VarType.Matrix3, tempMat3); break; case WorldViewProjectionMatrix: u.setValue(VarType.Matrix4, getWorldViewProjectionMatrixBuf()); break; case WorldMatrixInverse: tempMat4.multLocal(worldMatrix);
/** * Resets all uniforms that do not have the "set-by-current-material" flag * to their default value (usually all zeroes or false). * When a uniform is modified, that flag is set, to remove the flag, * use {@link #clearUniformsSetByCurrent() }. */ public void resetUniformsNotSetByCurrent() { int size = uniforms.size(); for (int i = 0; i < size; i++) { Uniform u = uniforms.getValue(i); if (!u.isSetByCurrentMaterial()) { u.clearValue(); } } }
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; }