Author Topic: Subtractive Shader  (Read 6058 times)

0 Members and 1 Guest are viewing this topic.

Offline Hery

  • 26
Hello there,
Some time ago I was playing with FS trying to get it all in grayscale (since some parts are still rendered using fixed-pipeline it wasn't a total success and I got "almost-a-Sin-City-style" :P ). What really pissed me of was amount of different shaders I had to modify. So I decided to fix this problem and introduce subtractive shader.

In this approach there is one huge shader with many #ifdefs. 3d engine can choose needed functions during shader compilation (it works in exactly the same way as C preprocessor does). Advantages: we have only one shader (one vertex shader and one fragment shader to be exact), code reusability is significantly increased, and everyting takes less space. Disadvantages: shader code is much harder too understand unless you are using editor that knows what #ifdef means :P (notepad won't be a good idea). Additionally, there should not be any performance loss.

I kept backwards compatibility, so if FS can't find main-v and/or main-f files then its uses old-style shaders.

Full pack (release build, shaders, modified CPP file)

Any feedback will be appreciated.

PS I am rather unaware of SCP development process, hence I don't know it is the most convenient way to send patches made by new developers, but I hope it won't be a problem.

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
This sounds pretty awesome.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Looks good. If only the shaders worked with Shader Model 2 cards....
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Hery

  • 26
If only the shaders worked with Shader Model 2 cards....
Don't look at me ;P I only merged the existing shaders into one ;D

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
At any rate, when making sample builds, could you provide debug builds as well as regular ones? And instead of giving us a complete .c file, could you just generate a patch that can be applied to trunk?
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Hery

  • 26
Here you are: click

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Steam
    • Twitter
    • ModDB Feature
If the shaders are using IfDef in this system, we can compartmentalize based off reported SM version from the card.
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline Colonol Dekker

  • HLP is my mistress
  • 213
  • Aken Tigh Dekker- you've probably heard me
    • My old squad sub-domain
What do they do? Ie screenshots for us nubs plox :nod:
Campaigns I've added my distinctiveness to-
- Blue Planet: Battle Captains
-Battle of Neptune
-Between the Ashes 2
-Blue planet: Age of Aquarius
-FOTG?
-Inferno R1
-Ribos: The aftermath / -Retreat from Deneb
-Sol: A History
-TBP EACW teaser
-Earth Brakiri war
-TBP Fortune Hunters (I think?)
-TBP Relic
-Trancsend (Possibly?)
-Uncharted Territory
-Vassagos Dirge
-War Machine
(Others lost to the mists of time and no discernible audit trail)

Your friendly Orestes tactical controller.

Secret bomb God.
That one time I got permabanned and got to read who was being bitxhy about me :p....
GO GO DEKKER RANGERSSSS!!!!!!!!!!!!!!!!!
President of the Scooby Doo Model Appreciation Society
The only good Zod is a dead Zod
NEWGROUNDS COMEDY GOLD, UPDATED DAILY
http://badges.steamprofile.com/profile/default/steam/76561198011784807.png

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
They don't change anything, they make them easier to work with the set as a whole if you want to do your own editing.  And if you can read the defines.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline Hery

  • 26
@Zacam: my patch wasn't necessary to do that, OpenGL supports GLSL preprocessor itself. However, I think I'm going to see what I can do in order to make shaders work with SM2.0

@Colonol Dekker: unfortunately it's only a "technical patch" which reduces number of shader files from about 60 to 2. I haven't added any new graphical effects.

 

Offline Colonol Dekker

  • HLP is my mistress
  • 213
  • Aken Tigh Dekker- you've probably heard me
    • My old squad sub-domain
Don't apologise pal, just because i don't comprehend the imapct doesn't mean it's not appreciated :)

Keep it going. :yes:
Campaigns I've added my distinctiveness to-
- Blue Planet: Battle Captains
-Battle of Neptune
-Between the Ashes 2
-Blue planet: Age of Aquarius
-FOTG?
-Inferno R1
-Ribos: The aftermath / -Retreat from Deneb
-Sol: A History
-TBP EACW teaser
-Earth Brakiri war
-TBP Fortune Hunters (I think?)
-TBP Relic
-Trancsend (Possibly?)
-Uncharted Territory
-Vassagos Dirge
-War Machine
(Others lost to the mists of time and no discernible audit trail)

Your friendly Orestes tactical controller.

Secret bomb God.
That one time I got permabanned and got to read who was being bitxhy about me :p....
GO GO DEKKER RANGERSSSS!!!!!!!!!!!!!!!!!
President of the Scooby Doo Model Appreciation Society
The only good Zod is a dead Zod
NEWGROUNDS COMEDY GOLD, UPDATED DAILY
http://badges.steamprofile.com/profile/default/steam/76561198011784807.png

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Steam
    • Twitter
    • ModDB Feature
Right. But what the patch does is simplify the process a great deal to being able to have a more universal set to work with, rather than adding a more cumbersome load set of files.

BTW, I'm testing this out heavily, and I may have new V and F files here shortly. The shine factor seems overly bright and there are a few other general modifications to be made. Givin that you don't have SVN access to the FSU MEdiaVP's, you wouldn't have had those shader files to work with.

Also, what SVN version is the build made on?

*Edit: Nevermind, read the patch. 5509. Sweet.
« Last Edit: August 07, 2009, 11:21:29 pm by Zacam »
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 
melikeee
But the thing we need to concentrate on with this patch is that it breaks compatibility with VPs - people will need new shader packs in order for this to work.
We really need to figure out a better distribution method (I've been looking at the RakNet autopatcher, however that's going to be a long way off).
STRONGTEA. Why can't the x86 be sane?

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Steam
    • Twitter
    • ModDB Feature
Uh...teh hell?

If the main-f and main-v are present, they process at priority and the mediavp ones are ignored. If they are NOT present (main-f and main-v) then the mediavp ones get used.

I attached some corrected shader files. It fixes the overly bright specular that occurs when -normal is on. No other real modifications needed, actually. Though I did change the lights load, it seems to be six of one half a dozen of the other on the method used at this point. **Edit: Attachment deleted, diffuse lighting was broken.

What I _need_ to see, is if anyone experiencing the "white polygons of death" debris or any other issues for which the mediavp shaders have been corrected to take in to account. From what I see by a comparison, there should be no problems. But some folks have had some strange issues when certain shader files are present with the rest of them, and the ATI normal's issue, that I need to hear from them with your build and the attached shaders first.
« Last Edit: August 08, 2009, 04:59:11 pm by Zacam »
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 
It's a case of reading the patch and not the context  :nervous:
Sorry!
We still need to check that thoroughly - even if it's only to make sure that nothing is getting mixed.
STRONGTEA. Why can't the x86 be sane?

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Steam
    • Twitter
    • ModDB Feature
Oh yeah.

The one majorly confusing thing it does.

The debug log will show all the mediavp shader names in the log, when being run with only the main-*.sdr files. This behaviour _must_ be corrected.
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline Hery

  • 26
I've changed format of the log information:
Code: [Select]
Compiling shader ->  real_vertex_shader (legacy_vertex_shader) / real_fragment_shader (legacy_fragment_shader) ...
Keeping the name of the legacy shader will let you know which parts of the main shader are turned on.

Pack (patch based on 5510)

@Zacam: Your shaders look like diffuse lightning is not working very well when normal mapping is turned off (at least on GF8800GT).

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Steam
    • Twitter
    • ModDB Feature
Really? Interesting, as compared to the current MediaVP shaders, the behaviour is identical.

Scratch that. Yeah, solid black models is not supposed to happen. Fixoring now.

Forgot that fixed rendering is different than just turning of the -normal flag, so, that's my bad.

Okay, so I resolved the issue, but now the specular shine when -normal is on is annoying as hell, and nothing I seem to do to it is fixing it.

*EDIT:
Fixed version. Needed an #ifdef for handling the lights for -Normal separatly from non-normal lights. Check le-v vs lne-v to verify.
FSU-MainShaders.7z
« Last Edit: August 09, 2009, 08:51:59 am by Zacam »
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Steam
    • Twitter
    • ModDB Feature
*pokes at people*

Yes, the post processing is shiney as all get out. FSU and SCP would like to know if the patched shaders and the latest build posted here (or Antipodes 2) does not break anything _before_ it goes in to trunk. Because if it breaks in trunk, we may not be so easily motivated towards fixing it _immediately_ because ya'll did not bother testing or reporting it NOW.

Just sayin.
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline pecenipicek

  • Roast Chicken
  • 211
  • Powered by copious amounts of coffee and nicotine
    • Skype
    • Steam
    • Twitter
    • PeceniPicek's own deviantart page
what are the most obvious known bugs at the moment? so i can whip up a unified test mission...
Skype: vrganjko
Ho, ho, ho, to the bottle I go
to heal my heart and drown my woe!
Rain may fall and wind may blow,
and many miles be still to go,
but under a tall tree I will lie!

The Apocalypse Project needs YOU! - recruiting info thread.