Shaders

Questions about the content creation procedure go here, including using Forge, Anvil, or other editors, or operating emulators like Basilisk II.

Post Feb 1st '11, 21:16

As an offshoot of my work in bumpmaps for my new textures, I happened to come across this post by Hopper from some time ago:
http://www.pfhorums.com/index.php?showtopi...ost&p=77822

Then, looking for more info, I found another more relevant post by Hopper here:
http://www.pfhorums.com/index.php?showtopi...ost&p=75886

Having downloaded the Default Shaders Plugin, I felt compelled to tinker around in there, and I realized that there is a lot of possibility.

If you haven't already gotten it, I suggest you download the Default Shaders Plugin and try messing around. It's really nifty.

Has anyone else done any tinkering in there? I found a couple of neat things I could do were:
  • Make fog affect the landscapes in more subtle and odd fashions.
  • Make a bumpmapped texture look like a shiny reflective surface (kind of).
  • Totally fuck shit up without trying very hard.

And that's just stuff I did without any real idea of what I was doing.
Could someone explain what's going on inside of the shader files? For example, what is the language used there?
Is there a resource on editing these already available?
Image
Kurinn

Post Feb 1st '11, 21:38

I feel I should warn you, since this just came up internally, there are no guarantees shader MML will work the same way from release to release--or even parse the same way. In fact, it's almost certain to change. If you're OK with rewriting your MML when new releases come out, and possibly even being unable to do some of the things that are possible now, proceed.

Vertex and fragment shaders are written in GLSL. You should have no trouble finding tutorials. As for the values passed into the shaders Aleph One uses, there's no real documentation. The available shaders are listed in MML.html, and I think they all make an appearance in the Default Shaders plugin.
Last edited by treellama on Feb 1st '11, 21:38, edited 1 time in total.
User avatar

treellama
Pittsburgh

Post Feb 1st '11, 22:34

Treellama wrote:I feel I should warn you, since this just came up internally, there are no guarantees shader MML will work the same way from release to release--or even parse the same way. In fact, it's almost certain to change. If you're OK with rewriting your MML when new releases come out, and possibly even being unable to do some of the things that are possible now, proceed.

Vertex and fragment shaders are written in GLSL. You should have no trouble finding tutorials. As for the values passed into the shaders Aleph One uses, there's no real documentation. The available shaders are listed in MML.html, and I think they all make an appearance in the Default Shaders plugin.


Thank you. I think I can live with those caveats, and I'll look into GLSL. If I come up with anything interesting, I'll post screenshots here.

I've thinking about trying to tweak things to create effects which mimic refraction in non-opaque textures somehow. I figure that that would be someplace where the shaders might come into play, but I am not sure if it is germane to the realm of possibility or if it is just the gross product of an unholy union between my imagination and my ignorance.

If I remember correctly, the new renderer was created by hogdotmac, and then implemented by yourself and Hopper. From your point of view, are there any near term plans for further development in this area? If things are going to change, where are we going with it? Is there anything in particular to be excited about at the moment?
Image
Kurinn

Post Feb 2nd '11, 01:57

Kurinn wrote:I've thinking about trying to tweak things to create effects which mimic refraction in non-opaque textures somehow.

GLSL can do that, but probably not the way we have it set up. You can only have one shader for all walls right now, so it would have to run for all your non-opaque textures too. Plus, I'm guessing you'd need the scene rendered to a texture to do refraction, and the engine doesn't give you that.

If I remember correctly, the new renderer was created by hogdotmac, and then implemented by yourself and Hopper.
Most of the credit goes to those two.

From your point of view, are there any near term plans for further development in this area? If things are going to change, where are we going with it? Is there anything in particular to be excited about at the moment?

For the next release, only minor improvements. More efficient rendering, non squished landscapes, more classic fog, etc. The base shaders will change (have already changed) but I believe the MML will be the same.
Last edited by treellama on Feb 2nd '11, 01:57, edited 1 time in total.
User avatar

treellama
Pittsburgh

Post Feb 3rd '11, 23:46

I've had "write shader documentation" on my to-do list for months (EDIT: over a year), but there's still no real progress. I'm not going to write a general GLSL tutorial, as there are plenty of those and my own understanding is actually pretty limited. But, a guide to the special variables provided by the engine is sorely lacking. For now, I did find in my notes this (possibly inaccurate) list of GLSL variables passed to each shader.

Code: Select all
blur
    offsetx, offsety, pass
bloom
    pass

landscape / landscape_bloom
    repeat, usefog
    various options stuffed into texture matrix

sprite / sprite_bloom
    depth, glow, flare

invincible / invincible_bloom
    depth, flare, time, usestatic
    glow always 0 - doesn't get glow step

invisible / invisible_bloom
    depth, flare, visibility
    glow always 0 - doesn't get glow step

wall / wall_bloom
    depth, glow, wobble, flare
    has normal
    
bump / bump_bloom
    depth, glow, wobble, flare
    has normal
    has normal map in texture 1


Any or all of this may change by the next release. Any polished documentation won't be released before then, but feel free to ask questions (and PM me if I don't respond, in case I take another 8-week break from the Pfhorums).
Last edited by Hopper on Feb 3rd '11, 23:52, edited 1 time in total.
Aleph One:  Download 1.2.1         Plugins:  Vasara  ·  more
User avatar

Hopper

Post Feb 17th '11, 13:49

Here's another thing you can do with shaders, if you're crazy enough:

User avatar

treellama
Pittsburgh

Post Feb 17th '11, 17:55

somebody should be crazy enough
User avatar

ukimalefu

Post Feb 17th '11, 22:50

Treellama wrote:The engine doesn't support any colored lighting right now.

Oh, you tricky bastard. [MTongue] This just begs the question, what cool feature will DADDY Z3RO ask for, and get, next?

If you'll entertain some more serious questions...
- It appears this screenshot uses a single dynamic light. Is it trivial to create more than one at once?
- How big an impact does a dynamic light have on performance?
- It also appears the dynamic light is the only light source affecting surfaces. That is, the ambient light level as set in the map editor is ignored. Can dynamic lighting be added on top of Aleph One's traditional lighting? (I would assume so)
- Is the lighting dynamic, specifically in the sense that it can change over time? Is there functionality implemented or planned to have a light source change intensity/color, follow a path, or attach to a moving object (e.g. a monster)?
- Can dynamic lights and bump maps work together on the same surface? Again, I would assume the answer is yes.
- Are there plans to make dynamic lights affect sprites?
- How can the mapmaker create a dynamic lights in his level?
User avatar

Crater Creator

Post Feb 17th '11, 22:54

Treellama wrote:Here's another thing you can do with shaders, if you're crazy enough:



It's not easy being green.

How, exactly?
Image
Kurinn

Post Feb 18th '11, 02:05

Crater Creator wrote:Oh, you tricky bastard. [MTongue] This just begs the question, what cool feature will DADDY Z3RO ask for, and get, next?

If you'll entertain some more serious questions...
- It appears this screenshot uses a single dynamic light. Is it trivial to create more than one at once?
- How big an impact does a dynamic light have on performance?
- It also appears the dynamic light is the only light source affecting surfaces. That is, the ambient light level as set in the map editor is ignored. Can dynamic lighting be added on top of Aleph One's traditional lighting? (I would assume so)
- Is the lighting dynamic, specifically in the sense that it can change over time? Is there functionality implemented or planned to have a light source change intensity/color, follow a path, or attach to a moving object (e.g. a monster)?
- Can dynamic lights and bump maps work together on the same surface? Again, I would assume the answer is yes.
- Are there plans to make dynamic lights affect sprites?
- How can the mapmaker create a dynamic lights in his level?

Haha calm down. "Dynamic liting" is a joke. I just hard coded a light source into the wall vertex and fragment shaders. You could probably hard code a few more in there, and you could probably get it to work with bump maps, but the results are pretty limited. No occlusion (unless you get super creative), intensity and color hard coded.

There's no speed hit because as you saw I removed all the other lighting including the miner's light.

Finally, rest assured, if dynamic lighting does get added, it won't be because D0 asked for it.
User avatar

treellama
Pittsburgh

Post Feb 18th '11, 03:21

Kurinn wrote:It's not easy being green.

How, exactly?

Here, I cleaned it up for you. It probably won't do you much good, though. There's no occlusion, no shadows, and you probably want to put back in all the other lighting, transfer mode handling, etc. I took out.

These will make a nice white point light in the middle of King of Pain. Decrease the falloff to increase the size of the light. Small lights will work best, though.

Code: Select all
varying vec3 normal, direction;
varying float distance;

void main(void) {
    // point light location in WU
    vec3 locationWorld = vec3(0.0, 0.0, 2.0) * 1024.0;

    vec4 locationEye = gl_ModelViewMatrix * vec4(locationWorld, 1.0);
    vec4 vertexEye = gl_ModelViewMatrix * gl_Vertex;
    vec3 segment = vec3(locationEye - vertexEye);

    direction = normalize(segment);
    distance = length(segment) / 1024.0;

    normal = normalize(gl_NormalMatrix * gl_Normal);

    gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
    gl_Position = ftransform();
}


Code: Select all
uniform sampler2D texture0;
varying vec3 normal, direction;
varying float distance;

void main (void) {
    // point light diffuse color
    vec4 diffuse = vec4(1.0, 1.0, 1.0, 0.0);
    // point light ambient color
    vec4 ambient = vec4(0.1, 0.1, 0.1, 0.0);
    // global ambient color
    vec4 color = vec4(0.1, 0.1, 0.1, 0.0);

    float constantFalloff = 0.2;
    float linearFalloff = 0.1;
    float quadraticFalloff = 0.05;

    vec3 n = normalize(normal);

    float NdotL = max(dot(n, normalize(direction)), 0.0);
    if (NdotL > 0.0) {
        float attenuation = 1.0 / (constantFalloff + linearFalloff * distance + quadraticFalloff * distance * distance);
        color += attenuation * (diffuse * NdotL + ambient);
    }

    gl_FragColor = color * texture2D(texture0, gl_TexCoord[0].xy);
}
User avatar

treellama
Pittsburgh

Post Feb 19th '11, 00:12

Treellama wrote:Here, I cleaned it up for you. It probably won't do you much good, though. There's no occlusion, no shadows, and you probably want to put back in all the other lighting, transfer mode handling, etc. I took out.

These will make a nice white point light in the middle of King of Pain. Decrease the falloff to increase the size of the light. Small lights will work best, though.


Thank you.
Image
Kurinn

Post Feb 19th '11, 05:57

Coming soon... Alpha One version 1!

- Dynamic lighting!

- Bridges and balconies!

- Built-in jumping script!

- All-new menu screen by Goran!

- All-new Alpha One Icon by W'rkncacnter and Pfhorrest!

...And much, much more!!!
Last edited by President People on Feb 19th '11, 06:13, edited 1 time in total.
Love Marathon, and also play Doom on modern source ports? You might like these skins!
User avatar

President People

Post Feb 20th '11, 03:29

Treellama wrote:Here, I cleaned it up for you. It probably won't do you much good, though. There's no occlusion, no shadows, and you probably want to put back in all the other lighting, transfer mode handling, etc. I took out.

These will make a nice white point light in the middle of King of Pain. Decrease the falloff to increase the size of the light. Small lights will work best, though.

Code: Select all
snip 1

Code: Select all
snip 2

I'd like to experiment with your shader, but I can't get it to work. I downloaded the default shaders, made a copy of it, and replaced wall.frag and wall.vert with those two bodies of text. I tried it both ways: with the first code block as wall.frag and the other way around (this may be obvious to a non-novice, but it isn't to me). I changed the Plugin.xml to rename the plugin "Point Light" and changed the Plugin.mml to just
Code: Select all
<?xml version="1.0"?>
<marathon>
  <opengl>
    <shader name="wall" vert="wall.vert" frag="wall.frag"/>
  </opengl>
</marathon>


I deleted the other shader components from the folder, just in case. I put it in the plugins folder, and enabled it (and only it) in the preferences. I'm rendering with OpenGL (Shader), and I have all other scripts turned off. I ran it on King of Pain, and there is no change: everything is lit normally. Help?
User avatar

Crater Creator

Post Feb 20th '11, 03:40

The first shader is vertex, it sets gl_Position. The second is fragment, it sets gl_FragColor. Experimenting will be a challenge if you can't tell them apart.

I just tested these with 0.23.2 and they work--I had been using SVN. Since you're replacing the basic wall shader, make sure you disable Bump/Bloom.
User avatar

treellama
Pittsburgh

Post Feb 20th '11, 15:45

Crater Creator wrote:Oh, you tricky bastard. [MTongue] This just begs the question, what cool feature will DADDY Z3RO ask for, and get, next?


I don't think i neccesarily ask for features, but I DO ponder the possibility of them.
"Escape will make me God"
User avatar

zero
Tau Ceti or bust!

Post Feb 20th '11, 16:36

DADDY Z3RO wrote:[topic="6321"]I don't think i neccesarily ask for features, but I DO ponder the possibility of them.[/topic]
underworld : simple fun netmaps // prahblum peack : simple rejected netmaps
azure dreams : simple horrible netmaps // v6.0!!!: thomas mann's greatest hits : simple simple netmaps
User avatar

irons
(.Y.)

Post Feb 20th '11, 19:35

He wasn't asking, irons, as much as demanding.
Last edited by treellama on Feb 20th '11, 19:36, edited 1 time in total.
User avatar

treellama
Pittsburgh

Post Feb 20th '11, 19:38

I was waiting for him to realize that. Thanks for blowing the whole operation.
underworld : simple fun netmaps // prahblum peack : simple rejected netmaps
azure dreams : simple horrible netmaps // v6.0!!!: thomas mann's greatest hits : simple simple netmaps
User avatar

irons
(.Y.)

Post Feb 20th '11, 22:41

Treellama wrote:He wasn't asking, irons, as much as demanding.


Oh come now.
I asked if it were possible for you to incorporate it, I never said TREELLAMA PUT IN DYNAMIC LIGHTING.
Plus, that was a SUGGESTION/WISHLIST thread.
Last edited by zero on Feb 20th '11, 22:43, edited 1 time in total.
"Escape will make me God"
User avatar

zero
Tau Ceti or bust!

Post Feb 20th '11, 23:06

DADDY Z3RO wrote:Oh come now.
I asked if it were possible for you to incorporate it, I never said TREELLAMA PUT IN DYNAMIC LIGHTING.
Plus, that was a SUGGESTION/WISHLIST thread.


DADDY Z3RO wrote:For the entirety of the Aleph One, there has been suggestions.

Hm, cool. He's calling them suggestions. Therefore, they must be suggestions.

You post what you want, and we see what we get as a response.

[...]

-Aleph One should have support for some form of area effect colored lighting
-Weland should be able to open M1 Maps in the same way that Aleph One does.
-Shapefusion should have some option to modify M1 shapes files.
-Weland should have a Visual Mode.

Oh, silly me. I guess he doesn't realize that these come across as demands. He should read his own post next time.
underworld : simple fun netmaps // prahblum peack : simple rejected netmaps
azure dreams : simple horrible netmaps // v6.0!!!: thomas mann's greatest hits : simple simple netmaps
User avatar

irons
(.Y.)

Post Feb 21st '11, 00:55

Should does not mean will.

AND never boldface my own words for self-emphasis again.
Last edited by zero on Feb 21st '11, 00:55, edited 1 time in total.
"Escape will make me God"
User avatar

zero
Tau Ceti or bust!

Post Feb 21st '11, 00:58

DADDY Z3RO wrote:Should does not mean will.

AND never boldface my own words for self-emphasis again.

Won't you ever stop making demands?
underworld : simple fun netmaps // prahblum peack : simple rejected netmaps
azure dreams : simple horrible netmaps // v6.0!!!: thomas mann's greatest hits : simple simple netmaps
User avatar

irons
(.Y.)

Post Feb 21st '11, 01:09

DADDY Z3RO wrote:Should does not mean will.


Sorry dude, irons is right. OED's definition of should:
modal verb
1 used to indicate obligation, duty, or correctness, typically when criticizing someone's actions


Even threads with polite, well thought out feature requests usually don't alter my to-do list, but hopper said they might be useful to others so I just stay out of them. But yours was certainly neither of those.
Last edited by treellama on Feb 21st '11, 01:10, edited 1 time in total.
User avatar

treellama
Pittsburgh

Post Feb 21st '11, 01:11

DADDY Z3RO wrote:Should does not mean will.

AND never boldface my own words for self-emphasis again.

Quit being a selfish prick.
User avatar

Wrkncacnter

Next

Return to Editors, Emulation, Etcetera



Who is online

Users browsing this forum: No registered users