[SOLVED] Lightmap-Tint in Character-Shader

  • #1, by caligarimarteSaturday, 16. March 2019, 11:37 A year ago
    Hello, I recently noticed that after applying a Shader to my Character, the Character would lose its lightmap-influenced Tint. So, I thought I'll just add the Tint to the Shader as a vec3 -- and then I remembered the Tint is in Hex-Code, so I have to try and parse it from Hex to RGB first. I have a functioning Script for the Conversion, at least it functions if I manually write down a Hex-Color like "#ff0000" or "0xff0000" and convert that to RGB, but when I tell the Code to do that with Player-Character's Tint, it just doesn't work. I would like to try and display what the Character's Tint Value looks like, by trying to display it either as an Int or a String onscreen (I don't seem to understand how to use the print Function in Visionaire -- yes, I know that sounds ridiculous), but the only Results I get are "-1" or "nil", but never anything that looks like a Hex-Colorcode. So, in Order to know what exactly it looks like and to know how the Hex-RGB-Conversion Script must be adapted, how can I see the Character's Tint displayed anywhere?

    Forum Fan

    145 Posts


  • #2, by afrlmeSaturday, 16. March 2019, 14:03 A year ago
    tint is 0xBGR I think. for some reason red & blue are not in the correct order they are supposed to be, so red would be something along the lines of 0x00ff00 instead of 0xff0000.

    Imperator

    6773 Posts

  • #3, by caligarimarteSaturday, 16. March 2019, 14:46 A year ago
    tint is 0xBGR I think. for some reason red & blue are not in the correct order they are supposed to be, so red would be something along the lines of 0x00ff00 instead of 0xff0000.
    I am aware of that (in BGR Red would be 0x0000ff), but that is not my Problem. I just do not know how to visualize the Value so I can check what it looks like, because I have to assume the Conversion Code cannot handle it, and if I depict tostring(Characters["Player"].Tint) in an Object Text via <vs> (since I cannot seem to make Sense of the print-Function in Visionaire), I only get -1 or nil as a Result. Depicting or utilizing (in the Shader) a manually written Hex-Code is no Problem, so I have to assume there is something odd about the Tint's Format, and it is not just that it is BGR.

    Here is the Conversion-Code, and the Line to depict it as an ObjectText for the Value "DebugText"; "Erlene" is a Global that refers to my Player-Character, getObject("Characters[Erlene]"). What could I be doing wrong?

    Values.DebugText.String = tostring(Erlene.Tint)

    hex = tostring(Erlene.Tint):gsub("0x","")

    graphics.shaderUniform(eff, "ObjTint", {
    tonumber("0x"..hex:sub(1,2)),
    tonumber("0x"..hex:sub(3,4)),
    tonumber("0x"..hex:sub(5,6))
    } );
    1
    2
    3
    4
    5
    6
    7
    8
    9

    Forum Fan

    145 Posts

  • #4, by afrlmeSaturday, 16. March 2019, 16:33 A year ago
    it seems to be -1 for default tint (aka no tint) otherwise if you were to assign a red tint with 0x0000ff, then it would return 255 which I think is the alpha equivalent of hex?

    Imperator

    6773 Posts

  • #5, by caligarimarteSaturday, 16. March 2019, 16:58 A year ago
    it seems to be -1 for default tint (aka no tint) otherwise if you were to assign a red tint with 0x0000ff, then it would return 255 which I think is the alpha equivalent of hex?
    Though I have just tried and turned off the Shader-Script entirely, then told Visionaire to wait two Seconds before executing Values.DebugText.String = tostring(Erlene.Tint), and then after another short Pause told it to give show me <vs=debugtext>, and although without the Shader I can clearly see the Character being tinted according to the Lightmap, the Value I am shown is still "-1". So, it must be something other than Default-Tint aka. no Tint...<div>
    ... or is the Character's lightmap-influenced Tint not saved in the Character's "Tint"? This has just now occurred to me, in which Case it would make Sense why this hasn't worked so far. But as far as I can tell, "the lightmap (if present) and scene brightness will be used for the tint of the character", so to my Understanding (or Lack thereof) the Tint according to the Lightmap should actually be accessible via the Character's Tint, without a manual Setting. Or is lightmap-influenced Tint just "no Tint"? But then, where and how do I get the Linghtmap-Influence-Tint via Lua?

    EDIT: I guess it might be possible to load the current Scene's Lightmap into the Shader and use the Character's Position to calculate from that Lightmap-Image what Color it should be. I guess. I just hoped it would not have to be such a clunky Workaround. :/
    </vs=debugtext>

    Forum Fan

    145 Posts

  • #6, by caligarimarteSaturday, 16. March 2019, 19:28 A year ago
    Okay, I have solved the Issue as described, by loading the Lightmap into the Shader and calculating Color of the Player's Spot on it inside the Shader -- assuming a Game-Resolution of 1920*1080px, here are some Code-Snippets for that Solution, in Case anyone else on the Forum might ever need it.

    LUA-SCRIPT:
    graphics.shaderUniform(eff, "ObjPosX", Characters["Player"].Position.x /1920);
    graphics.shaderUniform(eff, "ObjPosY", Characters["Player"].Position.y /1080);
    graphics.shaderUniform(eff, "_t_LightmapTex", game.CurrentScene.LightMap) 
    1
    2
    3

    SHADER:
    uniform sampler2D LightmapTex;
    uniform float ObjPosX;
    uniform float ObjPosY;
    ...
    vec3 Lightmap = texture2D(LightmapTex, uvVarying / vec2(1920,1080) + vec2(ObjPosX,ObjPosY) ).rgb;
    result.rgb *= Lightmap;
    1
    2
    3
    4
    5
    6

    For the Sake of other People's Comfort, if anyone will ever search for it, I will also change the Title of the Thread, to befit the Solution better -- I hope that is okay.

    Forum Fan

    145 Posts

Write post