Author Topic: Shaders  (Read 395 times)

Illysia

  • Forum Addict
  • *
  • Posts: 2774
    • View Profile
Shaders
« on: December 21, 2016, 02:12:30 pm »
Does anyone know how shaders work in a 3D game? I know that they are used to do all sorts of wonderful things in game but each time I try to look it up my eyes glaze over. The programming aspect doesn't make a whole lot of sense to me since I have little idea of what is being talked about.

The reason I ask is because shaders are often used to swap colors on textures. A prime example is changing skin, hair, and eye color in character creators. Being able to swap texture colors would get a lot more use out of the art assets already in game; they would just need the right shaders and to have their textures colors converted to better base colors.

Shatterkiss

  • Hydlaa Resident
  • *
  • Posts: 92
    • View Profile
Re: Shaders
« Reply #1 on: December 21, 2016, 10:16:57 pm »
I've suggested that as a way to implement tailoring without needing new textures, but there are limitations. For example, people's graphics settings might negate the shaders.

Illysia

  • Forum Addict
  • *
  • Posts: 2774
    • View Profile
Re: Shaders
« Reply #2 on: December 21, 2016, 11:22:00 pm »
Negate them in what way? I know that if you lower graphics, it will override the shaders that cause things like movement, but I've never heard of it affecting color swaps beyond sometimes showing the base color before the intended color is rendered.

Shatterkiss

  • Hydlaa Resident
  • *
  • Posts: 92
    • View Profile
Re: Shaders
« Reply #3 on: December 22, 2016, 01:47:15 am »
Yeah, when I talk about computer stuff it's like reading from a tourist's phrase book: I just stumble my way through and hope I don't call someone's mother a *****. I figured low settings ignored shaders altogether, but if some are still applied then my comment is incorrect.

LigH

  • Forum Legend
  • *
  • Posts: 7096
    • View Profile
Re: Shaders
« Reply #4 on: December 22, 2016, 02:57:13 am »
At first, you'll have to separate "vertex shaders" from "pixel shaders".

Vertex shaders can manipulate where objects appear. Using them, you can change the shape of objects parametrically (e.g. make jelly wobble, or – with additional Tesselation and Geometry shaders – display 4-dimensional fractals you could hardly prepare as a mesh in a 3D modeller). Those won't be too common yet in PS.

Pixel shaders can manipulate how objects appear. Objects in 3D worlds will usually have a base color (interpolated between the vertices = edge points of mesh primitives, usually triangles), most often covered by a texture (a picture mapped onto its surface); but every pixel displayed on screen can also have a small routine attached which calculates differences from the base color or each "texel" (pixel in the mapped texture) at this position.

Very common pixel shaders do calculate gloss and reflections, based on the "normal vector" (the direction perpendicular to the angle of the surface at this pixel, which may be altered by additional "normal maps", making a surface look bumpy despite its 3D model = mesh being flat); good looking water surfaces with ripples and even gradual transparency are already quite complex pixel shaders and may require an advanced generation of graphic cards. The pixel shaders tinting hair are very simple, in comparison.

Gag Harmond
Knight and Ambassador
The Royal House of Purrty

Illysia

  • Forum Addict
  • *
  • Posts: 2774
    • View Profile
Re: Shaders
« Reply #5 on: December 22, 2016, 09:28:34 am »
Thank you LigH, that was an explanation in plain English. :) Do you happen to know how they work in PS? What I am most interested in is how they work for changing texture colors in part and in whole.

LigH

  • Forum Legend
  • *
  • Posts: 7096
    • View Profile
Re: Shaders
« Reply #6 on: December 22, 2016, 09:49:18 am »
No, I don't have such an insight, just a little generic knowledge. But I guess it is similar to Minecraft: The texture stores the luminance at least, but the chrominance will be exchanged. No clue about the exact formula, though. May not even happen in RGB color space (maybe in HLS instead)? One may have to check if there are sources of the shader program in the PS source repository.

Gag Harmond
Knight and Ambassador
The Royal House of Purrty

Eonwind

  • Developers
  • Hydlaa Notable
  • *
  • Posts: 815
    • View Profile
Re: Shaders
« Reply #7 on: December 22, 2016, 01:15:01 pm »
No, I don't have such an insight, just a little generic knowledge. But I guess it is similar to Minecraft: The texture stores the luminance at least, but the chrominance will be exchanged. No clue about the exact formula, though. May not even happen in RGB color space (maybe in HLS instead)? One may have to check if there are sources of the shader program in the PS source repository.
I admit I have no insight myself, but given I have never spotted this piece of code in PS source code and given there is no GM or scripting command to adjust/change shaders in real time I suspect they are only handled by CS at the moment. I hope this help.