Sign in to follow this  
he3117

forward rendering idea

Recommended Posts

he3117    374

Hi

I want to start writing forward rendering pipeline for my deferred engine and I'm looking for efficient way to pass light information to shader.

I have an idea about it.I don't want to pass light info as constant or array so I'm thinking about sending them as textures.

for point lights I need:

 

struct PointLight

{

   COLOR LightColor;

   Vector3 LightPosition;

   float LightRadius;

}

 

It seems I can store this structure in 2 pixel of a texture:

RGB=LightColor;

alpha=LightRadius;

 

RGB=xyz of light position

 

struct SpotLight

{

   COLOR LightColor;

   Vector3 LightPosition;

   float LightRadius;

   float CosAngel;

}

RGB=LightColor;

alpha=LightRadius;

 

RGB=xyz of light position

alpha=CosAngel;

 

so with a texture 128*2 I can pass 128 point light to the shader.

But what is the best way to fill this texture?Should I make a vertex buffer with light info and pass it to a shader to writing in texture or use LockRect and fill the texture on CPU?

 

also I can pack all light info in one texture and use another texture to pass ligh Ids to shader

Share this post


Link to post
Share on other sites
Schrompf    1035

Try standard passing by constant registers first. Textures can store a lot more data than constant registers, but access to textures is pretty slow, and updating them is even slower. In contrast: reading from constant registers is "free" by nearly any measurement, and updating constant registers is quite cheap in my experience. And with 4096 x float4 constant registers you can still store a lot of lights.

Share this post


Link to post
Share on other sites
Jason Z    6434

Try standard passing by constant registers first. Textures can store a lot more data than constant registers, but access to textures is pretty slow, and updating them is even slower. In contrast: reading from constant registers is "free" by nearly any measurement, and updating constant registers is quite cheap in my experience. And with 4096 x float4 constant registers you can still store a lot of lights.

 

I completely agree with this - you could try using a texture as an experiment, but you are nearly certain to switch back to using constants afterwards...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this