• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

jjwalker

Sergeant
Nov 16, 2020
68
5
Starting an official thread since we are beyond just playing around with it, it's now a project.

I just uploaded version 1.1 to the steam workshop.

Here is the desription...


Dynamic lighting shaders by jjwalker - Version 1.1 Released 11/28/2020

Updated and made some changes, here is the list!
-Fixed Diffuse light vector interpolation bug
-moved lights off the z=0 axis to 0.1... the game is 2D but the lights still aren't level with the dirt.
-updated color blending
- improvements to shadows but I don't consider it done or fixed, just better than it was
- added attenuation
-various other adjustments

Basically, added depth but still 2D. Put your video card to work!

This mod is just shy of full dynamic lighting (only slightly). I got bored and have been rewriting the shaders. Vast improvement over stock with no performance penalty and if anything, your CPU is receiving less interrupts for frame requests. Put your GPU to work!
 
I'll be uploading the 1.2 beta later today. a lot of work was put into it and fixes almost all issues associated with 1.1. It is also considerably faster and I have moved a considerable amount of calculation away from CPU bound items so that they are mostly done GPU side where they belong in the first place. One very large improvement was rewriting the vertex shader portion to be more efficient. Matrix multiplications are extremely costly so I all but elimated most of them. The code is actually more complicated on the vertex shader but don't be fooled as once compiled takes about 1/3 of the originals calculations to complete.

So far...

-Shadows are almost entirely fixed!
-The entire lighting system runs much MUCH faster... code on the vertex AND fragment side is much more complicated but you can't use conventional thinking here. More code =/= less performance.
- lighting calculation are almost entirely dynamic, meaning constant variables (ex. y=k/x) where K would be out constant is now variable. This is just one example.

Once released, I'll explain in more detail, but just know the 1.2 beta is vastly superior to 1.1, almost to the point I should be calling it 2.0, but we aren't quite that far along...yet. My "schedule" puts us at version 2.0 coming after v1.3.

I'll update this thread accordingly once uploaded to the workshop but I am excited as 1.1 to 1.2 is a significant leap forward!
 
I ended up rewriting 1.2 Beta until I ended up at revision F. I ended up taking an entirely different approach and now pass the lightmaps through the dynamic lighting (weird, I know) but the previous route would have never been fixable. I ended up realizing some issues with it while testing it.

So yeah, turns out instead of dynamic lighting around the lightmap, I pass the lightmap through the dynamic lighting. It saves a few texture lookups and looks better anyway which is always a plus.
I also adding what I dubbed as "ghetto normal mapping". When I say ghetto, really it is just clever. I have been using the lightmap sampler to get greyscale images of the individual textures so what I ended up doing is using those greyscale texture lookups to make a on the fly normal map. By ghetto, I mean I take this greyscale normal map and transform it's RGB coordinates to Unit vectors like a surface normal and pass it to the lighting. The only reason I am able to do this is because the Camera/View position is always in line with the Z axis at coordinate 0.0. Under normal circumstances it is much more involved because your view wouldn't deviate from Z = 0.0 but textures in a 3D world would and thus requires considerably more math for that reason.

So anyway, with that said, I will be, FOR REAL this time, releasing the1.2 Beta either tonight or tomorrow.
 

Attachments

  • PA_shaders10.png
    PA_shaders10.png
    3,4 MB · Views: 0
  • PA_shaders11.png
    PA_shaders11.png
    2,2 MB · Views: 0
  • PA_shaders12.png
    PA_shaders12.png
    2,5 MB · Views: 0
  • PA_shaders13.png
    PA_shaders13.png
    2,1 MB · Views: 0
  • PA_shaders14.png
    PA_shaders14.png
    2 MB · Views: 0
Well, here it is!

Current bug list:
- Z-fighting when mouse over more than one object and multiple dialog boxes are showing. - Fix known
- Room checkerboard slightly too opaque -Fix known
- Door servos sometimes end up behind doors - Fix known, related to Z-fighting

I'll have these fixed probably by tomorrow, but for now it works great. Me personally, I have almost double the framerate over the base game. I know exactly why. Without giving an entire hour worth of reading, basically the GPU is more "tied up". The more cycles it spends rendering, the longer the CPU can go without a frame request. The CPU will stop to process every interrupt from the GPU and the CPU priority hierarchy is as follows...

OS Kernel: Realtime
Biometric input (mouse/keyboard): Very high
GPU related functions: High
Fullscreen applications: Above Normal
Windowed application: Normal or Below Normal
OS services: Below Normal or Low

GPU frame requests are costly operations when you are extremely CPU bound like PA is. The sad reality is, PA will never be multithreaded unless it is moved from OpenGL to Vulkan, which I can tell you now will never happen. In its current state, PA is running OpenGL 2.1 (which is 10 years old). If it is in fact MAYBE one version higher it's running in Legacy Compatibility mode.
Oh and here is a fun fact, Windows 10 doesn't treat PA as a fullscreen application even when running fullscreen. If you press PrtScr key on your keyboard, you'll get a screenshot of the main menu before you loaded your prison. If you alt + tab out of the game and back in, you'll get a screenshot of the first frame rendered when you come back.

Anyway, enough of all that. Attached is Lenticular Float32 1.2 Beta rev. D
Enjoy :)
 

Attachments

  • Lenticular_Float32_v1.2B_rev_D.zip
    156,6 KB · Views: 0
Wow, and just like that I fixed the shadows...they now work 100% properly
I'll post the update later this evening and it'll also be available on the steam workshop.

I decided to start upgrading to a newer OpenGL version, and suddenly a compiler error in Debug.txt popped up that had not before. This led me to the exact line where an error was occurring and a quick change fixed it. Since the shader version was never declared, the compiler would just pass over any errors that didn't totally fail, because it was defaulting to compatibility mode.

Here is the CRAZY part about that... Prison Architect SHIPS like that!!! OpenGL compatibility mode is so slow and old, I really have to ask...

Why did D11 and Paradox let that happen?! That should have never been like that. I guarantee this just fixed 90% of the games issues. I bet I just fixed my Z fighting error along with the incorrect positioning of objects that was already present before I touched it.

Let me do some testing to 100% verify but I bet this just fixed a motherload of graphical errors, even ones present before I started messing with it.

I'll update this in a little while and post the fixed code. Shame shame...
 
So just to note, testing has revealed that this is also solving the huge slowdown when weather is active and it snows. The framerate still drops a little but it is negligible compared to before.

Testing also has revealed land expansion is no longer causing a large drop in frame rate, it still drops slightly but again, it's negligible.

I caught one instance of an object being out of place but it isn't related to the Z axis fighting bug I fixed, it's a bug in the .exe in which I do not have access to.

So far I can't report any bugs with the mod, so really I wouldn't be wary of taking the Beta tag off of it and call it stable. The average framerate has increased exponentially, in most cases by almost 200%. So far the game feels fixed and I am not experiencing any of the graphics related trouble from before.

So I guess the next step in this process is to get the game up another version with OpenGL. I have to remove any deprecated functions and replace them to do so, but I am confident I'll be successful. I think the only things that are going to cause problems will be "gl_Position" and "gl_Color"... but we'll see.

@Fifnaril see if thee dev team with throw me a few transform matrices from the CPU side.
 
Although there seems to be little interest here, I'll continue updating for posterity.
The latest change notes are as follows...


Dynamic lighting shaders by jjwalker - Version 1.2 Beta rev. F3 - Released 12/17/2020

1.2 Beta is a total rewrite from previous versions, should be compatible with all hardware. I am now passing the lightmaps through the dynamic lighting instead of adding the dynamic lighting to the lightmaps. I have also added Normal mapping (not to be confused with bump mapping). See notes in source code for more information!

1.2 Beta rev. F3 Changes:
- We are now at OpenGL version 3.3! Compiled with 0 errors, 0 warnings. I plan to stay at 3.3 as to not exclude older hardware and this version should fit any future needs I have.
- Optimized a couple of other things. I am starting the process of converting Divide operations to Multiply/Multiply Add where floating point rounding error is of no consequence. MUL and MAD instructions can execute up to 6X faster in some cases (it is hardware dependent but always faster). Unit Vectors will be left alone where rounding errors are unacceptable and full 32bit precision is needed.
- No longer sharing variables aross multiple conditionals. Since we now have code branching, conditionals can now save us resources instead of waste them!
- Added lot's of comments and full explanations of just about how every piece of code works and why I do this or that. If you are interested in GLSL or C language based variants, take a look at the source code.

I will continue to optimize and refine along with starting to work on some improvements, in the mean time PLEASE if something weird happens or if something doesn't
look right, please leave me a comment! Your graphics card manufacturers driver compiles this code at runtime based on what hardware you have, so just because
it works on my Nvidia GTX960 doesn't mean it will be bug free on yours.

1.2 Beta rev. F2 Changes:
- Removed a couple of unused but declared variables that will cause errors in a dumb compiler (Intel Integrated Graphics specifically).
- Began removing functions deprecated in OpenGL 3.0
- Optimized a few lines of code that 100% assuredly working - Saves about 4,000 GPU cycles per frame (if Super Sampled) and half that without SSAA

1.2 Beta rev. F1 Changes:
- Fixed lightmap.vs(0x56) attenuation variable error (implicit vec2 to float). Was not a visible error but the compiler caught it.

1.2 Beta rev. E Changes:

- Shadows are now completely fixed!
- Base game runs OpenGL 2.0 compatibility mode, I have updated it to OpenGL 3.0 Core
- The performance improvement by updating OpenGL is substantial
- Fixed Z fighting - if an object still exhibits this behavior on a prior save, re-position the object and It'll fix it.
- New prisons shouldn't exhibit this behavior any longer.

All of the updates are being uploaded to the steam workshop. In the future I will no longer be posting zipped archives, it will exclusively be on the workshop. I will however post change notes here when they become substantial.
 
1.2 Rev. F4 progress notes:

I am delayed again because I have been implementing some neat stuff.
I've added..
-Shader based MSAA - Very fast because I am sampling neighbor pixels as they run through the GPU's pipeline, so thus it is very cheap. Pixels are shaded in 2x2 batches so sampling a neighboring pixel while "in-flight" is extremely fast. This greatly reduces texture aliasing while moving the camera.
- Variance based shadows - in progress and while working, need tweaking.
- Per pixel shadows and post process filter - I found I can use the final pass used for shadows for post process. I have a form of self shadowing going on which was the result of a mistake (one I am glad I made, lol).
 

Attachments

  • PA_shader_LF32_R4_1.png
    PA_shader_LF32_R4_1.png
    2,2 MB · Views: 0
  • PA_shader_LF32_R4_2.png
    PA_shader_LF32_R4_2.png
    2,2 MB · Views: 0
  • PA_shader_LF32_R4_3.png
    PA_shader_LF32_R4_3.png
    1,6 MB · Views: 0
  • PA_shader_LF32_R4_4.png
    PA_shader_LF32_R4_4.png
    1,9 MB · Views: 0