Get Character's current Animation-Frame's Size & Position?

  • #10, by MachtnixTuesday, 26. March 2019, 18:02 5 years ago
    Ok, I get nearer... wink Slooooowly...
    Every character has usually a mask to seperate it from enviroment (alpha-channel). This one is always exactly on position. Can't you use them? You want - for example - that the 2D-character sheds a shadow?

    Thread Captain

    1097 Posts


  • #11, by caligarimarteTuesday, 26. March 2019, 18:53 5 years ago
    getAnimationSize() should work.
    At least as i tried it last time, i got the sprite size incl. its zoom calculated in. the problem is that the sprite position is mostly not exactly the point where the sprite ends or exactly centeres. 
    So you need to consider that you need to substract also the spriteSize-"distance to position.x/y"
    Yes, it is very strange though. I seemingly can load the AnimationSize (divided by the Screen-Dimensions or not):
      graphics.shaderUniform(shader_effects[eff].num.num, "AnimationSize", 
    <span>    {
    </span><span>      graphics.getAnimationSize(Erlene).x / 1920,
    </span><span>      graphics.getAnimationSize(Erlene).y / 1080
    </span><span>    } )</span>

    But then, the Duplicate weirdly has very different Scaling-Dimensions compared to if I put in the Values of the usual Animation-Size manually inside the Shader -- as you can see in the Image with the three differently scaled Duplicates.
    (I also tried making the Screen-Dimension-Division inside the Shader when using the Uniform loaded via getAnimationSize(), but that strangely did not work at all then.)

    I am not 100% sure what you mean by substract also the spriteSize-"distance to position.x/y". Right now, the UV-Coordinate for the Mask gets a manually inserted Offset "+vec2(0.5,0.94)" to approximate the Position according to the Animation-Center. Did you mean something different? If so, then maybe that could be something I have been entirely missing so far. smile

    @ Machtnix:
    Yes, after loading the Sprite into the Shader and scaling/positioning the Sprite to somewhat fit the Player-Character, I use the Alpha-Mask to get a Mask for Effects like Shadowcasting and Crepuscular Rays (as you can see on one of the Images, though I will have to use a different Rays-Technique due to a Lack of Downscaling (or does Visionaire have that??)), or the RGB-Values for a Reflection (as seen one another one of the Images). Yes, the Alpha-Mask has the same Dimensions as the Sprite, but Positioning and Scaling the Sprite in the Shader (automatically and exactly) is the Problem. smile

    Forum Fan

    145 Posts

  • #12, by sebastianTuesday, 26. March 2019, 19:00 5 years ago
    why dont you use a normalmap for the light stuff?
    The reflection shader however looks neat. You need to share some scripts wink
    I am not 100% sure what you mean by substract also the spriteSize-"distance to position.x/y". Right now, the UV-Coordinate for the Mask gets a manually inserted Offset "+vec2(0.5,0.94)" to approximate the Position according to the Animation-Center. Did you mean something different? If so, then maybe that could be something I have been entirely missing so far. smile
    I thought you want to get the top/left position of the actual sprite and calculate it by substracting the AnimationSize from the actual players position. This however doesnt contain the offset from the sprite to the actual center.

    Thread Captain

    2346 Posts

  • #13, by caligarimarteTuesday, 26. March 2019, 19:42 5 years ago
    why dont you use a normalmap for the light stuff?
    The reflection shader however looks neat. You need to share some scripts wink
    ...
    I thought you want to get the top/left position of the actual sprite and calculate it by substracting the AnimationSize from the actual players position. This however doesnt contain the offset from the sprite to the actual center.
    Thanks. smile
    The Mechanics are still a Bit faulty though, only the Reflection works without any Problems, because that is such a simple Technique... except for the Positioning/Scaling, as that is the big Problem discussed here.

    I actually started out writing a Shader that would automatically generate a Normalmap for my Character that could be used for Lighting (see Image -- though that is a WIP-Shot), but then I had to admit to myself that I just don't understand the necessary Normal-Vector-Dotproduct-Etc.-Calculations necessary to actually actually use the Normalmap (but I might keep trying), so I instead settled with the much easier Mechanic of using an offset inverted Alphamask blurred across the Character according to the Lightvector (as seen on the multiple Images I have already posted), and I think the Results are neat enough, and run fast enough as well. smile
    However, I never said that that the "Lighting-Stuff" -- i.e. the Character-Lighting -- is problematic in any Way, my Problem is with getting a properly positioned Mask for the shown Effects. I don't see how a Normalmap (on my Character) could possibly produce Godrays, Reflections, or Shadows cast across the Background in Pseudo-3D. Normalmaps don't help with that.

    Concerning this: I thought you want to get the top/left position of the actual sprite and calculate it by substracting the AnimationSize from the actual players position. This however doesnt contain the offset from the sprite to the actual center.
    I am currently using the Character's Position (and the upper-left Corner of the Duplicate would be there), which is at the Animation-Center and therefore have to offset the Duplicate by the Position of the Animation-Center, which usually is half the Width of the Character-Sprite, and ca. 0.94 of its Height. If, however, I could load the Animation-Sprite's upper-left Corner's Onscreen-Position directly, I would not have to shift it by any such Offset (which changes with each Angle) and could most probably directly place it where the current Sprite is. But you might be right, I should try and do the Calculation with the AnimationSize or AnimationInnerSize and see if that might make any beneficial Difference. smile (Problem still being that the AnimationSize does such weird Things when being loaded into the Shader.)

    Forum Fan

    145 Posts

  • #14, by sebastianTuesday, 26. March 2019, 20:08 5 years ago
    didnt recognize the god rays. Pretty neat. Im very interested in how that works :O

    Normalmaps as itself can be done inside a normal shader as you can use a normal map uniform _t_normal inside the callback(object):
    ...
    local nmap = "normalmaps/"..graphics.getCurrentSpritePath(object)
    ...
    graphics.shaderUniform(lightingShader, "_t_normal", nmap )



    Thread Captain

    2346 Posts

  • #15, by caligarimarteTuesday, 26. March 2019, 22:29 5 years ago
    didnt recognize the god rays. Pretty neat. Im very interested in how that works :O

    Normalmaps as itself can be done inside a normal shader as you can use a normal map uniform _t_normal inside the callback(object)

    Oh, is there already a functional Normalmap-Lighting-Shader available online for Use in Visionaire? If so, I must have totally missed that -- and, where could I find that? (I think it could easily be combined with automatic Normalmap-Generation as I have started to work on.)

    The Godrays in that Screenshot are unfortunately rather expensive -- primarily because I have no Downsampling and therefore must use too many Samples (48 Iterations of Textures offset against the Light-Vector), so I have alternatively started to play around with a simpler Concept which uses only 3 Samples of Textures being bent/stretched and clamped at different Points (see Image, also with a Shadow using only 1 Sample -- I consider offering Graphings Settings with different Levels of Complexity).

    Forum Fan

    145 Posts

  • #16, by sebastianWednesday, 27. March 2019, 02:36 5 years ago

    Thread Captain

    2346 Posts

  • #17, by caligarimarteWednesday, 27. March 2019, 11:51 5 years ago
    SimonS did an example here:




    Oh thanks! ... but the Link seems to be dead, I get a "404 Not Found"-Error. roll Any Chance for a Re-Upload?

    Forum Fan

    145 Posts

  • #18, by afrlmeWednesday, 27. March 2019, 13:37 5 years ago
    here you go.

    Imperator

    7278 Posts

  • #19, by caligarimarteWednesday, 27. March 2019, 15:25 5 years ago
    here you go.

    Thank you so much, AFRLme! smile Now I can play around with it and try to combine it with automatic Normalmap-Generation. AND in a weird Twist, I have noticed that SimonS's Script uses "graphics.getAnimationSize" but ALSO "graphics.getCharacterTextPosition" -- so, wait, is that the TextURE-Postion of the Character?? Due to a Lack of Information on it in the Lua Docs I kept thinking that it was about the Position of the Character's (spoken) Text. But if that is the Texture-Position instead, then that might help me with my initial Problem (but right now I am only guessing).

    Forum Fan

    145 Posts

  • #20, by afrlmeWednesday, 27. March 2019, 16:21 5 years ago
    I guess because the text position places it at the top-center of the active sprites canvas?

    Imperator

    7278 Posts