-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
In-pass shadows (WIP) #723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several remarks:
1- Don't you have a Test class to see the usage and well... test it.
2- It's seems that inpass shadows use a different technique and techniqueDefLogic so how could I combine them with the PBR shader?
3- It seems there is 1 shadow renderer by light type is that correct?
4- Could be nice that you explain the whole principle in a short summary.
|
private void updateRenderState(RenderManager renderManager, Renderer renderer, TechniqueDef techniqueDef) { | ||
if (renderManager.getForcedRenderState() != null) { | ||
renderer.applyRenderState(renderManager.getForcedRenderState()); | ||
if (techniqueDef.getForcedRenderState() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could break compatibility... I think it fixes a bug, or changes behavior
|
||
protected float encodeLightType(Light light) { | ||
switch (light.getType()) { | ||
case Directional: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, this breaks any custom lighting shaders
import com.jme3.texture.TextureArray; | ||
import java.util.EnumSet; | ||
|
||
public class ShadowStaticPassLightingLogic extends StaticPassLightingLogic { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static pass should probably be removed. It doesn't add any value now
return super.makeCurrent(assetManager, renderManager, rendererCaps, lights, defines); | ||
ambientLightColor.a = 1.0f; | ||
|
||
filteredLightList.sort(new Comparator<Light>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should refactor this comparator to avoid allocation
* @author Kirill Vainer | ||
*/ | ||
public final class StaticPassLightingLogic extends DefaultTechniqueDefLogic { | ||
public class StaticPassLightingLogic extends DefaultTechniqueDefLogic { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
* | ||
* @author Kirill Vainer | ||
*/ | ||
public class PreShadowRenderer implements SceneProcessor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a test... TestInPassShadows
uses the regular PreShadowArrayRenderer
* | ||
* @author Kirill Vainer | ||
*/ | ||
final class ShadowDebugControl extends AbstractControl { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be used by the test
/** | ||
* @author Kirill Vainer | ||
*/ | ||
public interface ShadowParameters { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DirectionalShadowParameters implement it... not sure why it's needed though.
There is no other type of Shadow parameter and directional parameters are used with the type DirectionalShadowParameters So this interface is IMO useless. I'll remove it if you agree.
super(array, layer, textureSize, true); | ||
} | ||
|
||
private static boolean isParallelToYUp(Vector3f direction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be used for directional lights too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, done.
@Override | ||
public Matrix4f getBiasedViewProjectionMatrix() { | ||
// return shadowCamera.getViewProjectionMatrix(); | ||
throw new UnsupportedOperationException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
} | ||
|
||
public void setNumSplits(int numSplits) { | ||
// TODO: ensure it is 1 to 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a check here
lightDir.w = clamp(lightDir.w, 1.0 - posLight, 1.0); | ||
#else | ||
lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0); | ||
lightDir.w = 1.0; // clamp(1.0 - position.w * dist * posLight, 0.0, 1.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this
…. Also addressed some comments on the PR
What is the state of this one btw? is this still alive? |
@empirephoenix |
This is the PR implementing in-pass shadows as shown in the April 2016 screenshot thread:
https://hub.jmonkeyengine.org/t/april-2016-monthly-wip-screenshot-thread/35512/128
How it works:
PreShadowArrayRenderer
is responsible for generating a texture array containing shadow maps for every light that should be shadowed. Directional lights use PSSM with 1-4 slices, spot lights use 1 slice, and point lights will use 6 slices (not implemented yet). The information of which texture array to use and the slices is represented in theShadowMap
interface. This is then associated with the light so that later it can be retrieved.When the scene is rendered,
ShadowStaticPassLightingLogic
is theTechniqueDefLogic
implementation that is capable of rendering in-pass shadows. The light types are statically known which allows the shader to avoid control flow. It works similarly toSinglePass
, except that the lights are first sorted by type and then their counts are known statically, so instead of this loop:It becomes
This then allows using different logic depending on the light type. The way shadow maps are fetched varies depending on the type of light, which is why this is required.
Theoretically, if we have control flow in the shader then we don't need to know the light type in advance and we can calculate the slice to fetch per each light. This is probably how in-pass shadows will be integrated with the rest of the lighting shaders.
TODO:
ShadowUtil
Optional: