Sign in to follow this  

per-pixel attenuation

This topic is 4852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey people, im working per-pixel lighting with dot3 bump mapping, I'm using Cubemaps, Normalmaps and Decalmaps right now. The result is nice but how would I add attenuation now? The way I have it right now is more like "diffuse per-pixel lighting" meaning that every surface has lighting. The tutorials like ronfraziers or nvidia use a 1D and 2D texture to apply the effect but I don't have a texture unit left to do that.. Ideas :)?

Share this post


Link to post
Share on other sites
whoa I already got it working using 3d texture attenuation, I love the result, and don't tell me not all cards support it, i don't really care since this engine is pretty high end :).

Share this post


Link to post
Share on other sites
cool, any screens/ source ?

Also for attenuation you can use projective lightning. I've been meaning to try to create complete projective "per-pixel lightning", but never got around to it. I know you don't need any extensions whatsoever for pojective lighting, but i am not sure about speed yet.

Share this post


Link to post
Share on other sites
Pretty Cool, I finished my DOT3 Bump Mapping few days ago (with some bugs), and working now on the same thing "Attenuation", i don't know if i should do it the old way or with Fragment programs
Care to share the Source code?, it might help me clarify some bugs in my code

Share this post


Link to post
Share on other sites
L0rdDiabl0: If you use fragment programs you can do attenuation in them also. And it's so much simpler to, compared to RC/TexEnv/.. Either calculate it using math or access another 3D falloff texture.

Share this post


Link to post
Share on other sites
Thanks for the response _DarkWIng_
So you suggest that i start learning ARB_Fragment_Program and skip the traditional ways of coding?
Any good learning resources of ARB_Fragment_Program?

Share this post


Link to post
Share on other sites
Quote:
Original post by JazzD
search the forums here, you find pretty much everything about it, vincoof posted some great code once, I'm using a part of it :).

I found it
I'll look into into it

Share this post


Link to post
Share on other sites
I'm not saying to skip it. It depends on what HW you want your program to run on. If you target older HW then you will need to learn how it works on TexEnv. If you target GF-FX and above then you can skip it. And if you target this hight you might as well skip FP and go straight to GLSL (or some other high-level shading language).

But that is just implementation. The actual math, the concepts, the theory, all the things that are really important are the same in all cases. I sugest you to read all you find about it. Even if you don't need to implement it, it may still give you some more info you might need later on.

Share this post


Link to post
Share on other sites
Quote:
Original post by _DarkWIng_
I'm not saying to skip it. It depends on what HW you want your program to run on. If you target older HW then you will need to learn how it works on TexEnv. If you target GF-FX and above then you can skip it. And if you target this hight you might as well skip FP and go straight to GLSL (or some other high-level shading language).

But that is just implementation. The actual math, the concepts, the theory, all the things that are really important are the same in all cases. I sugest you to read all you find about it. Even if you don't need to implement it, it may still give you some more info you might need later on.

Thanks for the explanation, i'll do as you recommend and go through all the techniques.
I've been reading for a while about what type of "Shader Coding" is better, and it seems that there isn't a prefered platform, some guys recommend GLSL as it's the future of Coding in spite of the various bugs that exists now, and others recommend cg as they claim it's more reliaple and has a good support , and some other guys recommend Fragment Programing as it has the best support across all the cards and it's going to be further developed in the future.

So what do you think is the best platform and why?
Thank you again for keeping up with me

Share this post


Link to post
Share on other sites
Just to answer few questions and guesses out there.

1) 3D textures are supported since R200 (that is, Radeon 8500 and up) and NV2x (GeForce 3/4Ti and up, except GeForce4MX and Geforce4Go), talking about gamers' grapics cards of course. And BTW I mean "supported in hardware", otherwise NVIDIA supports it in software for all its GeForce series but it's way too slow on eg GeForce2.

2) Of course fragment programming is much easier than NV_rc/ATI_fs, but you need much better hardware. Typically, you need a R300 card (Radeon 9500 and up, not Radeon 9000-9499) and NV3x (GeForce FX and up).

3) GLSL is currently being hardly supported in its full spec, so it's a bit hard to play with working and unworking features. Also, drivers tend not to work quite well actually, although they improve every time. It's a common problem to any "new" feature.

4) NVIDIA is dropping Cg more and more every day. They'll support GL2, but apart from that they're not going to make it evolve very much, as David KIRK (at NVIDIA) announced. NVIDIA would rather concentrate their effort onto HLSL (DirectX's shading language). So my guess is that Cg is not a good deal in the long run. That's fine if your engine already uses it, but if you plan to use it or not in the future I'd rather say "no go".

Share this post


Link to post
Share on other sites
hey vincoof ;), tell me something about multipass rendering, I'm having problems rendering multiple lights. There's only one light drawn even if I use blending.

Share this post


Link to post
Share on other sites
Quote:
Original post by JazzD
hey vincoof ;), tell me something about multipass rendering, I'm having problems rendering multiple lights. There's only one light drawn even if I use blending.

Which blending function are you using, and do you enable blending ?
Also if you can post screenshots and/or source code that'd be great.

Share this post


Link to post
Share on other sites
well I never worked with multipass rendering, I simply loop through all the light and render the faces again, I used GL_ONE, GL_ONE as blendmode..


for(int i=0;i<num_OfLights;i++) {
glBlendFunc(GL_ONE,GL_ONE);
glEnable(GL_BLEND);
RenderFace(faceIndex,i);
}


i tried something like that yet... correct me if it is totally wrong :)

Share this post


Link to post
Share on other sites
try this:

for(int i=0;i<num_OfLights;i++) {
glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ONE);
glEnable(GL_BLEND);
RenderFace(faceIndex,i);
}
glDisable(GL_BLEND);

Share this post


Link to post
Share on other sites
JazzD : this is good, granted you have no ambient lighting and no material emission. Also, make sure you don't call glBegin/glEnd outside the for loop. Check for GL errors (call glGetError after the loop and check it returns GL_NO_ERROR).

b3rs3rk : you're talking about smooth additive blending. While it will still work somehow, and probably even give better result than plain additive, it's not how OpenGL's lighting model is specified.

Generally smooth additive is used in cunjunction with particle systems, not with lighting equations. But you're free to do it, as I said it could even look better.

Share this post


Link to post
Share on other sites
Also make sure you set right depth-testing modes. So that you actuay draw other passes, otherwise you might only see first pass.

A bit of a sidenoe. Addive blending can lead to saturation in area with alot of lights. This can be solved by additional pass. In first n passes you accumulate only light intensitiy, then in n+1 pass you multiply this intensity with diffise(decal) texture. This way you get lighting as color = diffuse * sum[ normal dot light(i) ]. If you allso need specular you just add another n passes after that.

Share this post


Link to post
Share on other sites
i tried it the way berserk said but the whole map is only drawn transparent and only one light is visible still. Also I tried to render every light in the map alone and they are all valid and work. hmmm have to check for the depth testing thing.

Share this post


Link to post
Share on other sites

This topic is 4852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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