Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 06 Aug 2011
Offline Last Active Apr 20 2013 07:57 PM

Topics I've Started

Rendertarget switching with deferred lighting

23 February 2013 - 01:06 PM

hello again, this time im doing deferred lighting following this concept:



ive got it implemented, but some questions remain...

-in the first pass you need to turn off color, while the second one draws to the rendertarget. at the moment i achieve this by setting the rendertarget to 0 during the first pass. however rendertarget switching is expensive, so i wonder if i should do this maybe with alpha blending. i know i can simply try it out, but i don't want a days worth of bughunting just to find out my original solution was better, and rather profit from someone elses experience. any other clever (i.e. fast) ways to mask out color drawing?


-also, when doing multiple lights, i save a light color and specular factor in the rendertarget and accumulate values for all lights in the same target. is this the right way to do it?


in pseudocode, i do a loop over my lights which looks something like this:


for (all lights)









so my loop always switches between those targets, feels kinda expensive (atm my fps drop from 200 to 60 with 50 lights each covering ~30% of the screen, even though their pixelshader code does almost nothing, only a tex lookup (well overdraw also kills fps, but that much?)). doing the first pass with all lights, then the second doesnt work obviously, because backfaces of some light may coincide with frontfaces of another drawn earlier, and produce a draw area which should've been stenciled out.


im using dx11 btw, if it matters...


any thoughts how to do this properly is appreciated




Data pair searchable structure

04 February 2013 - 02:06 PM

Hello gamedevs!

i'm pretty sure this has been asked a million times before, but i couldn't come up with search keywords (which you probably can tell by the awkward topic title)
following problem:

i have got a set M of arbitrary data values of the same type.
now i have some random algorithm which pairs them up and puts them into a list, obeying the rule that although a data value may appear in several pairs, the symmetric counterpart (e.g. for the pair values <A,B>, with A,B in M, this would be the pair <B,A>) should not. also, no pair should appear twice.

the elements have, needless to say, no intrinsic ordering relation (else you could sort the pair to have the smaller always first, and would only need to check for the this item when looking if it already exists).

the obvious approach would be to search the entire list first item for A, and check if the pairing with B exists, then search the list's first item for B, and check if the pairing with A exists. if not, add the pair.

i am aware that in programming, you can always define an ordering relation by interpreting the data as a stream of 0 and 1, and use the induced ordering, but it seems so weak a solution. this problem just 'feels' like it can be solved more elegantly. if an ordering were used, what would be the quickest way? the one i mentioned using a sorted list?

i also hope i haven't offended anyone (or perhaps even clouded the question and/or assumptions) by my horrible translation of german math lingo into english.


sizeof() giving strange results...

22 January 2013 - 09:33 AM

i wrote a 3d vector class a while ago, been using it ever since without problem, now recently i found out it seems to have the wrong size in bytes
class Vector3 {
    float x;
    float y;
    float z;
    Vector3(const Vector3 &v);
    Vector3(float xIn, float yIn, float zIn);
    virtual Vector3 operator=(const Vector3 &rhs);
this yields a sizeof() of 16 bytes instead of 12.
by trying around, i found out that it is due to the the operator(s) being virtual (or any virtual method i add, even the destructor)
if i leave out the 'virtual' keyword, the size is correct, but the linker cant resolve the symbols.

any idea how to handle this, or why the use of 'virtual' changes a classes size?

also, pls dont link descriptions to the virtual keyword, i have been through many, and still don't get it =)
thanks in advance,

how to do a brightpass properly

31 December 2012 - 04:15 PM

ello, been off the forums (and off my hobby) for a while, now back at it :)

so im trying to write a bloom/glow/whateveryouwantocallit shader for my app along the lines of this page:


okeys... got stuff working now, still looks kinda crappy :D

parameters used:
-gauss blur sigma: 0.84
-gauss blur domain: -3*sigma to 3*sigma; codomain normalized to sum = 1
-gauss kernel samples: 15 (on all targets)
-highpass filter funtion: inputColor-(0.5,0.5,0.5)
-target sizes: B0:512x256, B1: 256x128, B2: 128:64
-scene texture size: 1280x720
-combine blur targets function: blurAccum = B0+B1+B2
-combine bloomtexture with scene: finalColor = blurAccum*0.5+scene*0.5

EDIT: ha i actually found my old thread:

that one wasn't quite answered completely so feel free to comment on that too :)

EDITEDIT: updated the original post to reflect the progress

understanding theory of bloom effect

12 October 2011 - 06:15 AM

hey all.

i want to implement a bloom effect similar to the one described by this guy.
i do understand the basic principle of what he is doing, since it seems fairly easy to understand and to implement, but im not sure about the technical details.
seems to me, unless you have a card with an awesome fill rate, this method is rather expensive. but maybe it isn't, or i'm just not doing it right.

so this is how i would generate the bloom texture:

  • i do a regular render of my scene to a texture 'SCENE'. to keep this example easy, lets say i have a square screen with 1024x1024 resolution. *without* the bloom effect, i would now simply render a screen filling quad with this texture to the backbuffer and advance the swapchain, displaying the scene on screen. at the moment, this is also the status quo for my code.
  • however, now i want to generate a bloom texture based on the SCENE texture. so i go and render the SCENE screen quad to another texture BRIGHTPASS (by 'screen quad' im talking of normalized device coordinates, obviously, just something that fills the rendertarget) the size of BRIGHTPASS is only 1/64 of SCENE: 128x128. the pixelshader for this pass has to look something like this (pseudocode):

sample all texels from (x-blursize,y) to (x+blursize,y) {
	if (luminance is above a certain value)             		//probably something like (texel.r+texel.g+texel.b > 2.4)
    	accumulate the contribution in color, multiplied by the gauss blur constant for that texel
normalize color in respect to samples taken
return color

this would yield a brightpass and a horizontal blur

  • now render to yet another texture BLUR1 applying a vertical blur (size of BLUR1 128x128)
  • at this point BLUR1 should contain a downscaled, brightpass filtered and blurred texture.
  • repeat this process for 2 other rendertargets with the sizes 256x256, BLUR2, and 512x512 BLUR3
  • render SCENE, then blend in BLUR1 to BLUR3 additively (which are all now mapped to a screen filling quad), using linear filtering or such to magnify
  • drink a beer
its probably quicker to do the brightpass only once for a 512x512 unblurred texture, then use this texture as the base for the BLUR1~3 textures. should save a lot of conditionals, the extra mul and add of scalar values should be faster, esp. since one of the factors is constant. however, this whole thing looks *awfully* slow ans expensive, and im not sure the author in the link i posted was talking about doing it this way.
would be nice if anyone could comment on this. dont care too much about the numbers used, they are more or less arbitrary, im more interested if the m.o. is correct. if you have got a completely different method of doing a nice bloom/glare effect that is even way more awesome than this feel free to post :) realism is not necessary, im more interested in speed, and, to a degree, in flexibilty considering the parameters (like the strength of the glare, scalability of the speed/quality tradeoff).

and yes, i do intend to drink a beer EVERY FRAME.