SHADER window/glass material

Discussion in 'Modding' started by Luchian, Oct 23, 2014.

  1. Luchian

    Luchian Administrator Staff Member Concurent RLR

    Joined:
    Jun 3, 2014
    Messages:
    1,107
    Likes Received:
    279
    [justify]AC member TTM (< thank you) found a way to do some decent looking window/glass material, should you need one for your tracks. Here is his method:

    "Step1:
    Window texture alpha channel controls window transparency. Texture must be saved 8.8.8.8 argb 32 bpp - unsigned

    Step2: ksEditor
    Select window object and apply ksPerPixelAT material and then apply ksPerPixelReflection material. :) ..Without applying ..PixelAT material first window is not transparent.

    Step3:
    Material settings. ksSpecularEXP value controls reflection sharpness. (There is no need 0,5 to KsAlphaRef, i left value accidentally..) isAdditeve needs to be 1. FresnelMaxLevel is window's brightness, maybe not right word describe, but change value and you see. :)

    btw, there is also ksPerPixelSimpleRefl material with same values to material window only relfects blue color."
    [/justify]
     
    3 people like this.
  2. MGMetroDave

    MGMetroDave Guest

    Hi Luchian,

    Firstly, thanks for taking the time to make these instructions. I've already used them several times and it generally works great! The tip about switching to alphatest shader first for transparency worked perfectly. Thanks.

    I did have 1 little question about the level of transparency, though.

    Basically I'm trying to create heavily black tinted glass for a trackside building, which in daylight is heavily tinted and looks almost opaque, but at night is lit up from the inside. It's based on a real life building where this happens.

    I've tested and tested, but can't quite get it to appear correctly. It may just be a glitch my end, but I've noticed that while the alpha channel of the image definitely does control transparency, it seems to only allow 3 options: fully opaque, 50% transparent, or 100% transparent. It seems to 'snap' to one of these settings depending on which is the closest option to the actual alpha channel transparency. Hope that makes sense.

    e.g. if I set the alpha channel to something near 50% grey, the window will be 50% transparent, but if I try to increase the opacity closer to about 80% (a lighter grey on the alpha), it appears fully opaque, since this was the closest option.

    The only reason I can think why it's doing this is because the shader might be using 'alpha test' mode rather than 'alpha blend' mode.

    In the material properties in ksEditor there's the option to change it to alpha blend, which then gives the impression of working perfectly when viewed in ksEditor, but in game it still appears fully opaque if the alpha channel colour is too light.

    Just wondering if you (or anyone else here) has any suggestions on this from your experience? Sorry for the long post! Thanks!
     
    1 person likes this.
  3. Luchian

    Luchian Administrator Staff Member Concurent RLR

    Joined:
    Jun 3, 2014
    Messages:
    1,107
    Likes Received:
    279
    First of all this is the perfect way of asking for help. You have clearly explained what the issue it, so kudos on that.

    Unfortunately, I did not experiment more than this with the shader, so I'm afraid I cannot contribute. Hopefully, some of the "elders" know something more (..or at the least, know if this is the limit).
     
  4. MGMetroDave

    MGMetroDave Guest

    Thank you Luchian for your super quick reply. Really appreciate your reply even if on this occasion you couldn't help. Hopefully someone else can chime in :)
     
  5. Johnr777

    Johnr777 Guest

    Hopefully I can help...

    Nowadays with CSP and SOL, the game is looking great, with new features and what not... but ksEditor is still the same old one, made to resemble things before CSP. So often you are going to get different results in both scenarios.

    Best is to pay attention to what the game outputs, and not the editor.

    Here is what I've been using for window settings. have a look at ambient and diffuse settings, all zeros.

    View attachment windowsAC.jpg

    The texture itself:

    View attachment RoadAM_building_windows.jpg
     
    3 people like this.
  6. MGMetroDave

    MGMetroDave Guest

    Thank you, Johnr777. I will try this. Really appreciate your help.
     
  7. Kornepheros

    Kornepheros Guest

    I've been working on a track that has a stream running nearby. I've created a rocky-textured creek bottom with a plane of "glass" plane sitting 10 cm above it. I used a custom DDS image that has a wave pattern to try to give some texture to the water surface. I then used the ksPerPixelReflection shader with the settings used by Johnr777 and it looks really great in the ksEditor... but in the game (using Content Manager) it's opaque purple! (Actually, the water looks good when looking through it at the car tires, but is opaque when looking through it to the stream bed. Also, I adjusted the ambient and diffuse settings to show the water texture better, but the results were the same when I tested with these set to zero.) Reading through this entire discussion, there are a couple of things that were not clear to me that may be the culprit:

    1. luchian mentioned the need to apply the ksPerPixelAT shader first... but I'm not sure what this means... Do I simply set the object's shader to ksPerPixelAT (do the settings matter?), then switch to ksPerPixelReflection? Or is there some way to apply two shaders at the same time that I haven't figured out yet? What does this need to look like in the .fbx.ini file?

    2. MGMetraDave thanked luchian for the tip on switching to alphatest shader first... is this referring to the ksPerPixelAT shader? eAlphatest is a blend mode within a shader, not a shader itself, and I don't recall luchian saying anything about using eAlphaTest in this discussion instead of eAlphaBlend...

    3. luchian also mentioned the need to use an argb 8.8.8.8 texture... Might this different from other DDS images that I have used successfully on my track? I am no expert on DDS files or how GIMP saves them, but my 2048x2048 image saved uncompressed is 16 MB in size, which is exactly what I would expect... Might my ignorance about this file format be the problem? Here is what my image looks like, texture on the left, alpha channel on the right:

    View attachment AnimatedStreamTexture.jpg

    After trying to get the ksPerPixelReflection shader to work, I later found and installed the stFlow shader. Now my water is animated and looks amazing in ksEditor:

    View attachment AnimatedStream.jpg
    But the animated water is still purple in the game! It looks like some sort of toxic sludge instead of water:

    View attachment AnimatedStream2.jpg

    Oddly, I've discovered that playing using my Oculus Rift results in the purple color... if I play on a monitor it looks opaque grey:

    View attachment AnimatedStream3.jpg

    Does anyone have an idea what I am doing wrong?
     
  8. Probably something to do with the fact you are not using a normal map in the normal map slots:
    View attachment upload_2019-12-28_11-26-36.png

    I'd use a flat normal map (something like 128 red, 128 green, 255 blue) in those slots to see what happens, though obviously to get the best effect you will want to make an actual normal map.
     

Share This Page