How to start writing a (TressFX) plugin ?

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
vlj
Gnoblar
Posts: 3
Joined: Fri Mar 20, 2015 11:54 pm

How to start writing a (TressFX) plugin ?

Post by vlj »

Hi,

I've ported TressFX sample to OpenGL 4.3 and I'd like to avoid it beeing forgotten in a github repo so I'd like to write a plugin for Ogre3D 2.1.
TressFX is about rendering hair in a realistic way : it ships a simple simulation routine and a Kajiya shading wrapped in an order independent transparency algorithm.
It was used in Tomb Raider 2013 and will be present in Deus Ex Universe (the 4th one). And it looks quite nice.

My port uses Shader Storage Buffer Object and compute shader for the simulation, SSBO again, texture storage, image read/write and atomic counter for the rendering part.
It's a quite straightforward port at the moment, gl features are mapped to their hlsl counterpart in quite a 1:1 fashion ; maybe Intel interlocked write (which is supported by catalyst)
and their nv equivalent ("ROV") can be used to speed up the rendering later.
The code is slower than DX11 code on AMD, I have yet to find out why. I tried to write a version using OpenCL to see if I can overlap some work but Catalyst and CodeXL are crashing all the time
(the fun part is that if I disable OpenGL code, the OpenCL code runs perfectly...) which make it really unpracticable.

Issue is that I don't really know where to start to look at. I have no experience with Ogre3d and the codebase is huge.
Ogre3d 2.1 current code ships with some plugins that are mostly scene manager related and doesnt make explicit GL or DX call, and I suspect them to be outdated.
Besides I'm not sure Ogre3d is intended to work with SSBO or atomic counter atm ; there are samples but there are empty.
There is also 2 uniforms buffer I use, and I don't know how Ogre3d bound them so that I avoid conflicting state change.

Do you have any advice or pointer or code sample that can help me starting ?

Regards,
Vincent

frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 61

Re: How to start writing a (TressFX) plugin ?

Post by frostbyte »

native gl/dx calls
http://www.ogre3d.org/tikiwiki/tiki-ind ... stem+Calls
http://www.ogre3d.org/forums/viewtopic.php?p=296902
opencl integration
https://bitbucket.org/ogreaddons/visual-experiments
https://bitbucket.org/ogreaddons/gpusphsim

this should get you started...but i dont see the point of using ogre just to make direct opengl calls with opencl...( so what you need ogre for? )
ogre is a scene rendering manager sitting on top of the rendering system( dx11/gl3+/glES ) and also abstracting large parts of it( including uniform buffers etc... ) , i think you should use this abstraction otherwise there is no benefit of using ogre and no benefit to ogre...
no compute shaders yet inside ogre, but its in the distant roadmap after ogre 2.1 will stabilize
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos

vlj
Gnoblar
Posts: 3
Joined: Fri Mar 20, 2015 11:54 pm

Re: How to start writing a (TressFX) plugin ?

Post by vlj »

I'd like to use the abstraction when possible. My goal is to make TressFX available to Ogre 2.0+ users and use the graph features transparently (culling, eventually LOD, shadows...).

My issue is that TressFX is not a "simple" node since it needs to be rendered in 2 passes, a geometric one that writes to an Image (but not to fbo) and a fullscreen pass.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4260
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 831
Contact:

Re: How to start writing a (TressFX) plugin ?

Post by dark_sylinc »

I saw your thread on GD.Net

I couldn't find many performance issues; but the best one in that position would be you since you're familiar with the code (start by stripping code until you find culprits, use GPUPerfStudio and other GPU profiling tools, etc...).

There are two things that spot my eye though:
  • SSBOs allow unbounded arrays. Try "PerPixelListBucket PPLL[]" instead of "PerPixelListBucket PPLL[10000000];"
  • This one is probably the reason for it: The original HLSL code contains the [earlydepthstencil] modier. This modifier can cause major speed ups when UAVs/atomics are involved. The GLSL version is early_fragment_tests
  • HLSL code returns 1, 0, 0, 0; while GLSL code returns "vec4( 1. )" which is looking for trouble.
As for Ogre, I'm afraid Compute Shaders haven't received all the love yet. But soon will be. They will be refactored in 2.1.
The code posted above for gl/dx native calls is for 1.x and won't work in 2.1. A custom Hlms implementation can issue native calls though.
As for the plugin thing in CMake, many of the options that are disabled by default (except for the D3D11 RenderSystem) aren't working; so just leave the defaults. OGRE_BUILD_SAMPLES2 is enabled by default but if it can't find SDL2 (which happens in Windows) it will become disabled, and thus needs to be manually reenabled.

Cheers

vlj
Gnoblar
Posts: 3
Joined: Fri Mar 20, 2015 11:54 pm

Re: How to start writing a (TressFX) plugin ?

Post by vlj »

Thanks for your tips on the shaders, I made the aforementioned change but unfortunatly it didnt change performance.
I opened a thread on amd devgurus platform here :
http://devgurus.amd.com/thread/170179
I don't really know how to increment atomic counter value otherwise, I know I can put atomic counter Inside a ssbo but I don't think it'll make a difference.
Official SDK uses an UAV so I don't think wrapping an atomic counter inside an image will improve things either...
However since Graham Sellers answered I have some hope I'll get an answer soon.

Post Reply