[GSoC 2012] Off-Screen Particles project - continuation

Threads related to Google Summer of Code
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

This one is mixed-resolution solution without stencil buffer (Using only "discard" operation):
Image

I was thinking about hardware acceleration, using Stencil buffer instead of second set of "discard" operations (It is always faster when in one of the passes there is no need to load texture to compare value, but also there is huge advantage because of hardware support).

I have question about stencil script.
My question is about compositor script level configuration.

I'd like to check If I finally have changed the value in stencil buffer during render_quad operation :)
I stillthink that there might be something missing in configuration.

Rendering of 2 targets with "discard" command is just easy - I've done that with no problem. The whole point is to gain hadrware acceleration by using stencil buffer.

I'd like to provide that acceleration to make things work faster.

I am executing a rendering pass that takes 2 inputs (offscreen texture and sobel filter):

Code: Select all

target_output 
        {
			depth_check off
			depth_write off
			cull_hardware off
			cull_software off
			input none
            //shadows off
            pass clear{
				buffers stencil
				stencil_value 0
			}
			stencil
			{
				check on
				ref_value 1
				pass_op replace
			}
            input none
            //pass clear{}
            pass render_quad
            {
				material OSP_BlendedOffScreenToOutput
				input 0 particlesDownsampledTexture
				input 1 sobelMaskTexture
            }
        }
Inside of shader, the pixels where [sobel filter texture value == 1] are discarded.

I hope that hanks to this configuration:

Code: Select all

            pass clear{
				buffers stencil
				stencil_value 0
			}
			stencil
			{
				check on
				ref_value 1
				pass_op replace
			}
(I hope that with above configuration) I've achieved this state:
-Stencil buffer is cleared to 0
-Stencil buffer checking is activated.
-In every painted pixel (not discarded) stencil value changes from 0 (initial value after clear) to 1.

Next pass renders everything in stencil version (but it is supposed to do only in pixels with stencil value that still == 0).

Code: Select all

		target_output
        {
			depth_check off
			depth_write off
			cull_hardware off
			cull_software off
			input none
            //shadows off
			
			material_scheme STANDARD //PARTICLE_ALPHABLEND_SCHEME
			
			stencil
			{
				check on
				comp_func not_equal
				ref_value 1
				pass_op replace
			}
			
			
            pass render_scene
            {
                first_render_queue 10
                last_render_queue  20
            }
        }
Well, I see no command to define whether to render in this pixel based on stencil value (instead of using "discard" again):
there are only options to set how buffer is changed after rendering if the compare function of original value with reference value passes. I am not 100% sure about rules in that script to say "do not render here".

Could you please explain me how to cope with that based your experience?
(Reference Value & Mask) CompareFunction (Stencil Buffer Value & Mask)
Is it enough to fail comparation function so that pixel would avoid being rendered? Or is this function only used to decide whether to execute commands from fail_op attribute, etcetera?
If from some although setting " stencil {check on}" it is not tourned on, (it is hard to debug), then what is needed to do so.
Are there any restrictions, additional expectations to activate it?

I've been trying to find that information weeks ago repeatedly, but I am not sure whether I get the documentation right (it uses both mask and stencil buffer). Lost many time without finding it out for sure.

I've of course red the forum thread under link that you gave me (about coping with stenciling on application level), I've red documentation of class used for controling stencil buffer form application, forum threads where people wanted to use stencil to something completely different (most of them ended with resigning from that idea :) ). I'm still not 100% sure that Iget it right.

I think I might know how it works but it is possible that I am missing some part needed here.

Edit:

Is it possible only from level of code to manage that sctipt? Or does attribute "check on" activate stencil writing just like i tkink?


Edit2:

Code uploaded to repository.
Tests of efficiency show that decision made by "discard" operation in case of full resolution texture, only slows down rendering :)
It has to be buffer.

This is version that uses Sobel texture for stencilin with proper Y axis also in OpenGL and preserves the same calculations of colour:
Image
Last edited by Karol Badowski 1989 on Mon Aug 27, 2012 8:11 am, edited 3 times in total.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: [GSoC 2012] Off-Screen Particles project

Post by Assaf Raman »

Does the stencil demo from my link work for you? Did you compile and run it?
Watch out for my OGRE related tweets here.
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

Yes, I have run this application. About month time ago :) It worked back then.
I'm compiling it right now.

I've updated in my signature below, the right link to repository fork (there was old link). Any1 who wanted to see actual version, saw the old one :)
Now it should be ok.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

[EDIT 12:00]
Since yesterday evening I'm uploading to project wiki page http://www.ogre3d.org/tikiwiki/tiki-ind ... +Particles reports of progress timeline.
Still continuing to describe progress.
After a break for breakfast I'll start adding detailed reports based on backup - files (they are stored in first fork in zip archives) from cumulative update. Observing changes in code and scripts let me remember more detailed progress from time when I worked offline.
Some of them already described (only some of them, I' ve just started);

When I'm finished I'll update the report about current model, make report of current state of application and describe how it works.


EDIT:

About hardware acceleration of current mixed-resolution.
Describing parameters in stencil{} section does not work the way I'd like - something is missing.
I also shoud not use definition of stenciliing for entire rendering group like in application.

That is why I think the best solution would be CompositorInstance::Listener
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

I'm dealing with sharp edge between full resolution and downsampled texture in mixed resolution. There seems to be a little displacement between them - noticeable better on big downsampling.

Downsampled offscreen when blended to the output - looks much better with linear filtering(but gets darker on edges).
I think I could try rendering them both for sake of tests to another output texture (fullscreen one) and then run the filtering

[EDIT: well no, it will treat printed pixels like something that does not need filtering, like full resolution texture that just is pixelated a bit - instead I'll do the blurring or try other way].

Full resolution paticles will receive there stencil buffer and depth from depth texture (not downsampled one)
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

I've set certain configuration of filtering and alteration of shaders (where alpha and colour would not be dependant on depth in case of range changing). Particles seemed still to be little brighter when rendered on full resolution - for 4x4 downsample I discovered that when there was nothing in background it only happened on edges.

(Edges with width dependant of downsample were brighter and middle area of full resolution render was simmilar colour like offscreen rendering).
That means rendering with alpha-blend on the same place happened in some cases.

I've changed the range (values compared with local Sobel map texture value) of discarding.
Edges became smoother.
Discovered that it might be good to use none filtering for colour and trilinear for texture of Sobel Filter.

In following view I changed range too much on purpose just to show the meaning (edges are not so drastically pixelated now):
Image

I was going to check how it works with replaced depth acquisition and some changes to alpha - blending.
[I wanted to post that message 6 hours ago :)]
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

I thought it is matter of rendering in front of solid objects, jowever brightness of colour differs between these 2 resolutions also on background.
I'm doing modiffications to both stages of alpha-blending (one that happens between particles, second one when blending to scene), to spot the difference.

Image
(left side is mixed resolution, right side full resolution)
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

I've uploaded changes to repository (for now changed for debug view - so frame drop rate will be high).
My upload has stopped due to connection to server temporary problem (I hope that files are not corrupted there now).

I'll swap modifier of alpha channel - output alpha of render target will be reversed in the moment of rendering to screen.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

For offcreen target (blended one), I made following changes:

1) For additive particle materials, changed multiplier of new colour from one to zero (the same reason)

Code: Select all

	technique
	{
		scheme PARTICLE_ALPHABLEND_SCHEME
	
		pass
		{
			lighting off
			
	  //-A------BLENDED_OFF_SCREEN----------------ORIGINALLY_ALPHA_BLEND-------	
		/*
			Thanks to this operation we create semi-transparent output for "BLENDED OFF SCREEN PASS" that can be later BLENDED to background layer.
				new.rgb=old.rgb*(1-delta.a) + delta.rgb*delta.a;
				//new.a=old.a*(1-delta.a) + delta.a;
				new.a=old.a*(1-delta.a);//we use alpha channel for storing inverted alpha of output layer (1-final alpha)=MULTIPLY[i=1..n](1-particle[i] alpha)
			Where delta is output of a shader, old is current frame buffer and new is new value to save in frame buffer.
		*/
			separate_scene_blend src_alpha one_minus_src_alpha zero one_minus_src_alpha //USE FOR BLENDED OFF SCREEN PASS
	  //-A----------------------------------------------------------------------

			(...)

		}
	}
EFFECT: everything is unvisible (final alpha = 0)

2) In compositor in clear pass, changed initial opacity to 1 (we calculate influence of background - that means inversion [1-value] of cummulative alpha).

Code: Select all

        target particlesDownsampledTexture
        {
		
            depth_check off
            depth_write off
            cull_hardware off
            cull_software off
            input none
            shadows off
            pass clear{
                buffers colour depth stencil
                depth_value 1.0 
                colour_value 0 0 0 1 //alpha changed to 1, because we store inverted cummulative alpha
            }
			
            material_scheme PARTICLE_ALPHABLEND_SCHEME
			
            pass render_scene
            {
                first_render_queue 20
                last_render_queue  20
            }
        }
EFFECT: we store inverted cummulative alpha

Image

3) In pass of printing offscreen target to output, inverse that alpha.
Inversion can be made in many places, for example

Code: Select all

material OSP_BlendedOffScreenToOutput
{
    technique
    {
        pass
        {
			(...)
	
			//scene_blend alpha_blend 
			separate_scene_blend one_minus_src_alpha src_alpha zero one_minus_src_alpha  
			
			(...)
        }
    }
}
Or for example in called shader, replace output alpha with 1-alpha.



Other changes: obel texture is passet from compositor level, co I removed call of external source texture in
OSP_BlendedOffScreenToOutput material
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

It seems to work right on black backgroungs,
Image

I'll check situation with solid colorfull objects -still seems like if colour was little to dark.



PS:
It seems that there was problem to connect with bitbucket repository.
Update froze in the middle, so I have lock on my repository and can't do update / close TortoiseHG until previous operation is finished.

Do you know how to deal with it?


EDIT: Only way was to kill some processes drastically from task manager. I hope the update is in good shape.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

Well, when I render my target with no blending, everything seems allright.
Image
However with alpha blending, it seems that alpha is still a little bit too low.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: [GSoC 2012] Off-Screen Particles project

Post by Assaf Raman »

Good progress.
Watch out for my OGRE related tweets here.
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

Well, I am debugging state of other cases than black background

It is matter of darkness that comes from colour and matter of transparency too.
At the moment, mentioned solution might be great when particles are monochromatic.

That is why i use separate channels to debug changes in cummulative alpha, alpha of singe particle texture, colours of textures.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

EDIT:

Wow, it turns out I did count everything allright.
Only last operation is different when rewriting.

In last operation alpha blend replaced:
backround multiplied by offscreen alpha channel + offscreen (not scaled, just added)

There are pictures of debug today:
Image
Image
Image
Image
Image
Image
Image
Image

Could have been replaced days ago. Fortunatelly, I counted everything and here we are. I've got solution.


EDIT:

My solution, different than NVIDIA one - did not expect inversting alpha and reverting it again after calculations, But also needed an analogic trick to be used.
Last edited by Karol Badowski 1989 on Thu Aug 30, 2012 10:35 pm, edited 1 time in total.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
PhilipLB
Google Summer of Code Student
Google Summer of Code Student
Posts: 550
Joined: Thu Jun 04, 2009 5:07 pm
Location: Berlin
x 108

Re: [GSoC 2012] Off-Screen Particles project

Post by PhilipLB »

Btw, F6 could make you happy. :) Makes instantly a screenshot and writes it as PNG to disc in the folder of the SampleBrowser.exe.
Google Summer of Code 2012 Student
Topic: "Volume Rendering with LOD aimed at terrain"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Mattan Furst


Volume GFX, accepting donations.
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

Thanks. I'll remember that tip ;).
I mainly test things in my equivalent application to the sample browser one. Starts faster, I have better camera there and mouse buttons instead of controls.

Next test:
http://www.bmm.yoyo.pl/everyday_screens ... reen97.JPG

I thougt I was close and I was close, I fixed everything there:

Here is concatenation of ofscreen target through blending:
Image
And here through right solution:
Image
I spent all day on that, now I go preparing myself for conference.
I had to do a lot to spot it and recalculate.

All in all, my solution (different than used by NVIDIA) also was right and needed the same change - but works without need of inverting alpha all the time.


I'll turn linear filtering back on.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

Today I'll travel to another city and prepare for conference. I'll work from there after conference.

I tested the speed of current version of scripts, in release version. If course I use some debug views, so half of the screen was rendered with full resolution.

I turned off last pass to test the time (full resolution was exactly on half of the screen). The best acceleration was from 60fps to 170 fps. so that will be next task - to eliminate some parameters from script, turn some calculations off to increase framerate after removing debug views.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project

Post by Karol Badowski 1989 »

Today is last day of conference I'm currently on.
[WGK 1012 - National Conference On Computer Games Developement]
I was reading a book with scientific articles, released for the conference
(here was my first publication "Physics Of Rigid Body For Three Dimensional Computer Game" - it was about engine I've been creating with my friend for BSc Thesis).

I found an article in that book, on "Fast Order-Independent Particles Using Exponential Weighting" - it connects soft particles effect and rendering particles without sorting - mihgt be useful.

Tomorrow I'll be back to optimalisations to the project.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
Alexiss
Halfling
Posts: 74
Joined: Wed Aug 10, 2011 2:11 pm
x 11

Re: [GSoC 2012] Off-Screen Particles project

Post by Alexiss »

Hey,

Any update on this ?
PhilipLB
Google Summer of Code Student
Google Summer of Code Student
Posts: 550
Joined: Thu Jun 04, 2009 5:07 pm
Location: Berlin
x 108

Re: [GSoC 2012] Off-Screen Particles project

Post by PhilipLB »

This project seems to be very quiet...
Google Summer of Code 2012 Student
Topic: "Volume Rendering with LOD aimed at terrain"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Mattan Furst


Volume GFX, accepting donations.
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

Re: [GSoC 2012] Off-Screen Particles project

Post by drwbns »

I'm thinking he just bailed on it.
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project - Failed

Post by Karol Badowski 1989 »

I have managed to do advancement to stenciling few weeks ago, (hardware acceleration), in time between september exams.
This was one of the parts that was the most problematic for me before. For now it is unfortunately not a stable update yet.

Hardware aceleration of stenciling was finally working in separate, reduced project that I used to test stenciling and to find what part does not work from the level of the script. It was controled by shape, not by texture.

As output of experiments it turned out that "setting on/off" stencil buffer from level of script by flagues does not work as it should / or as I understood it from documentation (stencil buffer was still unactive even when the flagues were set on).
However mentioned hardware acceleration works for me now when I manipulate this flague from the level of code. Other settings turned out to have been set properly.


Before stable update, possibly bigger part of communication between my sript and code part will have to be changed, because I'll have to modify the way I am referencing render groups in current version.

I have a break between studies this week. Long weekend is comming on thursday (4 days of break between studies in a row), so I'll be able to apply mentioned modification from my test project to this project on days.


Thing that I plan to improve next week is displacement of texture. When I use "discard" operation, It is easy to notice that position of texture, between Dx9 and OpenGL is different by one pixel in x and y. I've recently got to know what possibly could have been the reason.
Last edited by Karol Badowski 1989 on Mon Oct 29, 2012 6:11 pm, edited 1 time in total.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: [GSoC 2012] Off-Screen Particles project - Failed

Post by Assaf Raman »

Nice to know you are still working on this.
Keep up the good work.
Watch out for my OGRE related tweets here.
Karol Badowski 1989
Google Summer of Code Student
Google Summer of Code Student
Posts: 185
Joined: Fri Apr 06, 2012 3:04 pm
x 18

Re: [GSoC 2012] Off-Screen Particles project - Failed

Post by Karol Badowski 1989 »

Unfortunately this weekend I had to change plans because of funreal in my family, so I'll try to apply changes to main project in few iterations,
at next weekends in time between university duties.
Last edited by Karol Badowski 1989 on Wed Nov 14, 2012 2:32 pm, edited 1 time in total.
Google Summer of Code 2012 Student
Topic: "Implementation of Off-Screen Particles"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: Assaf Raman
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Re: [GSoC 2012] Off-Screen Particles project - Failed

Post by Assaf Raman »

No prob, take your time.
Watch out for my OGRE related tweets here.
Post Reply