TheOverfloater / pathos-public

Public release of Pathos Engine
MIT License
39 stars 9 forks source link

[Not an issue] with how pathos does rendering using FBO would it be possible to copy screen space normals and specular to a framebuffer? #34

Closed valina354 closed 1 month ago

valina354 commented 3 months ago

so im trying to add ssao to my engine based on this along with ssr and stuff that needs deferred shading, so for deferred shading i think i need to copy like screen space normals,specular,etc into a seperate framebuffer, however it doesnt seem like that would even be possible at least from looking at r_bsp.cpp, would it even be possible or not?

TheOverfloater commented 3 months ago

This isn't so simple, because you basically need to render all solid objects in the world and then store their normals in an FBO. For this you'd need a new type of shader to be added both to the BSP and VBM renderers. If you want deferred shading, you'd need to redesign a major part of the engine as everything right now is based on forward multi-pass rendering.

valina354 commented 3 months ago

This isn't so simple, because you basically need to render all solid objects in the world and then store their normals in an FBO. For this you'd need a new type of shader to be added both to the BSP and VBM renderers. If you want deferred shading, you'd need to redesign a major part of the engine as everything right now is based on forward multi-pass rendering.

i pretty much need to render like these in seperate FBOs (image from learnopengl) which im not sure if its called deferred shading i call it that as i wouldnt use it for lighting just to get the info then use in a postprocessing shader to try and make like SSAO or SSR, so im guessing from what you said i would need to make new shader type that only like renders say albedo with no lighting, then use it for an FBO, and same thing for specular,normal and stuff? image

valina354 commented 3 months ago

ok so i got screen space normals to render but like im not really sure how i would get it to send into an fbo, i did this and when doing this it seems to be able to show screen space normals on screen, this is great but my issue is like how would i go about sending this into an fbo like i cant figure it out, you are like only person who knows this codebase so you might have an idea? @TheOverfloater image image image

TheOverfloater commented 3 months ago

You need to bind the FBO you want to use prior to rendering the surface normals. Take a look at how the water shader does it in r_water, that's a perfect example of rendering to an FBO. Also for rendering position of pixels, you'll need a float texture with texture clamping disabled when rendering to the FBO. Something like GL_RGBA16F.

valina354 commented 3 months ago

ok so i think i was able to get fbo to bind but like im not really sure how i would even go about making sure that like when player moves and stuff the normals move, but im going to just guess that it works, so im guessing what i need to do is do same thing for like albedo,specular,position,repeat for vbm models, merge both of the brush and vbm normals,specular,albedo,positon together somehow, and that should be it? @TheOverfloater image image

valina354 commented 3 months ago

my main concern is that im kinda worried about the determinators because i dont notice any performance fps drop with too many determinators, but i dont want shader compile time to be like 30 mins cuz that would be crazy annoying for players and shader editing

valina354 commented 3 months ago

i tried changing to rgb16 and well it kinda fucked up the rendering i tried to do it to lower memory usage so if every fbo uses 8mb of memory thats probably a problem cuz 8mb of vram is a lot for 1, it seems anything other then GL_RGB or GL_RGBA causes that strangely, but trying GL_RGB it lowers to 6mb vram useage which is better i guess image image

valina354 commented 3 months ago

well uhm i kinda tried doing same thing for specular and uhm image image im not sure what im doing wrong

valina354 commented 3 months ago

by stepping through debugger i figured out it crashes here, i think its trying to do both normal and specular to fbo at same time causing crash, but i dont know how i would prevent that image image

TheOverfloater commented 3 months ago

Many things to note here, first of all:

valina354 commented 3 months ago

Many things to note here, first of all:

  • You want to allocate an FBO only once, then reuse it over and over again. Same for that texture you're using as a renderbuffer, it should be allocated only once in InitGL as it's a screen texture. Doing it per frame is a bad idea.
  • You want to bind your FBO before rendering what you want in it, then unbind it.
  • While you can lower the number of determinators used using $invalid_state settings, it might be best at this point to use another shader script specifically for your needs with Deferred Shading, as otherwise the shader will just bloat, as you mentioned.
  • I don't recommend using anything but GL_RGBA for the normals texture, as 0-255 still gives you decent accurary with normals, I would reserve RGBA32F for the pixel coordinate texture. The goal here is to only bloat the VRAM use if absolutely needed, and floating point renderbuffers will cause a lot of bloat.

im not really sure how i would only allocate fbo and texture once, because like from what i know i need seperate to do that and also when using them in postprocessing shaders i would need to like bind seperatly so only specular for speculartexture,normal,etc, even in learnopengl deferred shading it shows do to something like that image

valina354 commented 3 months ago

i tried to do this in initgl image but now i get image i dont know why everything seems to go wrong

valina354 commented 3 months ago

i somehow fixed it but now theres this, with nsight so i cant even debug it to see if the specular works in fbo it fells like cycle of working then not working image

valina354 commented 3 months ago

i decided to try to do for VBM models now as they seem more complex so i at least have base to try more specular/albedo to fbo on both or at least be able to use screen space normals in shaders but for some reason on VBM i cant get it working, i tried to do similar like this but for some reasn the normals show in game and cause crazy performance loss (from thousands of fps to 30) vbm seems more complex and i dont know how i would go about fixing it @TheOverfloater image image

btw i init the render screen space normals after everything in 'bool CVBMRenderer::Render( void )'

valina354 commented 3 months ago

whoops part of that was my bad i forgot to do this causing it to infintly generate frame buffers resulting in fps loss but still issue with it showing the normals in game when they are meant to only render to buffer image

valina354 commented 3 months ago

and the generated fbo seems broken anyways for some reason, rev3 is broken compared to 2 image image

valina354 commented 3 months ago

ok i forgot to disable determinator prior to deleting the textures which is why it was showing ingame so only issue rn is for some reason fbo seems broken as in for some reason theres parts of vbm model vanishing in the normal view which unless im wrong isnt correct, also notice it seems to make different fbo for each different model instead of in 1 texture which i tested and when having hunderds of models it lowers fps a ton because literally so much time is spent on each model and lowers fps to like 20 due to doing it in multiple framebuffers i guess instead of doing all at same time and im not sure what to do about that

valina354 commented 3 months ago

i dont know what to do tbh because i have been spending hours on this and i still cant figure out, brushes seem to work fine, no performance loss, its just models causing issue with fbo

valina354 commented 3 months ago

yup i confirmed it generates multiple fbos or textures for each models, this quickly takes up gpu memory and performance (compared to just 1 texture for the brushes) i dont know how to fix this @TheOverfloater image this is the full code: image

and i init it at end of 'bool CVBMRenderer::DrawModel( Int32 flags, cl_entity_t* pentity )', i noticed if i try to force just 1 texture as in using a bool to do it only once, the fbo normals break and no longer send to fbo

valina354 commented 3 months ago

i dont understand where the equivelant of 'drawworld' in vbm, because i just copy and pasted drawworld in bsp and did the fbo stuff and it worked, but drawmodel doesnt seem like equivelant

valina354 commented 3 months ago

ok so i was able to do this and performance is way way way better, but theres an issue, theres crazy overdraw @TheOverfloater image image i think im closest to getting models to work with screen space normals to fbo (btw sorry for so many pings i hope its not annoying but i really dont know what to do

valina354 commented 3 months ago

i noticed even with 1 model it still occurs its very strange image

TheOverfloater commented 3 months ago

In the last image, you need to make sure you clear the color and depth buffers after binding the FBO. I'd really also just recommend looking up some tutorials on basic OpenGL on the internet, to help get you into working with it. Try NeHe and https://learnopengl.com, these sites helped me a lot back in the day.

valina354 commented 3 months ago

In the last image, you need to make sure you clear the color and depth buffers after binding the FBO. I'd really also just recommend looking up some tutorials on basic OpenGL on the internet, to help get you into working with it. Try NeHe and https://learnopengl.com, these sites helped me a lot back in the day.

im guessing you mean like this? image

that seems to cause another issue which is that depending on rev a different model is there, which im not sure if accurate but i think when binding this to a shader it would mean only for 1 model at a time it would work image

valina354 commented 3 months ago

it literally seems impossible to get this working

TheOverfloater commented 3 months ago

Without seeing and debugging the code myself I cannot tell what is wrong here right off the bat, even with pictures. The problem is that right now I am already loaded with other things related to Pathos development, so I have limited time at the moment. However after the next update I could take a look perhaps, depends on my job and health too.