Soft Shadows (w/o EA) Demo (99% done, released)

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply

Is there demand for a soft shadows + non-Example Application demo?

Yes
243
98%
No
5
2%
 
Total votes: 248

User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Zeal wrote:Libraries? What libraries? I thought this was just a collection of shaders/materials. I am using the Ogre SDK if thats what you mean.
Well, Ogre. I thought you're compiling the demo/your own source? Besides the actual shader, you need some C++.
Now that you mention mingwm... I notice the mingwm dll being used in the demo, what exactly is that for? Sorry I saw no mention of it anywhere on this thread or in the readme..
Yeah, run using your own environment DLLs for Ogre and what-not. The mingw dll was always there for me, not entirely sure if it's still needed (I use mingw).
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Post by Zeal »

Got it working, looks nice good job! I was able to skip the 'vp setup' part (since I was getting that strange error), however I found out I MUST include the following...

Code: Select all

	   for (unsigned int i = 0; i < numShadowRTTs; ++i)
		   Ogre::TexturePtr tex = mGraphicsCore.sceneMgr->getShadowTexture(i);
Otherwise my app crashes, and I get the following error in the ogre log...
21:42:45: OGRE EXCEPTION(4:ItemIdentityException): Resource with the name Ogre/ShadowTexture0 already exists. in ResourceManager::add at e:\projects\ogrecvs\branches\eihort\ogre\ogremain\src\ogreresourcemanager.cpp (line 113)
Make any sense? Oh well its 'working' so I guess I shouldnt complain.

Im wondering though, have you given any thought to directional lights and/or large scale scenes? These spot lights look amazing in small spaces, but that can only get you so far. I implemented PSSM awhile ago, but ended up scrapping it due to crappy performance (having to render your scene multiple times really ruins the technique imo). Have you heard of this one technique (forget the name) where you warp all your casters (in a vertex shader), focusing the details in your geometry infront of the shadow camera?

Or do you have any other clever ideas for how to do large scale shadows?

*BTW does 1.4.9 support per material shadow casters? Tuan made a patch implementing this awhile back. It was the only way to have one material for 'solid' shadow casters, and another material for 'partially transparent' shadow casters (trees, fences, ect...).

*FYI - Forget about that "Run-Time Check Failure #0" I was reporting earlier. I started getting it again today, and realised that after I upgraded to 1.4.9 SDK I was still pointing to a old CVS include path for all my ogre headers. Fixed that and the error went away! Score one for Zeal!
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Post by Zeal »

Hey I implemented your shadows with my deferred rendering today, but im having a little trouble... The shadows on the ground seem to be getting blured, but the self shadowing on the sphere looks terrible...

Image

I have double checked to make sure I copied everything exactly... maybe I missed something though.. judging by the screenshot do you have any ideas for things to tripple check?
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Are you doing proper N.L diffuse lighting? Technically, the left half of the sphere should be dark anyways, and the shadow wouldn't be visible.
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Post by Zeal »

Hrmm well I had 'lighting' turned off, so youre saying its normal for things to be that jaggy? With lighting on things look better, but I still detect something isnt right. Maybe it has something to do with my depth value being stored as 16bit? Perhaps my texel positions are off...

*gah but the shadowmap is only 16bit in your demo... although maybe I should still up my scene depth to 32bit, for when I reconstruct a texel world space position...
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Well, it's OK to get that jaggy back-shadowing, since it'd be covered by by N.L being <= 0. Or, at least that's what should happen. Can I see a screen shot with lighting on?
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Post by Zeal »

Well I will admit it looks a lot better when I enable lighting and tone down the intensity (even now its still very bright, but I had it WAY brighter before). Something still feels a little off though, ill run some more tests tomorrow..

Image

*for one thing I am getting some zfighting on the ground when I pull the camera back. I think maybe adding some biasing to the shadowcaster shader might fix that..
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Alright, good luck!
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Post by xadhoom »

I really look forward to see your final results Zeal. :P
Kerion
Goblin
Posts: 235
Joined: Wed Feb 05, 2003 5:49 am
Contact:

Post by Kerion »

Is it possible to make this technique work with directional lights? I am playing with it now, but I can't seem to get it to actually shadow. All the materials load and everything runs, and I get an image, just not a shadowed image. The only thing I can think of is that it's because I am using a directional light.
Kerion
Goblin
Posts: 235
Joined: Wed Feb 05, 2003 5:49 am
Contact:

Post by Kerion »

Okay, I got your technique working, kind of. I have a very odd problem.

I made a slight modification to your shader, to remove the spot light portion. The scene was rendering, but it was in flat color, no diffuse spot light rendered, and I thought perhaps it was my code modifications. Well, after about three hours of trying various things, I took out the diffTex.xyz component of the final color, and low and behold, I got my light and shadows, but of course the scene looked washed out because the diffuse texture wasn't used as a component.

But as soon as I add the diffuse texture BACK, it goes back to flat colored, no lighting, no shadows. What in the world? My materials are pretty much copied and pasted from yours, so all of the texture settings are the same.

Here is my slightly modified shader code:

Code: Select all

POut ps_main(PIn IN,
    uniform float3 lightDif0,
    uniform float4 lightPos0,
    uniform float4 lightAtt0,
    uniform float4 depthRange,
    uniform float4 invSMSize,
    uniform sampler2D dMap : TEXUNIT0,
    uniform sampler2D shadowMap : TEXUNIT1
    ) {
    POut OUT;

    // direction
    float3 ld0 = normalize(lightPos0.xyz - (lightPos0.w * IN.wp.xyz));

    // attenuation
    half ila = length(lightPos0.xyz - IN.wp.xyz) / lightAtt0.r;
    ila *= ila; // quadratic falloff
    half la = 1.0 - ila;    
    
    float3 normal = normalize(IN.n);

    float3 LdotN0 = max(dot(ld0, normal), 0);
    float4 difTex = tex2D(dMap, IN.uv);
            
    float3 light0C =
		(LdotN0 * lightDif0 * difTex.xyz) * la *
		shadow(
            // pass in the shadow map
            shadowMap,
            // the calculated shadow position in the shadow map
            IN.lp,
            // distance to light, done just as in the caster shader
            (length(lightPos0.xyz - IN.wp.xyz) - depthRange.x) * depthRange.w,
            // radius to blur (we discussed)
            3,
            // inverse shadow map size so we know how much to move when blurring
            invSMSize.xy);

    OUT.c = float4(light0C, 1);

    return OUT;
}
Again, if I take out the difTex.xyz component from the shader, I get the "correct" screen shot :)

Very strange.

EDIT: I am such a dope, this is fixed. I had the texture in my template named diffuseTex, but was setting the alias in the child material as diffuseTexture. Doh, it works now. I removed the screens to save bandwidth, but I'll leave the problem here in case anyone else runs in to it.
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Post by xadhoom »

Do you have proper results for directional light now? If so how do you arrange your lightsetting?
Kerion
Goblin
Posts: 235
Joined: Wed Feb 05, 2003 5:49 am
Contact:

Post by Kerion »

Nope, still nothing on directional lights.

There a couple of problems. First, directional lights have a constant attenuation, so the whole variance part of the shadow map doesn't make a lot of sense, as it ends up being pretty uniform. In addition, there is no distance to the light. You can calculate a reasonable distance along the direction of the light, at max.z distance, I think...but I haven't tried it yet.

In the end, we may end using a shader based soft LiSPSM for our outdoor scenes, as it's setup to handle directional lights a bit better. We will probably use VSM for our indoor scenes, as we will get a much better effect from it in areas with more dynamic lighting.
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

http://www.ogre3d.org/docs/api/html/cla ... anagera159

Make clever use of that + and orthographic projection. Instead of storing actual distance, store:

Code: Select all

// vertex-shader
OUT.viewSpacePos = mul(worldViewMatrix, IN.position).xyz;

// pixel-shader
float depth = IN.viewSpacePos.z; // possibly divide by the value you set in the noted function
Try that instead of length(viewSpacePos).
ramar
Gnoblar
Posts: 9
Joined: Thu Aug 28, 2008 11:42 am

Huge light attenuation

Post by ramar »

Hi, i am pretty new with ogre and i am testing this awesome shadows. I used this code and it seems to work (aka: i can compile it without error) but it seems the light is not so power and get attenuated very much, so objects receive light only when they are really close to the light source.
Of course I played with "light->setAttenuation(...)", but no matter what value i put as first param, nothing change.
Any Idea? :)
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

Post by Jabberwocky »

Misunderstanding the range parameter of the setAttenuation call is a common mistake. It doesn't do what you think it does.

You should read the api comments for this function:
http://www.ogre3d.org/docs/api/html/cla ... 9f906bb65d

You're going to need to change you other attenuation parameters to make your light brighter. The attenuation formula is a standard graphics thing, and you should be able to find more information by searching on the forums or on the internet.
Image
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Jabberwocky wrote:Misunderstanding the range parameter of the setAttenuation call is a common mistake. It doesn't do what you think it does.

You should read the api comments for this function:
http://www.ogre3d.org/docs/api/html/cla ... 9f906bb65d

You're going to need to change you other attenuation parameters to make your light brighter. The attenuation formula is a standard graphics thing, and you should be able to find more information by searching on the forums or on the internet.
Actually, it depends on the shader.

@ ramar: Are you using the example diffuse_template shader from the demo itself? What world units are you working in? The range you provide for the spotlight is in world units.
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

Post by Jabberwocky »

nullsquared wrote: Actually, it depends on the shader.
Sure, you could write a shader that makes an object brighter the further it is away from the light. :)

The standard attenuation formula I'm talking about is the fixed function one, which is a good place to start in order to understand how the attenuation parameters are meant to work. And why just increasing the range parameter might not have the effect you expect it to.

Unless of course your shader ignores attenuation params, in which case nevermind. :) I haven't looked at it that closely.
Image
Trosan
Greenskin
Posts: 101
Joined: Sun Jun 10, 2007 4:57 pm
x 1

Post by Trosan »

Just a little question is "Version: 0.9 alpha" the current version?

Took me some time to find the download link. Would you mind updating the first post? Or perhaps add it to OgreAddons or something?
EDIT: Sorry, I was a bit "blind" here...

Little question to the technique itself: Have I understood correctly that if you have transparent windows/whatever using alpha rejection, the shadow is not drawn correctly?

I won't be able to try it out soon, have just ordered a new graphics card, my old one is not capable of displaying the demo (lack of features).

Thanks in advance!
Last edited by Trosan on Sun Aug 31, 2008 9:08 pm, edited 2 times in total.
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Trosan wrote:Just a little question is "Version: 0.9 alpha" the current version?

Took me some time to find the download link. Would you mind updating the first post? Or perhaps add it to OgreAddons or something
Uh. Yes, it is. Though my SSAO demo (look in the Showcase forum) has the same shadow code, with some minor additions and tweaks, so you might want to look at that, too.

Little question to the technique itself: Have I understood correctly that if you have transparent windows/whatever using alpha rejection, the shadow is not drawn correctly?
Currently, it's not. Though you can now make use of Shoggoth's shadow_caster_material directive to use a transparent shadow caster instead of the usual opaque shadow caster for alpha rejected materials (like grass and what-not).
User avatar
NoodlesOnMyBack
Goblin
Posts: 200
Joined: Tue Feb 05, 2008 4:14 am
Location: Buenos Aires, Argentina
Contact:

Post by NoodlesOnMyBack »

Sorry to bump this, but i have some problems trying to make this work :(

Image

The materials get semi-transparent, and no shadows at all.
The pre-compiled demo runs fine, then i did a minor change to the code to compile with Shoggoth:

Code: Select all

//Replaced the old Ogre::ShadowListener code with this:
struct Mgr: public Ogre::SceneManager::Listener, public Ogre::WindowEventListener {
	Ogre::ConfigFile cfgFile;
	Ogre::Root *root;
	Ogre::SceneManager *sceneMgr;
	Ogre::Camera *cam;
	Ogre::Viewport *vp;
	Ogre::RenderWindow *window;
	Ogre::Timer *timer; // we'll just use the root's timer
	Ogre::RenderSystem *rsys;

	OIS::InputManager *input;
	OIS::Keyboard *keys;
	OIS::Mouse *mouse;

        //Added the required new parameter: size_t iteration
	void shadowTextureCasterPreViewProj(Ogre::Light *light, Ogre::Camera *cam, size_t iteration);
	void shadowTexturesUpdated(size_t) {}
	void shadowTextureReceiverPreViewProj(Ogre::Light*, Ogre::Frustum*) {}

	void preFindVisibleObjects (Ogre::SceneManager *source, Ogre::SceneManager::IlluminationRenderStage irs, Ogre::Viewport *v) {}
	void postFindVisibleObjects (Ogre::SceneManager *source, Ogre::SceneManager::IlluminationRenderStage irs, Ogre::Viewport *v) {}

	bool running;

	void windowClosed(Ogre::RenderWindow *window) {
		running = false;
	}

	Mgr():
	root(NULL), sceneMgr(NULL), cam(NULL), vp(NULL), window(NULL), timer(NULL),
		rsys(NULL), input(NULL), keys(NULL), mouse(NULL), running(true) {
	}
} mgr;

Code: Select all

16:16:59: CPU Identifier & Features
16:16:59: -------------------------
16:16:59:  *   CPU ID: AuthenticAMD: AMD Athlon(tm) 64 Processor 3000+
16:16:59:  *      SSE: yes
16:16:59:  *     SSE2: yes
16:16:59:  *     SSE3: yes
16:16:59:  *      MMX: yes
16:16:59:  *   MMXEXT: yes
16:16:59:  *    3DNOW: yes
16:16:59:  * 3DNOWEXT: yes
16:16:59:  *     CMOV: yes
16:16:59:  *      TSC: yes
16:16:59:  *      FPU: yes
16:16:59:  *      PRO: yes
16:16:59:  *       HT: no
16:16:59: -------------------------
16:16:59: D3D9 : Subsystem Initialising
16:16:59: ***************************************
16:16:59: *** D3D9 : Subsystem Initialised OK ***
16:16:59: ***************************************
16:16:59: D3D9RenderSystem::_createRenderWindow "Ogre Soft Shadowing", 800x600 windowed  miscParams: FSAA=4 vsync=false 
16:16:59: D3D9 : Created D3D9 Rendering Window 'Ogre Soft Shadowing' : 800x600, 32bpp
16:16:59: D3D9 : WARNING - disabling VSync in windowed mode can cause timing issues at lower frame rates, turn VSync on if you observe this problem.
16:16:59: Registering ResourceManager for type Texture
16:16:59: Registering ResourceManager for type GpuProgram
16:16:59: D3D9: Vertex texture format supported - PF_FLOAT32_RGB
16:16:59: D3D9: Vertex texture format supported - PF_FLOAT32_RGBA
16:16:59: D3D9: Vertex texture format supported - PF_FLOAT32_R
16:16:59: RenderSystem capabilities
16:16:59: -------------------------
16:16:59: RenderSystem Name: Direct3D9 Rendering Subsystem
16:16:59: GPU Vendor: nvidia
16:16:59: Device Name: NVIDIA GeForce 6600 GT
16:16:59: Driver Version: 6.14.11.6369
16:16:59:  * Fixed function pipeline: yes
16:16:59:  * Hardware generation of mipmaps: yes
16:16:59:  * Texture blending: yes
16:16:59:  * Anisotropic texture filtering: yes
16:16:59:  * Dot product texture operation: yes
16:16:59:  * Cube mapping: yes
16:16:59:  * Hardware stencil buffer: yes
16:16:59:    - Stencil depth: 8
16:16:59:    - Two sided stencil support: yes
16:16:59:    - Wrap stencil values: yes
16:16:59:  * Hardware vertex / index buffers: yes
16:16:59:  * Vertex programs: yes
16:16:59:  * Fragment programs: yes
16:16:59:  * Geometry programs: no
16:16:59:  * Supported Shader Profiles: hlsl ps_1_1 ps_1_2 ps_1_3 ps_1_4 ps_2_0 ps_2_a ps_2_b ps_2_x ps_3_0 vs_1_1 vs_2_0 vs_2_a vs_2_x vs_3_0
16:16:59:  * Texture Compression: yes
16:16:59:    - DXT: yes
16:16:59:    - VTC: no
16:16:59:  * Scissor Rectangle: yes
16:16:59:  * Hardware Occlusion Query: yes
16:16:59:  * User clip planes: yes
16:16:59:  * VET_UBYTE4 vertex element type: yes
16:16:59:  * Infinite far plane projection: yes
16:16:59:  * Hardware render-to-texture: yes
16:16:59:  * Floating point textures: yes
16:16:59:  * Non-power-of-two textures: yes
16:16:59:  * Volume textures: yes
16:16:59:  * Multiple Render Targets: 4
16:16:59:    - With different bit depths: no
16:16:59:  * Point Sprites: yes
16:16:59:  * Extended point parameters: yes
16:16:59:  * Max Point Size: 8192
16:16:59:  * Vertex texture fetch: yes
16:16:59:    - Max vertex textures: 4
16:16:59:    - Vertex textures shared: no
16:16:59:  * Render to Vertex Buffer : no
16:16:59:  * DirectX per stage constants: yes
16:16:59: ResourceBackgroundQueue - threading disabled
16:16:59: Particle Renderer Type 'billboard' registered
16:16:59: Creating resource group Media
16:16:59: Added resource location '../data' of type 'FileSystem' to resource group 'Media'
16:16:59: Initialising resource group Media
16:16:59: Parsing scripts for resource group Media
16:16:59: Parsing script 00ambient.material
16:16:59: Parsing script 00diffuse.material
16:16:59: Parsing script caca.material
16:16:59: Parsing script metal.material
16:16:59: Parsing script ogre.material
16:16:59: Parsing script robot.material
16:16:59: Parsing script shadow_caster.material
16:16:59: Parsing script test.material
16:16:59: Parsing script white.material
16:16:59: Parsing script blur.compositor
16:16:59: Finished parsing scripts for resource group Media
16:16:59: Mesh: Loading level.mesh.
16:16:59: Can't assign material 01 - Default to SubEntity of level because this Material does not exist. Have you forgotten to define it in a .material script?
16:16:59: Texture: RustedMetal.jpg: Loading 1 faces(PF_R8G8B8,512x512x1) with  hardware generated mipmaps from Image. Internal format is PF_X8R8G8B8,512x512x1.
16:16:59: Texture: spot_shadow_fade.png: Loading 1 faces(PF_R8G8B8,128x128x1) with  hardware generated mipmaps from Image. Internal format is PF_X8R8G8B8,128x128x1.
16:17:11: *-*-* OGRE Shutdown
16:17:11: Unregistering ResourceManager for type Compositor
...
Then i changed all .materials adding the line at the top:

Code: Select all

import diffuse_template from 00diffuse.material //added
material ogre : diffuse_template
{
    set_texture_alias ambient_tex GreenSkin.jpg
    set_texture_alias diffuse_tex GreenSkin.jpg
}
Same results with OpenGL or DirectX... i dont know what else to do :S
Anyone?
Image
User avatar
mkultra333
Gold Sponsor
Gold Sponsor
Posts: 1894
Joined: Sun Mar 08, 2009 5:25 am
x 114

Re: Soft Shadows (w/o EA) Demo (99% done, released)

Post by mkultra333 »

The demo worked ok on my computer, Windows Athlon dual core 7950GT.

And I really like the cut down code. Trying to work out what's going on in all the lighting "examples" I've seen so far is a nightmare. Since they're based on ExampleApplication I can't work out what headers I really need, and the shadows demo is more like a byzantine maze of cegui code than anything else.

I'm now trying to add these soft shadows to my own project, it's starting to work but I've had a few problems.

Firstly the shader programs wouldn't compile, it complained that blur was trying to use 49 registers when there are only 12. I changed the blur radius to 1 in the shader and it was ok then.

Next it couldn't fine the diffuse_template, even though I can see it's there. This is probably my fault, it seems my programs are having trouble finding scripts unless they are in the same file. Maybe I'm missing a header or something. I fixed this by shifting the metal and white material onto the bottom of the 00diffuse.material file.

Now the log says everything is ok. I've tried to work out what bits of the project I need to copy over and I've managed to get a couple of lights up and running. I can't say I understand some of the code though. For instance, there's the shadowTextureCasterPreviewProj function. Nothing seems to call it. So how does it get used?

It'd be cool if you included a complete VC9 project instead of just a raw .cpp file too... in fact, do you know what would be really cool?

I've noticed Ogre is seriously lacking in shadow department. Not in the abilities, but in the documentation and examples. The wiki has nothing but a couple of old, useless articles. Tutorial 2 is waaay too simple (ok as an intro, but no good for doing anything sophisticated) and has the annoying ExampleApplication, while the Demo_Shadows.exe is a complicated, tangled horror (handy for demonstrating capabliities, but useless for seeing how the work programmatically).

It'd be great if someone made a couple of VC9 projects like your one, each simply demonstrating one type of shadow. For instance, I'd really like to use PCF depth shadow map in my program, but I can't work out how to construct them from any of the documents or examples. And I've seen Sinbad mention iterative shadows here, http://www.ogre3d.org/forums/viewtopic.php?f=5&t=46826. But there's no demo projects.

Anyhow, thanks for the soft shadows app, nullsquared. It'd be even better with a VC9 solution. :)
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Re: Soft Shadows (w/o EA) Demo (99% done, released)

Post by nullsquared »

Guys, forget this demo.

Check out my SSAO compositor demo, instead. It's Shoggoth-compatible out of the box, and runs under both OpenGL and Direct3D. Just search for it on the forums, it has the updated shadow code from this demo.
Post Reply