Flickering issue with lighting based on direction I'm facing

Hello all,

I have actually had this issue twice now, so I will explain both.

hub.jmonkeyengine.org/wiki/doku.php/jme3:advanced:light_and_shadow

The first was when I was using the DirectionalShadow Filtering from the tutorial and the direction I faced would influence the changing of my walls. I figured this was due to it being “directional” and I assumed it was based on the location of my cam.

[java] DirectionalLight sun = new DirectionalLight();
sun.setColor(ColorRGBA.White);
sun.setDirection(cam.getDirection());
rootNode.addLight(sun);

    /* Drop shadows */
    final int SHADOWMAP_SIZE=1024;
    DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3);
    dlsr.setLight(sun);
    viewPort.addProcessor(dlsr);

    DirectionalLightShadowFilter dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 3);
    dlsf.setLight(sun);
    dlsf.setEnabled(true);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(dlsf);
    viewPort.addProcessor(fpp);[/java]

So now I’m trying out SSAO

[java]FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
SSAOFilter ssaoFilter = new SSAOFilter(12.94f, 43.92f, 0.33f, 0.61f);
fpp.addFilter(ssaoFilter);
viewPort.addProcessor(fpp);[/java]

and it is also flicking. I can take a video or w/e but I want to know why this is happening. I originally had my entire scene built out, but now it’s just my walls(which is the only lighting material), and it’s still happening. I figured I had some piece of code that could be effecting it, but now I’m not too sure.

I looked up and found this thread http://hub.jmonkeyengine.org/forum/topic/ssaofilter-flickering-problem/ which talks about the sample having issues, which I did not find…

I tried editing all of the options but nothing worked really…

Anyone have a clue?

Thanks.

Yes a video would help

@nehon said: Yes a video would help

Will do… I also wanted to ask about “normals” I have a custom mesh for the walls, and I believe I heard something about lighting materials and that “normals” are needed for light to work or something…?

The rest of my scene looks fine, but they are regular boxes and textured boxes… I haven’t looked at the custom meshes with textures though. At first I only had lighting on my walls, but if I changed to unshaded the same thing occurs…

View My Video

For some reason my post was deleted?

@KonradZuse said: For some reason my post was deleted?

Seems it was marked as spam for some reason (as were all of the other responses). Not sure why.

1 Like
@pspeed said: Seems it was marked as spam for some reason (as were all of the other responses). Not sure why.

No clue it was weird. I made my first post, then edited the video in, and then the post was deleted.

I tried to make another post, and it didn’t appear, then tried to redo it again and said “it was already posted.”

I made another post a week later, then it posted. Edited it again with the rest of the info BOOM DELETED again…

Super weird lol…

Does it usually tell you who marks it as spam?

Well, if you are trying to include a video then use the youtube button. Otherwise, I guess don’t include a video.

[video]http://tinypic.com/r/243kaon/8[/video]

Not too sure where I got the url code from, I must have grabbed it directly from their site.

Wondering if you’ve ever heard of FRAPs before.

@pspeed said: Wondering if you've ever heard of FRAPs before.

Lol yeah sorry the quality might be a big funky due to the lighting changes.

I didn’t want to go download fraps and such, wanted to make thsi ez :p.

If it’s a big deal I’ll take the vid again.

Also: http://hub.jmonkeyengine.org/javadoc/com/jme3/app/state/VideoRecorderAppState.html

…and then you don’t even have to download anything.

@pspeed said: Also: http://hub.jmonkeyengine.org/javadoc/com/jme3/app/state/VideoRecorderAppState.html

…and then you don’t even have to download anything.

Yeah I was going to edit before and mention I could use the built in recorder, just need to do a few things to set it up :P.

I can confirm the same issue from one of my tests cases
[video]https://vimeo.com/92138871[/video]

That looks weird :slight_smile: So the next questions are:
How are the models set up? Can there be duplicate vertices, Z-fighting between duplicate faces et.c
Do the models have normals? Are you sure?
What material and how are the material parameters set? Maybe tangents are needed but not calculated.

@jmaasing said: That looks weird :-) So the next questions are: How are the models set up? Can there be duplicate vertices, Z-fighting between duplicate faces et.c Do the models have normals? Are you sure? What material and how are the material parameters set? Maybe tangents are needed but not calculated.

As I told Pspeed I am using custom meshes for each section of my wall. I would normally want to use ONE custom mesh, but for some reason the mesh takes the entire area within itself, so my entire room would be part of that mesh, which causes problems when trying to do collision detection, so I made each wall i’s own mesh.

I need to fix this into something else since my code has somethings I neeed to fix regarding the size of the walls, but I’m not sure about the SSAO.

I did read somewhere that for lights you need “NORMALS” set up, which I have not. EDIT: I noticed you mentioned this as well, maybe I do need it then… I will try them out, I had them up when I was doing “lighting” before doign SSAO and it didn’t do anything(did I have the coordinates wrong)?

The custommesh tutorial doesnt’ go that deep into Normals, I’m assuming I want all the normals to be facing inwards since that’s how my rooms are laid out?

Teencrusher’s example seems to be worse than mine, hopefully it canbe fixed…

Again, I hear lowerign the radius can work, but Id on’t think that’s a legit fix we should be working with.

I would say this is “the important” part of the mesh code qwhich you were askign about above.

[java] m[i].setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices[i]));
m[i].setBuffer(VertexBuffer.Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord[i]));
m[i].setBuffer(VertexBuffer.Type.Index, 1, BufferUtils.createIntBuffer(index));
m[i].updateBound();
// System.out.println(p.point);

            geom[i] = new Geometry("Wall"+i, m[i]);
            geom[i].setLocalScale(ppi);
            mat[i] = new Material(assetManager,    "Common/MatDefs/Misc/Unshaded.j3md");
                           
            mat[i].setTexture("ColorMap", assetManager.loadTexture("/Textures/whiteWall.jpg"));
         //   mat.getAdditionalRenderState().setWireframe(true);
         //  
            geom[i].setMaterial(mat[i]);
            rootNode.attachChild(geom[i]);[/java]

@Op sorry for the late reply, about the question about normals.
Yes normal are mandatory for lighting to work properly and if your mesh doesn’t have normals then don’t look further that’s your issue.

@nehon said: @Op sorry for the late reply, about the question about normals. Yes normal are mandatory for lighting to work properly and if your mesh doesn't have normals then don't look further that's your issue.

No worries, I really wanted to make sure mostly why my stuff wasn’t being posted, Pspeed helped me out so I thank him for that, I could have tried to solve this later issue if need be.

Now there are other “custom mesh” objects in my scene that don’t seem to do this, but I will have to check them out completely since I have to fix them up as well.

I’ll try the normals myself and let you know…

One question

[java]Example: Using Meshes With Lighting.j3md

The previous examples used the mesh together with the Unshaded.j3md material. If you want to use the mesh with a Phong illuminated material (such as Lighting.j3md), the mesh must include information about its Normals. (Normal Vectors encode in which direction a mesh polygon is facing, which is important for calculating light and shadow!)

float[] normals = new float[12];
normals = new float[]{0,0,1, 0,0,1, 0,0,1, 0,0,1};
mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
You need to specify as many normals as the polygon has vertices. For a flat quad, the four normals point in the same direction. In this case, the direction is the Z unit vector (0,0,1), this means our quad is facing the camera.

If the mesh is more complex or rounded, calculate cross products of neighbouring vertices to identify normal vectors!

[/java]

I’m assuming the normals = new float[]{0,0,1, 0,0,1, 0,0,1, 0,0,1}; will work as is? But if we have more than 4 vertices we have to use cross products of “neighboring vertices” what would be the best approach to getting these “neighboring vertices?” It seems we are looking to just find which direction these face.

For each vertex, you will need a normal pointing in the surface direction at that vertex.

Are you asking how to calculate the surface direction? Usually if you are making quads then you already know it. If you are loading from some external format then it will need to supply the normals. There is no correct automated way to generate normals as a general solution unless all you want is flat shading.

@pspeed said: For each vertex, you will need a normal pointing in the surface direction at that vertex.

Are you asking how to calculate the surface direction? Usually if you are making quads then you already know it. If you are loading from some external format then it will need to supply the normals. There is no correct automated way to generate normals as a general solution unless all you want is flat shading.

Just curious how it’s done for things… Like the TESTSSAO

In this situation for my walls I want to shade only the corners in. For some reason the entire wall is being shaded(I’m assuming that’s due to what you mentioned before “flat shading”).

i guess I need to look up more on shading and such.

Also the tutorial in Light and Shadow says “In JME3, SSAO is implemented by adding an instance of com.jme3.post.SSAOFilter to a viewport which already simulates shadows using another method such as DirectionalLightShadowRenderer.”

In TESTSSAO all there is is the SSAO. My code works fine without another shadow also… Is this outdated information or…???

in testSSAO it’s not a custom mesh, the mesh has proper normals.
You don’t need a shadow renderer to have SSAO these are 2 different things.

@nehon said: in testSSAO it's not a custom mesh, the mesh has proper normals. You don't need a shadow renderer to have SSAO these are 2 different things.

I understand, but how is it calculated in the texture? There is also a “normal texture” but when I removed the normal it still showed the correct areas as shaded, just “not as shaded” if that makes sense. As in the radius of the shade was less, but not by much it seemed.

Should all diffusemap textures also come with a normal map texture?

I’m not that familiar with lightning and all these maps, so excuse my level of understanding of them.

It seems like each map it there to help the main texture accomplish something… We basically creates these additional maps around the main one? i.e., bump map we would create the bumps of the texture based on the texture itself in most cases? Shininess, etc? I’m assuming you could use additonal “bumpy” or “shiny” surfaces, they just might not look that good with your texture?

Thanks again everyone!