SAS Bindings and Deferred Rendering

rated by 0 users
This post has 4 Replies | 2 Followers

Top 100 Contributor
Posts 30
SunBurn_Community_Licensee
Duncan Blair Posted: 03-08-2010 11:24 PM

Are certain SAS bindings only made in forward rendering, and vice versa?

Specifically, I'm trying to grab the light direction of the first directional light in the scene to use in applying specular highlights to my water shader. While my binding seems to be identical to that of some forward rendered examples that work, it doesn't seem to be getting set in my code.

float3 AmbientLightColor < string SasBindAddress = "Sas.AmbientLight[0].Color"; > = 0;

float3 LightDirection < string SasBindAddress = "Sas.DirectionalLight[0].Direction"; >;

In the above two lines, the ambient light colour IS getting updated automatically, and I can use the ambient light colour in my shader successfully. The light direction doesn't seem to, however. I have a directional light in my scene (just one for that matter) but any changes I make to it's direction property don't seem to be reflected in my shader. The shader seems to be working correctly if I set the light direction manually, it just isn't linking up with the light value automatically.

I guess this is because it isn't expected to be needed in deferred rendering, where typically you won't need access to lighting data like that? If some bindings aren't updated in deferred or forward rendering, is there any documentation anywhere covering which ones are or aren't available? Or maybe I've just done something daft and it isn't working when it should be - that's ALWAYS possible when I'm involved :)

It isn't a huge problem if it won't work as I can just make the light direction a property you set on the effect seperately - it just makes it nice and tidy for my shader to automatically use the sunlight direction as set in the sunburn editor.

Thanks for any help!

Top 10 Contributor
Posts 4,546
Employee
SunBurn_Studio_Licensee

Hi Duncan,

The point and directional light bindings are only used in forward rendering.  With deferred rendering SunBurn automatically handles all lighting, shadows, specular, bump and more for you and returns the data in the shader textures variables using the SCENELIGHTINGDIFFUSEMAP and SCENELIGHTINGSPECULARMAP semantics.

It looks like the docs specify the deferred-only semantics and bindings, but not the forward-only.  We'll add this to our issue tracker and the docs should be clarified next update - thanks for pointing this out to us.

Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Top 100 Contributor
Posts 30
SunBurn_Community_Licensee

Thanks for the response John.

The reason I'd chosen not to use the SCENELIGHTINGDIFFUSEMAP and SCENELIGHTINGSPECULARMAP was partly because I'm not sure how to use them effectively. Well...the specular one at least :) I've made some other custom shaders that use the SCENELIGHTINGDIFFUSEMAP just fine, but my attempt to use SCENELIGHTINGSPECULARMAP in the same way wasn't being met with the correct results.

I'm working on a water shader, slightly based on your own reflection refraction sample project, but also integrating a few other features. In your sample project your water shader doesn't support specular lighting - that is instead handled in a second rendering of the same mesh using the built in material effects. This approach wasn't ideal for my water, as I'm using multiple bump maps at once to create small scale detail and larger scale variation. Our water you can both see from very far away and very up close, you see. I can't change the built in deferred material effect to use that dual-bumpmap system, hence I wanted to get specular highlights working in my water shader.

Have you got any tips for using the SCENELIGHTINGSPECULARMAP? Do I use it exactly as I use the SCENELIGHTINGDIFFUSEMAP? I pack the GBuffer using SaveSceneData in my GBufferEffectPass pixel shader, and it seems to correctly return diffuse lighting for another of my shaders (a texture splatting shader). But on trying to read from the specular map for my water shader I ended up with...

With my own specular implementation it looks like...

I've since deleted the implementation that caused the problem seen above so I can't show you the code. Do you have any suggestions as to what could have caused it though? Could it just have been caused by incorrect normals? They're meant to be packed in viewspace, correct?

I presumed I'd misunderstood what the SpecularMap generated by sunburn was for, and that it wasn't something I could directly sample, so went onto my own implementation route instead. I guess it'd be nice to use the sunburn system however so that if I choose to have multiple lights it will pick up on them all, so I'll maybe give it another try.

Thanks for any advice!

Top 10 Contributor
Posts 4,546
Employee
SunBurn_Studio_Licensee

Hi Duncan,

Wow that looks cool, is this game targeting XBLIG?

Duncan Blair:
Have you got any tips for using the SCENELIGHTINGSPECULARMAP? Do I use it exactly as I use the SCENELIGHTINGDIFFUSEMAP? I pack the GBuffer using SaveSceneData in my GBufferEffectPass pixel shader, and it seems to correctly return diffuse lighting for another of my shaders (a texture splatting shader).

The data in both the diffuse and specular lighting buffers is packed, so make sure to unpack the data using LoadLightingData() (see the deferred Custom Effect example shaders for implementation details).

What values are you supplying to the SaveSceneData() specular and fresnel arguments?  (Ideally these values would be supplied using global shader variables, so you can edit them in the SunBurn editor)

The arguments mirror the Sunburn material properties, where the specular power is between 0 - 256, the microfacet distribution between 0.0 - 1.0, and the bias between 0.0 - 1.0.  If the fresnel information is 0.0 then only standard specular is used.

Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Top 100 Contributor
Posts 30
SunBurn_Community_Licensee

Hey John, thanks a lot for the response. Got it working!

As these things normally are, it was down to a silly little mistake :) I'd forgotten to normalise the binormal and tangent vectors after transforming them, and it was resulting in some strange behaviour. The reason it threw me off for so long was that the implementation was identical in my texture splatting shader, and that one was working just fine! I guess that it was "working" but working incorrectly, and only because the terrain had varied vertex normals was it playing nicer than the flat water plane.

Anyway, glad to have it working, and it's definitely worth using the built in specular to benefit from the highlights not showing up in shadowed areas, working with multiple light sources, etc...

Oh and yeah the game is targeting XBLIG. Glad you like the look of it! Sunburn certainly plays a big part in the eye candy :D I guess you can probably figure out what'll be hanging on to the glider ;)

Thanks again!

Dunc

Page 1 of 1 (5 items) | RSS