Author Topic: GLSL preview shaders  (Read 560 times)

0 Members and 1 Guest are viewing this topic.

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
GLSL preview shaders
« on: January 01, 2012, 10:27:14 PM »
For alphas other than the primary diffuse, can the GLSL be changed to not use their alphas in the math?

Sorry very much for bothering you with something so persnickety, but it's hosing certain things in OpenBRF preview, as I'm using alphas in the normalmap in my new shaders :-)

I'd fix it myself, but I guess the GLSL is built into the app, not loaded from a text file.
« Last Edit: January 04, 2012, 01:31:38 AM by mtarini »

mtarini

  • Resource Wrangler
  • Moderator
  • *
  • [TLD] and [OpenBRF]
    • View Profile
    • [home]
  • Faction: Neutral
Re: GLSL shader and alphas
« Reply #1 on: January 03, 2012, 10:52:10 AM »
You're right, I should make it so that users could edit the shader sources (in GLSL) used by OpenBRF for previews.

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: GLSL shader and alphas
« Reply #2 on: January 03, 2012, 12:06:51 PM »
That would be truly awesome, but if it's too much work, just changing those lines in the current stuff would do it for me for now  :)

mtarini

  • Resource Wrangler
  • Moderator
  • *
  • [TLD] and [OpenBRF]
    • View Profile
    • [home]
  • Faction: Neutral
Re: GLSL shader and alphas
« Reply #3 on: January 03, 2012, 02:18:23 PM »
but, it would ruin it for others, right?

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: GLSL shader and alphas
« Reply #4 on: January 03, 2012, 06:42:53 PM »
Oops, I think I must not have explained myself correctly  :oops:

I just want lines like, "multiply X by Y" to read "multiply X.rgb by Y.rgb", where it doesn't need the alpha input. 

What happens, if you have an alpha defined in anything but the diffuse is that the alpha is getting used, giving weird results, because X.a and Y.a weren't being defined by the texture before, so OpenGL treated them as 1.  With them defined, they're getting used in multiply steps in ways that screw up the final result.

Try putting a cloudy alpha, just any old thing, into a normalmap; you'll see it immediately, I think, unless this is another one of those fun ATi-only issues.

But exposing the GLSL would be better, yeah; then I could re-write it to reflect the HLSL stuff fairly well and distribute that to help anybody wanting to mess with the new shaders.  I don't know how much work that would be, though, so I hesitated to ask.

mtarini

  • Resource Wrangler
  • Moderator
  • *
  • [TLD] and [OpenBRF]
    • View Profile
    • [home]
  • Faction: Neutral
Re: GLSL shader and alphas
« Reply #5 on: January 03, 2012, 08:08:34 PM »
Oh, I see. Well I added the custom shaders already.

It is a rushed job, but on the other hand it is intended for expert users so there they go.

Here is how it works:
openBRF now looks for a file, "customPreviewShaders.xml", in its directory. If it finds it there, it scans it for custom shaders.

One example of that file is provided in the zip.
The example file defines one Preview-Shaders, but you can define yours.
See if it can be understood.

Three caveats:

1) It's XML, so don't use <, >, or & signs in the code. Replace them with &lt; &gt;  &amp; instead.

2) The "techniques" field is a comma separated list of "techniques". OpenBRF will use that shader to preview any mesh using a material using a shader using a "technique" with that name.

3) It's GLSL, not HLSL (which the game uses). So don't expect cut-and-pasted Mount&Blade shaders code to work.

I expect that more accurate preview shaders will be made by users for other users, and maybe posted here.

PS: you refresh that file with F5
« Last Edit: January 04, 2012, 01:11:31 AM by mtarini »

Vincenzo

  • External Developer
  • *
  • Coder of code
    • View Profile
    • Flying Squirrel Entertainment
  • Faction: Neutral
  • MP nick: FSE_Vincenzo
  • M&BWBWF&SNW
Re: GLSL shader and alphas
« Reply #6 on: January 03, 2012, 11:21:03 PM »
If you could provide the current preview shader for blue normals + specmap that would be helfull for me  :)
The current one gives me quite weird results.
 

mtarini

  • Resource Wrangler
  • Moderator
  • *
  • [TLD] and [OpenBRF]
    • View Profile
    • [home]
  • Faction: Neutral
Re: GLSL shader and alphas
« Reply #7 on: January 04, 2012, 12:48:55 AM »

There was a bug in this area, it should be fixed now (in 0.0.69b).

Eheh, 0.0.69 was a little too rushed.


Anyway the normalmap (green version) + specmap is the example custom shader provided with the OpenBRF zip
(in customPreviewShaders.xml).
You just need to un-comment a few lines in the fragment program.

If you want to use the blue version, substitute the part that computes normt with:

vec3 normt = (texture2D( samplBump,tc).xyz * 2.0 )- vec3(1.0);

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: GLSL shader and alphas
« Reply #8 on: January 04, 2012, 01:04:08 AM »
Awesome!  Will find time to play with it soon :-)

Maxim Suvorov

  • SiCh Developer
  • External Developer
  • *
    • View Profile
  • Faction: Rhodok
Re: GLSL shader and alphas
« Reply #9 on: June 15, 2012, 07:12:53 AM »
You're right, I should make it so that users could edit the shader sources (in GLSL) used by OpenBRF for previews.

http://sourceforge.net/projects/hlsl2glsl/

 :idea:
Using Google translate to post messages.

Barabas

  • Master Knight
  • *
    • View Profile
  • Faction: Neutral
  • MP nick: Bassa Bar
  • WB
Re: GLSL preview shaders
« Reply #10 on: June 20, 2012, 12:16:57 PM »
In the meantime it moved twice, ending up here: https://github.com/aras-p/hlsl2glslfork