StaticPass supports setting shadow map index on light
This commit is contained in:
parent
cfcec44b9a
commit
42051b045b
@ -57,23 +57,29 @@ import java.util.EnumSet;
|
|||||||
*
|
*
|
||||||
* @author Kirill Vainer
|
* @author Kirill Vainer
|
||||||
*/
|
*/
|
||||||
public final class StaticPassLightingLogic extends DefaultTechniqueDefLogic {
|
public class StaticPassLightingLogic extends DefaultTechniqueDefLogic {
|
||||||
|
|
||||||
private static final String DEFINE_NUM_DIR_LIGHTS = "NUM_DIR_LIGHTS";
|
protected static final String DEFINE_NUM_DIR_LIGHTS = "NUM_DIR_LIGHTS";
|
||||||
private static final String DEFINE_NUM_POINT_LIGHTS = "NUM_POINT_LIGHTS";
|
protected static final String DEFINE_NUM_POINT_LIGHTS = "NUM_POINT_LIGHTS";
|
||||||
private static final String DEFINE_NUM_SPOT_LIGHTS = "NUM_SPOT_LIGHTS";
|
protected static final String DEFINE_NUM_SPOT_LIGHTS = "NUM_SPOT_LIGHTS";
|
||||||
|
|
||||||
private final int numDirLightsDefineId;
|
protected final int numDirLightsDefineId;
|
||||||
private final int numPointLightsDefineId;
|
protected final int numPointLightsDefineId;
|
||||||
private final int numSpotLightsDefineId;
|
protected final int numSpotLightsDefineId;
|
||||||
|
|
||||||
private final ArrayList<DirectionalLight> tempDirLights = new ArrayList<DirectionalLight>();
|
protected final ColorRGBA ambientLightColor = new ColorRGBA(0, 0, 0, 1);
|
||||||
private final ArrayList<PointLight> tempPointLights = new ArrayList<PointLight>();
|
protected final Vector3f tempPosition = new Vector3f();
|
||||||
private final ArrayList<SpotLight> tempSpotLights = new ArrayList<SpotLight>();
|
protected final Vector3f tempDirection = new Vector3f();
|
||||||
|
|
||||||
private final ColorRGBA ambientLightColor = new ColorRGBA(0, 0, 0, 1);
|
protected final ArrayList<DirectionalLight> tempDirLights = new ArrayList<>();
|
||||||
private final Vector3f tempPosition = new Vector3f();
|
protected final ArrayList<PointLight> tempPointLights = new ArrayList<>();
|
||||||
private final Vector3f tempDirection = new Vector3f();
|
protected final ArrayList<SpotLight> tempSpotLights = new ArrayList<>();
|
||||||
|
|
||||||
|
protected static final Matrix4f BIAS_MATRIX = new Matrix4f(
|
||||||
|
0.5f, 0.0f, 0.0f, 0.5f,
|
||||||
|
0.0f, 0.5f, 0.0f, 0.5f,
|
||||||
|
0.0f, 0.0f, 0.5f, 0.5f,
|
||||||
|
0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
public StaticPassLightingLogic(TechniqueDef techniqueDef) {
|
public StaticPassLightingLogic(TechniqueDef techniqueDef) {
|
||||||
super(techniqueDef);
|
super(techniqueDef);
|
||||||
@ -83,8 +89,7 @@ public final class StaticPassLightingLogic extends DefaultTechniqueDefLogic {
|
|||||||
numSpotLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NUM_SPOT_LIGHTS, VarType.Int);
|
numSpotLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NUM_SPOT_LIGHTS, VarType.Int);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected void makeCurrentBase(AssetManager assetManager, RenderManager renderManager,
|
||||||
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
|
|
||||||
EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {
|
EnumSet<Caps> rendererCaps, LightList lights, DefineList defines) {
|
||||||
|
|
||||||
// TODO: if it ever changes that render isn't called
|
// TODO: if it ever changes that render isn't called
|
||||||
@ -94,6 +99,8 @@ public final class StaticPassLightingLogic extends DefaultTechniqueDefLogic {
|
|||||||
tempDirLights.clear();
|
tempDirLights.clear();
|
||||||
tempPointLights.clear();
|
tempPointLights.clear();
|
||||||
tempSpotLights.clear();
|
tempSpotLights.clear();
|
||||||
|
ambientLightColor.set(0, 0, 0, 1);
|
||||||
|
|
||||||
for (Light light : lights) {
|
for (Light light : lights) {
|
||||||
switch (light.getType()) {
|
switch (light.getType()) {
|
||||||
case Directional:
|
case Directional:
|
||||||
@ -105,27 +112,41 @@ public final class StaticPassLightingLogic extends DefaultTechniqueDefLogic {
|
|||||||
case Spot:
|
case Spot:
|
||||||
tempSpotLights.add((SpotLight) light);
|
tempSpotLights.add((SpotLight) light);
|
||||||
break;
|
break;
|
||||||
|
case Ambient:
|
||||||
|
ambientLightColor.addLocal(light.getColor());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ambientLightColor.a = 1.0f;
|
||||||
|
|
||||||
defines.set(numDirLightsDefineId, tempDirLights.size());
|
defines.set(numDirLightsDefineId, tempDirLights.size());
|
||||||
defines.set(numPointLightsDefineId, tempPointLights.size());
|
defines.set(numPointLightsDefineId, tempPointLights.size());
|
||||||
defines.set(numSpotLightsDefineId, tempSpotLights.size());
|
defines.set(numSpotLightsDefineId, tempSpotLights.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
|
||||||
|
EnumSet<Caps> rendererCaps, Geometry geometry, DefineList defines) {
|
||||||
|
LightList lights = getFilteredLightList(renderManager, geometry);
|
||||||
|
makeCurrentBase(assetManager, renderManager, rendererCaps, lights, defines);
|
||||||
return techniqueDef.getShader(assetManager, rendererCaps, defines);
|
return techniqueDef.getShader(assetManager, rendererCaps, defines);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transformDirection(Matrix4f viewMatrix, Vector3f direction) {
|
protected void transformDirection(Matrix4f viewMatrix, Vector3f direction) {
|
||||||
viewMatrix.multNormal(direction, direction);
|
viewMatrix.multNormal(direction, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transformPosition(Matrix4f viewMatrix, Vector3f location) {
|
protected void transformPosition(Matrix4f viewMatrix, Vector3f location) {
|
||||||
viewMatrix.mult(location, location);
|
viewMatrix.mult(location, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLightListUniforms(Matrix4f viewMatrix, Shader shader, LightList lights) {
|
protected float getShadowMapIndex(Light light) {
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateLightListUniforms(Matrix4f viewMatrix, Shader shader) {
|
||||||
Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
|
Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
|
||||||
ambientColor.setValue(VarType.Vector4, getAmbientColor(lights, true, ambientLightColor));
|
ambientColor.setValue(VarType.Vector4, ambientLightColor);
|
||||||
|
|
||||||
Uniform lightData = shader.getUniform("g_LightData");
|
Uniform lightData = shader.getUniform("g_LightData");
|
||||||
|
|
||||||
@ -137,25 +158,26 @@ public final class StaticPassLightingLogic extends DefaultTechniqueDefLogic {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
for (DirectionalLight light : tempDirLights) {
|
for (DirectionalLight light : tempDirLights) {
|
||||||
ColorRGBA color = light.getColor();
|
ColorRGBA color = light.getColor();
|
||||||
|
float shadowMapIndex = getShadowMapIndex(light);
|
||||||
tempDirection.set(light.getDirection());
|
tempDirection.set(light.getDirection());
|
||||||
transformDirection(viewMatrix, tempDirection);
|
transformDirection(viewMatrix, tempDirection);
|
||||||
lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++);
|
lightData.setVector4InArray(color.r, color.g, color.b, shadowMapIndex, index++);
|
||||||
lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, 1f, index++);
|
lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, 1f, index++);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PointLight light : tempPointLights) {
|
for (PointLight light : tempPointLights) {
|
||||||
ColorRGBA color = light.getColor();
|
ColorRGBA color = light.getColor();
|
||||||
|
float shadowMapIndex = getShadowMapIndex(light);
|
||||||
tempPosition.set(light.getPosition());
|
tempPosition.set(light.getPosition());
|
||||||
float invRadius = light.getInvRadius();
|
float invRadius = light.getInvRadius();
|
||||||
transformPosition(viewMatrix, tempPosition);
|
transformPosition(viewMatrix, tempPosition);
|
||||||
lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++);
|
lightData.setVector4InArray(color.r, color.g, color.b, shadowMapIndex, index++);
|
||||||
lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRadius, index++);
|
lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRadius, index++);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SpotLight light : tempSpotLights) {
|
for (SpotLight light : tempSpotLights) {
|
||||||
ColorRGBA color = light.getColor();
|
ColorRGBA color = light.getColor();
|
||||||
Vector3f pos = light.getPosition();
|
float shadowMapIndex = getShadowMapIndex(light);
|
||||||
Vector3f dir = light.getDirection();
|
|
||||||
|
|
||||||
tempPosition.set(light.getPosition());
|
tempPosition.set(light.getPosition());
|
||||||
tempDirection.set(light.getDirection());
|
tempDirection.set(light.getDirection());
|
||||||
@ -164,17 +186,21 @@ public final class StaticPassLightingLogic extends DefaultTechniqueDefLogic {
|
|||||||
|
|
||||||
float invRange = light.getInvSpotRange();
|
float invRange = light.getInvSpotRange();
|
||||||
float spotAngleCos = light.getPackedAngleCos();
|
float spotAngleCos = light.getPackedAngleCos();
|
||||||
lightData.setVector4InArray(color.r, color.g, color.b, 1f, index++);
|
lightData.setVector4InArray(color.r, color.g, color.b, shadowMapIndex, index++);
|
||||||
lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRange, index++);
|
lightData.setVector4InArray(tempPosition.x, tempPosition.y, tempPosition.z, invRange, index++);
|
||||||
lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, spotAngleCos, index++);
|
lightData.setVector4InArray(tempDirection.x, tempDirection.y, tempDirection.z, spotAngleCos, index++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateShadowUniforms(Renderer renderer, Shader shader, int nextTextureUnit) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
|
public void render(RenderManager renderManager, Shader shader, Geometry geometry, int nextTextureUnit) {
|
||||||
Renderer renderer = renderManager.getRenderer();
|
Renderer renderer = renderManager.getRenderer();
|
||||||
Matrix4f viewMatrix = renderManager.getCurrentCamera().getViewMatrix();
|
Matrix4f viewMatrix = renderManager.getCurrentCamera().getViewMatrix();
|
||||||
updateLightListUniforms(viewMatrix, shader, lights);
|
updateLightListUniforms(viewMatrix, shader);
|
||||||
|
updateShadowUniforms(renderer, shader, nextTextureUnit);
|
||||||
renderer.setShader(shader);
|
renderer.setShader(shader);
|
||||||
renderMeshFromGeometry(renderer, geometry);
|
renderMeshFromGeometry(renderer, geometry);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user