Problems with shadows (visible where they shouldn't and a little bit ugly)

Hi guys,



at the moment I am trying to get some nice shadows. I followed the examples I have found and ended up with that result:





I have just three simple boxes that have a SimpleTextured (set to m_ColorMap). All those boxes have set their shadow mode to RenderQueue.ShadowMode.CastAndRecieve



There are two issues:

  • Wrong shadow fragments: There are fragments visible on the panels. Those fragments are only visible sometimes (depending on the rotation). Any ideas how I could get rid of those?
  • Not-so-beautiful shadows. The border of the shadows are not too nice. Anything I could do about this?
1 Like

Hi

could you provide a test case please, it seems there is something wrong indeed.



For the shadow edges, for now they are just smoothed by a 4x4 PCF filtering or a dithering filter, thats why they are a bit jagged.

We are planning to implement soft shadow edges.

What can be done about this :

  • wait…we’ll eventually implement it at some point
  • jump in and implement soft shadows. the options are Variance shadow maps, wide kernel pcf filtering on shadow edges using silhouette map, jittered shadow edges… It’s not trivial though, and we need to find a suitable solution for JME3.

Thanks for your answer. Test case:



[java]import com.jme3.app.SimpleApplication;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.queue.RenderQueue;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.shadow.BasicShadowRenderer;

import org.jetbrains.annotations.NotNull;



/**

  • @author Johannes Schneider (js@cedarsoft.com)

    */

    public class ShadowTest extends SimpleApplication {

    public static void main( String[] args ) {

    ShadowTest app = new ShadowTest();

    app.start();

    }



    @Override

    public void simpleInitApp() {

    DirectionalLight sun = new DirectionalLight();

    sun.setDirection( new Vector3f( -1f, -0.7f, -0.0f ) );

    rootNode.addLight( sun );



    BasicShadowRenderer shadowRenderer = new BasicShadowRenderer( assetManager, 1024 );

    shadowRenderer.setDirection( sun.getDirection() );

    viewPort.addProcessor( shadowRenderer );



    rootNode.setShadowMode( RenderQueue.ShadowMode.Off );





    //The box

    {

    Geometry box = new Geometry( “box”, new Box( new Vector3f( 0, 0, 0 ), 1, 2, 3 ) );

    box.setShadowMode( RenderQueue.ShadowMode.CastAndRecieve );

    setColor( box, ColorRGBA.Blue );

    rootNode.attachChild( box );

    }



    //the floor

    {

    Geometry floor = new Geometry( “floor”, new Box( new Vector3f( -100, -5, -100 ), new Vector3f( 100, -5.1f, 100 ) ) );

    floor.setShadowMode( RenderQueue.ShadowMode.CastAndRecieve );

    setColor( floor, ColorRGBA.LightGray );

    rootNode.attachChild( floor );

    }

    }





    public void setColor( @NotNull Geometry geometry, @NotNull ColorRGBA color ) {

    final Material material = new Material( assetManager, “Common/MatDefs/Misc/SolidColor.j3md” );

    material.setColor( “m_Color”, color );

    geometry.setMaterial( material );

    }

    }

    [/java]



    Implementing shadow on my own: At the moment I don’t have enough knowledge in that field. So I have to wait until some more talented guy steps in…

Oh you are using the BasicShadowRenderer?

Could you test with the PssmShadowRenderer? the usage is pretty much the same but you have to specify a number of splits (I suggest 3 for your scene)



I’ll look into this issue tonight

I will try that.



I have tried the code above with the latest nightly build. And it looks a little bit different…

The PssmShadowRenderer does not work at all (no shadow visible):



INFO: Child (floor) attached to this node (Root Node)

Oct 11, 2010 5:29:07 PM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

WARNING: Uniform g_WorldViewMatrix is not declared in shader.

Oct 11, 2010 5:29:07 PM com.jme3.renderer.lwjgl.LwjglRenderer updateShaderData

WARNING: shader link failure.

Fragment info


0(48) : error C5041: cannot locate suitable resource to bind parameter "shadowPosition"

[java]package com.cedarsoft.monkey;

import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.shadow.PssmShadowRenderer;
import org.jetbrains.annotations.NotNull;

/**
* @author Johannes Schneider (js@cedarsoft.com)
*/
public class ShadowTest extends SimpleApplication {
public static void main( String[] args ) {
ShadowTest app = new ShadowTest();
app.start();
}

@Override
public void simpleInitApp() {
DirectionalLight sun = new DirectionalLight();
sun.setDirection( new Vector3f( -1f, -0.7f, -0.0f ) );
rootNode.addLight( sun );

PssmShadowRenderer shadowRenderer = new PssmShadowRenderer( assetManager, 512, 3 );
shadowRenderer.setDirection( sun.getDirection() );
viewPort.addProcessor( shadowRenderer );

rootNode.setShadowMode( RenderQueue.ShadowMode.Off );


//The box
{
Geometry box = new Geometry( "box", new Box( new Vector3f( 0, 0, 0 ), 1, 2, 3 ) );
box.setShadowMode( RenderQueue.ShadowMode.CastAndReceive );
setColor( box, ColorRGBA.Blue );
rootNode.attachChild( box );
}

//the floor
{
Geometry floor = new Geometry( "floor", new Box( new Vector3f( -100, -5, -100 ), new Vector3f( 100, -5.1f, 100 ) ) );
floor.setShadowMode( RenderQueue.ShadowMode.CastAndReceive );
setColor( floor, ColorRGBA.LightGray );
rootNode.attachChild( floor );
}
}


public void setColor( @NotNull Geometry geometry, @NotNull ColorRGBA color ) {
final Material material = new Material( assetManager, "Common/MatDefs/Misc/SolidColor.j3md" );
material.setColor( "m_Color", color );
geometry.setMaterial( material );
}
}
[/java]

There is nothing abnormal about the first test…it’s just ugly :stuck_out_tongue:

But nothing similar to your screenshot, the banding on your solar panels should not be there.



For the Pssm, it’s working fine on my computer. What computer/Os/video card/opengl version so you use?

Ubuntu 10.04:



I think I will update to 10.10 within the next days. Maybe the problem is solved then…





Linux moria 2.6.32-25-generic #44-Ubuntu SMP Fri Sep 17 20:05:27 UTC 2010 x86_64 GNU/Linux

Intel® Core™2 Quad CPU Q6600 @ 2.40GHz



01:00.0 VGA compatible controller: nVidia Corporation G73 [GeForce 7600 GT] (rev a1)



java version “1.6.0_20”

Java™ SE Runtime Environment (build 1.6.0_20-b02)

Java HotSpot™ 64-Bit Server VM (build 16.3-b01, mixed mode)



GL_VERSION: 2.1.2 NVIDIA 195.36.24

GL_VENDOR: NVIDIA Corporation

GL_RENDERER: GeForce 7600 GT/PCI/SSE2





glxinfo:

name of display: :0.0

display: :0 screen: 0

direct rendering: Yes

server glx vendor string: NVIDIA Corporation

server glx version string: 1.4

server glx extensions:

GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_SGIX_fbconfig,

GLX_SGIX_pbuffer, GLX_SGI_video_sync, GLX_SGI_swap_control,

GLX_EXT_swap_control, GLX_EXT_texture_from_pixmap, GLX_ARB_create_context,

GLX_ARB_create_context_profile, GLX_ARB_multisample, GLX_NV_float_buffer,

GLX_ARB_fbconfig_float

client glx vendor string: NVIDIA Corporation

client glx version string: 1.4

client glx extensions:

GLX_ARB_get_proc_address, GLX_ARB_multisample, GLX_EXT_visual_info,

GLX_EXT_visual_rating, GLX_EXT_import_context, GLX_SGI_video_sync,

GLX_NV_swap_group, GLX_NV_video_out, GLX_SGIX_fbconfig, GLX_SGIX_pbuffer,

GLX_SGI_swap_control, GLX_EXT_swap_control, GLX_ARB_create_context,

GLX_ARB_create_context_profile, GLX_NV_float_buffer,

GLX_ARB_fbconfig_float, GLX_EXT_fbconfig_packed_float,

GLX_EXT_texture_from_pixmap, GLX_EXT_framebuffer_sRGB,

GLX_NV_present_video, GLX_NV_copy_image, GLX_NV_multisample_coverage,

GLX_NV_video_capture

GLX version: 1.4

GLX extensions:

GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_SGIX_fbconfig,

GLX_SGIX_pbuffer, GLX_SGI_video_sync, GLX_SGI_swap_control,

GLX_EXT_swap_control, GLX_EXT_texture_from_pixmap, GLX_ARB_create_context,

GLX_ARB_create_context_profile, GLX_ARB_multisample, GLX_NV_float_buffer,

GLX_ARB_fbconfig_float, GLX_ARB_get_proc_address

OpenGL vendor string: NVIDIA Corporation

OpenGL renderer string: GeForce 7600 GT/PCI/SSE2

OpenGL version string: 2.1.2 NVIDIA 195.36.24

OpenGL shading language version string: 1.20 NVIDIA via Cg compiler

OpenGL extensions:

GL_ARB_color_buffer_float, GL_ARB_copy_buffer, GL_ARB_depth_clamp,

GL_ARB_depth_texture, GL_ARB_draw_buffers, GL_ARB_fragment_program,

GL_ARB_fragment_program_shadow, GL_ARB_fragment_shader,

GL_ARB_framebuffer_object, GL_ARB_half_float_pixel,

GL_ARB_half_float_vertex, GL_ARB_imaging, GL_ARB_map_buffer_range,

GL_ARB_multisample, GL_ARB_multitexture, GL_ARB_occlusion_query,

GL_ARB_pixel_buffer_object, GL_ARB_point_parameters, GL_ARB_point_sprite,

GL_ARB_provoking_vertex, GL_ARB_shader_objects,

GL_ARB_shading_language_100, GL_ARB_shadow, GL_ARB_texture_border_clamp,

GL_ARB_texture_compression, GL_ARB_texture_cube_map,

GL_ARB_texture_env_add, GL_ARB_texture_env_combine,

GL_ARB_texture_env_crossbar, GL_ARB_texture_env_dot3,

GL_ARB_texture_float, GL_ARB_texture_mirrored_repeat,

GL_ARB_texture_non_power_of_two, GL_ARB_texture_rectangle,

GL_ARB_transpose_matrix, GL_ARB_vertex_array_bgra,

GL_ARB_vertex_array_object, GL_ARB_vertex_buffer_object,

GL_ARB_vertex_program, GL_ARB_vertex_shader, GL_ARB_window_pos,

GL_ATI_draw_buffers, GL_ATI_texture_float, GL_ATI_texture_mirror_once,

GL_S3_s3tc, GL_EXT_texture_env_add, GL_EXT_abgr, GL_EXT_bgra,

GL_EXT_blend_color, GL_EXT_blend_equation_separate,

GL_EXT_blend_func_separate, GL_EXT_blend_minmax, GL_EXT_blend_subtract,

GL_EXT_compiled_vertex_array, GL_EXT_Cg_shader, GL_EXT_depth_bounds_test,

GL_EXT_direct_state_access, GL_EXT_draw_range_elements, GL_EXT_fog_coord,

GL_EXT_framebuffer_blit, GL_EXT_framebuffer_multisample,

GL_EXT_framebuffer_object, GL_EXT_gpu_program_parameters,

GL_EXT_multi_draw_arrays, GL_EXT_packed_depth_stencil,

GL_EXT_packed_pixels, GL_EXT_pixel_buffer_object, GL_EXT_point_parameters,

GL_EXT_provoking_vertex, GL_EXT_rescale_normal, GL_EXT_secondary_color,

GL_EXT_separate_shader_objects, GL_EXT_separate_specular_color,

GL_EXT_shadow_funcs, GL_EXT_stencil_two_side, GL_EXT_stencil_wrap,

GL_EXT_texture3D, GL_EXT_texture_compression_s3tc,

GL_EXT_texture_cube_map, GL_EXT_texture_edge_clamp,

GL_EXT_texture_env_combine, GL_EXT_texture_env_dot3,

GL_EXT_texture_filter_anisotropic, GL_EXT_texture_lod,

GL_EXT_texture_lod_bias, GL_EXT_texture_mirror_clamp,

GL_EXT_texture_object, GL_EXT_texture_sRGB, GL_EXT_texture_swizzle,

GL_EXT_timer_query, GL_EXT_vertex_array, GL_EXT_vertex_array_bgra,

GL_IBM_rasterpos_clip, GL_IBM_texture_mirrored_repeat,

GL_KTX_buffer_region, GL_NV_blend_square, GL_NV_copy_depth_to_color,

GL_NV_depth_clamp, GL_NV_fence, GL_NV_float_buffer, GL_NV_fog_distance,

GL_NV_fragment_program, GL_NV_fragment_program_option,

GL_NV_fragment_program2, GL_NV_framebuffer_multisample_coverage,

GL_NV_half_float, GL_NV_light_max_exponent, GL_NV_multisample_filter_hint,

GL_NV_occlusion_query, GL_NV_packed_depth_stencil, GL_NV_pixel_data_range,

GL_NV_point_sprite, GL_NV_primitive_restart, GL_NV_register_combiners,

GL_NV_register_combiners2, GL_NV_texgen_reflection, GL_NV_texture_barrier,

GL_NV_texture_compression_vtc, GL_NV_texture_env_combine4,

GL_NV_texture_expand_normal, GL_NV_texture_rectangle,

GL_NV_texture_shader, GL_NV_texture_shader2, GL_NV_texture_shader3,

GL_NV_vertex_array_range, GL_NV_vertex_array_range2, GL_NV_vertex_program,

GL_NV_vertex_program1_1, GL_NV_vertex_program2,

GL_NV_vertex_program2_option, GL_NV_vertex_program3,

GL_NVX_conditional_render, GL_SGIS_generate_mipmap, GL_SGIS_texture_lod,

GL_SGIX_depth_texture, GL_SGIX_shadow, GL_SUN_slice_accum

Upgraded to Ubuntu 10.10. Same problem…

I’ve got a similar problem:



Image and video hosting by TinyPic



PssmShadowRenderer(mapsize 512, nbsplits 3) on a lighting material.

Graphic card is a Geforce GTX285

This is not the same issue, this is a bug i though i fixed :frowning:

Would you mind giving me this test case please?

I have upgraded my graphics card (to 450 GTS). Now the error has gone.



The PSSMShadow now at least has some visible effects. But they seems to be some problems, too:







Any hints?

ok…is there a chance you have a big quad outside of the camera view that is shadowing the whole scene?



i guess not… :frowning:



How many splits do you use?

No. Just the sky, the floor and those panels…

The shadow moves depending on the view point…

nehon said:
This is not the same issue, this is a bug i though i fixed :(
Would you mind giving me this test case please?


Ok, here's test code for you:

[java]package jme3test.texture;

import com.jme3.app.SimpleApplication;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.shadow.PssmShadowRenderer;

public class TestPssmRendering extends SimpleApplication {
@Override
public void simpleInitApp() {
Material whiteMat = new Material(assetManager,
"Common/MatDefs/Light/Lighting.j3md");

whiteMat.setFloat("m_Shininess", 0.1f);
whiteMat.setBoolean("m_UseMaterialColors", true);
whiteMat.setColor("m_Ambient", ColorRGBA.Black);
whiteMat.setColor("m_Diffuse", new ColorRGBA(.5f, .5f, .5f, 1f));
whiteMat.setColor("m_Specular", ColorRGBA.White);
whiteMat.setReceivesShadows(true);

whiteMat.setBoolean("m_VTangent", true);

Geometry geo = new Geometry("floor", new Box(new Vector3f(-10, 0, -10),
new Vector3f(10, 0f, 10)));
geo.setMaterial(whiteMat);
rootNode.attachChild(geo);

PointLight pl = new PointLight();
pl.setPosition(new Vector3f(7, 2, 3));
pl.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.4f));
pl.setRadius(0f);

rootNode.addLight(pl);

Material teapotMat = new Material(assetManager,
"Common/MatDefs/Light/Lighting.j3md");
teapotMat.setFloat("m_Shininess", 0.9f);
teapotMat.setBoolean("m_UseMaterialColors", true);
teapotMat.setBoolean("m_UseAlpha", false);
teapotMat.setColor("m_Ambient", ColorRGBA.Black);
teapotMat.setColor("m_Diffuse", new ColorRGBA(1f, 0f, 0f, 1f));
teapotMat.setColor("m_Specular", ColorRGBA.Gray);

Mesh b = new Sphere(20, 20, 1f);

geo = new Geometry("Object", b);
geo.setMaterial(teapotMat);
geo.setShadowMode(ShadowMode.CastAndReceive);
geo.setLocalTranslation(0, 1, 0);
rootNode.attachChild(geo);

rootNode.setShadowMode(ShadowMode.Receive);

cam.setLocation(new Vector3f(3, 2, 5));
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
cam.setFrustumPerspective(45f, (float) cam.getWidth() / cam.getHeight(),
1f, 1000f);
cam.update();

Vector3f shadowDir = new Vector3f(7, 2, 3).negate().normalizeLocal();
PssmShadowRenderer bsr = new PssmShadowRenderer(assetManager, 512, 3);
bsr.setDirection(shadowDir);
bsr.setShadowIntensity(.3f);
bsr.setLambda(.2f);
viewPort.addProcessor(bsr);
}

public static void main(String[] args) {
new TestPssmRendering().start();
}
}
[/java]

@3H ok check last SVN it Should be better

@jschneider i’m looking into your issue, i don’t forget you

nehon said:
@3H ok check last SVN it Should be better


Yes, it's much better now, thank you. :)
I got another problem: When I change the direction of the shadow, it is only updated on the next render loop. This occurs when I add a shadow processor to a running scene and change the direction. The first rendering shows the old direction. :(
3H said:
I got another problem: When I change the direction of the shadow, it is only updated on the next render loop. This occurs when I add a shadow processor to a running scene and change the direction. The first rendering shows the old direction. :(

Seems like this ties in with the "wandering" shadows in the beginning of the BrickWallTest, huh?

Maybe, but in TestBrickWall, there’s a BasicShadowRenderer used.

The shadow renderes use the same infrastructure