Java Code Examples for com.jme3.light.LightList#get()
The following examples show how to use
com.jme3.light.LightList#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Material.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
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; }
Example 2
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void setLighting(LightList list) { if (list == null || list.size() == 0) { // turn off lighting gl.glDisable(gl.GL_LIGHTING); return; } gl.glEnable(gl.GL_LIGHTING); gl.glShadeModel(gl.GL_SMOOTH); float[] temp = new float[4]; // reset model view to specify // light positions in world space // instead of model space // gl.glPushMatrix(); // gl.glLoadIdentity(); for (int i = 0; i < list.size() + 1; i++) { int lightId = gl.GL_LIGHT0 + i; if (list.size() <= i) { // goes beyond the num lights we need // disable it gl.glDisable(lightId); break; } Light l = list.get(i); if (!l.isEnabled()) { gl.glDisable(lightId); continue; } ColorRGBA color = l.getColor(); color.toArray(temp); gl.glEnable(lightId); gl.glLightfv(lightId, gl.GL_DIFFUSE, temp, 0); gl.glLightfv(lightId, gl.GL_SPECULAR, temp, 0); ColorRGBA.Black.toArray(temp); gl.glLightfv(lightId, gl.GL_AMBIENT, temp, 0); switch (l.getType()) { case Directional: DirectionalLight dl = (DirectionalLight) l; dl.getDirection().toArray(temp); temp[3] = 0f; // marks to GL its a directional light gl.glLightfv(lightId, gl.GL_POSITION, temp, 0); break; case Point: PointLight pl = (PointLight) l; pl.getPosition().toArray(temp); temp[3] = 1f; // marks to GL its a point light gl.glLightfv(lightId, gl.GL_POSITION, temp, 0); break; } } // restore modelview to original value // gl.glPopMatrix(); }
Example 3
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void setLighting(LightList list) { if (glslVer == -1) { GL gl = GLContext.getCurrentGL(); if (list == null || list.size() == 0) { // turn off lighting gl.glDisable(GLLightingFunc.GL_LIGHTING); return; } gl.glEnable(GLLightingFunc.GL_LIGHTING); gl.getGL2().glShadeModel(GLLightingFunc.GL_SMOOTH); float[] temp = new float[4]; // reset model view to specify // light positions in world space // instead of model space // gl.glPushMatrix(); // gl.glLoadIdentity(); for (int i = 0; i < list.size() + 1; i++) { int lightId = GLLightingFunc.GL_LIGHT0 + i; if (list.size() <= i) { // goes beyond the num lights we need // disable it gl.glDisable(lightId); break; } Light l = list.get(i); if (!l.isEnabled()) { gl.glDisable(lightId); continue; } ColorRGBA color = l.getColor(); color.toArray(temp); gl.glEnable(lightId); gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_DIFFUSE, temp, 0); gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_SPECULAR, temp, 0); ColorRGBA.Black.toArray(temp); gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_AMBIENT, temp, 0); switch (l.getType()) { case Directional: DirectionalLight dl = (DirectionalLight) l; dl.getDirection().toArray(temp); temp[3] = 0f; // marks to GL its a directional light gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_POSITION, temp, 0); break; case Point: PointLight pl = (PointLight) l; pl.getPosition().toArray(temp); temp[3] = 1f; // marks to GL its a point light gl.getGL2().glLightfv(lightId, GLLightingFunc.GL_POSITION, temp, 0); break; } } // restore modelview to original value // gl.glPopMatrix(); } }
Example 4
Source File: Material.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Uploads the lights in the light list as two uniform arrays.<br/><br/> * * <p> * <code>uniform vec4 g_LightColor[numLights];</code><br/> * // g_LightColor.rgb is the diffuse/specular color of the light.<br/> * // g_Lightcolor.a is the type of light, 0 = Directional, 1 = Point, <br/> * // 2 = Spot. <br/> * <br/> * <code>uniform vec4 g_LightPosition[numLights];</code><br/> * // g_LightPosition.xyz is the position of the light (for point lights)<br/> * // or the direction of the light (for directional lights).<br/> * // g_LightPosition.w is the inverse radius (1/r) of the light (for attenuation) <br/> * </p> */ protected void updateLightListUniforms(Shader shader, Geometry g, int numLights) { if (numLights == 0) { // this shader does not do lighting, ignore. return; } LightList lightList = g.getWorldLightList(); Uniform lightColor = shader.getLightColorUniform(); Uniform lightPos = shader.getLightPositionUniform(); Uniform lightDir = shader.getLightDirectionUniform(); lightColor.setVector4Length(numLights); lightPos.setVector4Length(numLights); lightDir.setVector4Length(numLights); Uniform ambientColor = shader.getAmbientColorUniform(); ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList)); int lightIndex = 0; for (int i = 0; i < numLights; i++) { if (lightList.size() <= i) { lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex); lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex); } else { Light l = lightList.get(i); ColorRGBA color = l.getColor(); lightColor.setVector4InArray(color.getRed(), color.getGreen(), color.getBlue(), l.getType().getId(), i); switch (l.getType()) { case Directional: DirectionalLight dl = (DirectionalLight) l; Vector3f dir = dl.getDirection(); lightPos.setVector4InArray(dir.getX(), dir.getY(), dir.getZ(), -1, lightIndex); break; case Point: PointLight pl = (PointLight) l; Vector3f pos = pl.getPosition(); float invRadius = pl.getInvRadius(); lightPos.setVector4InArray(pos.getX(), pos.getY(), pos.getZ(), invRadius, lightIndex); break; case Spot: SpotLight sl = (SpotLight) l; Vector3f pos2 = sl.getPosition(); Vector3f dir2 = sl.getDirection(); float invRange = sl.getInvSpotRange(); float spotAngleCos = sl.getPackedAngleCos(); lightPos.setVector4InArray(pos2.getX(), pos2.getY(), pos2.getZ(), invRange, lightIndex); lightDir.setVector4InArray(dir2.getX(), dir2.getY(), dir2.getZ(), spotAngleCos, lightIndex); break; case Ambient: // skip this light. Does not increase lightIndex continue; default: throw new UnsupportedOperationException("Unknown type of light: " + l.getType()); } } lightIndex++; } while (lightIndex < numLights) { lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex); lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex); lightIndex++; } }