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; }
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(); worldNormalMatrix.transposeLocal(); u.setValue(VarType.Matrix3, worldNormalMatrix);
private Uniform uniform(String name, VarType type, Object value) { Uniform u = new Uniform(); u.setName("m_" + name); u.setValue(type, value); return u; }
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; }
ambientColor.setValue(VarType.Vector4, ambientLightColor); isFirstLight = false; isSecondLight = true; } else if (isSecondLight) { ambientColor.setValue(VarType.Vector4, ColorRGBA.Black); tmpLightColor.set(color); tmpLightColor.a = l.getType().getId(); lightColor.setValue(VarType.Vector4, tmpLightColor); lightPos.setValue(VarType.Vector4, tmpLightPosition); tmpLightDirection.set(0, 0, 0, 0); lightDir.setValue(VarType.Vector4, tmpLightDirection); break; case Point: lightPos.setValue(VarType.Vector4, tmpLightPosition); tmpLightDirection.set(0, 0, 0, 0); lightDir.setValue(VarType.Vector4, tmpLightDirection); break; case Spot: lightPos.setValue(VarType.Vector4, tmpLightPosition); lightDir.setValue(VarType.Vector4, tmpLightDirection); ambientColor.setValue(VarType.Vector4, getAmbientColor(lights, false, ambientLightColor)); lightColor.setValue(VarType.Vector4, ColorRGBA.BlackNoAlpha); lightPos.setValue(VarType.Vector4, NULL_DIR_LIGHT);
private void updateLightListUniforms(Matrix4f viewMatrix, Shader shader, LightList lights) { Uniform ambientColor = shader.getUniform("g_AmbientLightColor"); ambientColor.setValue(VarType.Vector4, getAmbientColor(lights, true, ambientLightColor));
void updateUniformParam(String paramName, VarType type, Object value, boolean ifNotOwner) { Uniform u = shader.getUniform(paramName); // if (ifNotOwner && u.getLastChanger() == owner) // return; switch (type) { case Texture2D: // fall intentional case Texture3D: case TextureArray: case TextureCubeMap: case Int: u.setValue(VarType.Int, value); break; default: u.setValue(type, value); break; } // u.setLastChanger(owner); } void updateUniformParam(int paramIndex, VarType type, Object value, boolean ifNotOwner) {
void updateUniformParam(int paramIndex, VarType type, Object value, boolean ifNotOwner) { Uniform u = uniformArray[paramIndex]; if (u == null) { u = shader.getUniform(paramValues.getValue(paramIndex).getPrefixedName()); uniformArray[paramIndex] = u; } // if (ifNotOwner && u.getLastChanger() == owner) // return; switch (type) { case Texture2D: // fall intentional case Texture3D: case TextureArray: case TextureCubeMap: case Int: u.setValue(VarType.Int, value); break; default: u.setValue(type, value); break; } // u.setLastChanger(owner); }
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);
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; }
ambientColor.setValue(VarType.Vector4, ambientLightColor); isFirstLight = false; isSecondLight = true; } else if (isSecondLight) { ambientColor.setValue(VarType.Vector4, ColorRGBA.Black); tmpLightColor.set(color); tmpLightColor.a = l.getType().getId(); lightColor.setValue(VarType.Vector4, tmpLightColor); lightPos.setValue(VarType.Vector4, tmpLightPosition); tmpLightDirection.set(0, 0, 0, 0); lightDir.setValue(VarType.Vector4, tmpLightDirection); break; case Point: lightPos.setValue(VarType.Vector4, tmpLightPosition); tmpLightDirection.set(0, 0, 0, 0); lightDir.setValue(VarType.Vector4, tmpLightDirection); break; case Spot: lightPos.setValue(VarType.Vector4, tmpLightPosition); lightDir.setValue(VarType.Vector4, tmpLightDirection); ambientColor.setValue(VarType.Vector4, getAmbientColor(lights, false, ambientLightColor)); lightColor.setValue(VarType.Vector4, ColorRGBA.BlackNoAlpha); lightPos.setValue(VarType.Vector4, NULL_DIR_LIGHT);
ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList)); isFirstLight = false; isSecondLight = true; } else if (isSecondLight) { ambientColor.setValue(VarType.Vector4, ColorRGBA.Black); tmpLightColor.set(color); tmpLightColor.a = l.getType().getId(); lightColor.setValue(VarType.Vector4, tmpLightColor); lightPos.setValue(VarType.Vector4, tmpLightPosition); tmpLightDirection.set(0, 0, 0, 0); lightDir.setValue(VarType.Vector4, tmpLightDirection); break; case Point: lightPos.setValue(VarType.Vector4, tmpLightPosition); tmpLightDirection.set(0, 0, 0, 0); lightDir.setValue(VarType.Vector4, tmpLightDirection); break; case Spot: lightPos.setValue(VarType.Vector4, tmpLightPosition); lightDir.setValue(VarType.Vector4, tmpLightDirection); ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList)); lightColor.setValue(VarType.Vector4, ColorRGBA.BlackNoAlpha); lightPos.setValue(VarType.Vector4, nullDirLight);
private void updateLightListUniforms(Matrix4f viewMatrix, Shader shader, LightList lights) { Uniform ambientColor = shader.getUniform("g_AmbientLightColor"); ambientColor.setValue(VarType.Vector4, getAmbientColor(lights, true, ambientLightColor));
ambientColor.setValue(VarType.Vector4, ColorRGBA.Black); }else{ lightProbe = extractIndirectLights(lightList,true); ambientColor.setValue(VarType.Vector4, ambientLightColor); BoundingSphere s = (BoundingSphere)lightProbe.getBounds(); lightProbeData.setVector4InArray(lightProbe.getPosition().x, lightProbe.getPosition().y, lightProbe.getPosition().z, 1f / s.getRadius() + lightProbe.getNbMipMaps(), 0); shCoeffs.setValue(VarType.Vector3Array, lightProbe.getShCoeffs()); lightProbePemMap.setValue(VarType.Int, pemUnit); } else {
ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));