Reversing Morrowind's formulas

Everything about development and the OpenMW source code.
User avatar
Hrnchamd
Posts: 64
Joined: 11 Aug 2012, 00:48

Re: Reversing Morrowind's formulas

Post by Hrnchamd »

scrawl wrote: Someone just brought to my attention a problem with the persuasion mechanics - in vanilla MW, an increase in Speechcraft results in more disposition change per attempt. Though with the formula on the wiki, the maximum change is capped by iPerMinChance:

Code: Select all

target1 = max(iPerMinChance, target1)
I presume this should be a min?
The target* variables are fine, higher targets mean a higher chance of succeeding a roll (success if roll <= target*). The problem is in the implementation.

I am guilty of not making it totally clear, but the npcRating variables are supposed to be using terms calculated with NPC stats. mwmechanics npcRatings reuse the player terms and player stats when it should all be NPC terms and stats (no strange stats bugs in that part).
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Reversing Morrowind's formulas

Post by scrawl »

the npcRating variables are supposed to be using terms calculated with NPC stats. mwmechanics npcRatings reuse the player terms and player stats when it should all be NPC terms and stats (no strange stats bugs in that part).
Ouch, good find. I can't remember if I deliberately implemented it like that or was it just a typo.
All fixed now, sorry for the false alarm.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Reversing Morrowind's formulas

Post by scrawl »

We're having an issue with the sleep interruption mechanic.

Consider fSleepRandMod = 0.25 (default), hoursToRest = 24

The wiki says:
x = roll hoursRested // int [0, 23]
y = fSleepRandMod * hoursRested // 0.25 * 24 = 6.0
if x > y: // if roll(24) > 6.0
# interrupt sleep

A creature would spawn with a 17/24 (~70%) chance.

However, from tests in MW the chance seems more like 25%.

I usually wouldn't question your research based on RNG results, but I've slept maybe 40 times and a user confirmed it too, so you might want to double check this.

Edit: solved, see viewtopic.php?f=6&t=2891&start=50#p34612
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Reversing Morrowind's formulas

Post by scrawl »

I am trying to implement the full screen glare effect that is visible when looking directly at the sun.

The relevant ini settings are:

Code: Select all

[Weather]
Sun Glare Fader Max=0.5
Sun Glare Fader Angle Max=30.0
Sun Glare Fader Color=222,095,039
The effect appears to be implemented as an additive full screen quad with a solid color.

My first guess was to use a color of Sun Glare Fader Color * Sun Glare Fader Max, then scale that linearly based on the angle to the sun. That doesn't look correct at all. It's way too bright and too red as well.

I was wondering if it's a gamma correction issue, so I implemented gamma correction and the results are a little better, but still not correct. It's still slightly too bright, and the color tone is slightly off as well. I played around with the gamma value a bit (currently 2.2) but couldn't find one that's any better.

Code: Select all

            const float sunGlareFaderMax = 0.5f;
            float fade = value * sunGlareFaderMax;
            const float gamma = 2.2;
            fade = pow(fade, gamma); // gamma correction

            sunGlareFaderColor *= fade; // do fading in linear space

            for (int i=0; i<4; ++i)
                sunGlareFaderColor[i] = std::pow(sunGlareFaderColor[i], 1.0/gamma); // back to gamma space

            mat->setEmission(osg::Material::FRONT_AND_BACK, sunGlareFaderColor);
By taking two vanilla screenshots (with and without the glare), loading those into GIMP then setting the second layer to Difference mode I determined the effective color addition in vanilla to be: (60, 45, 18
). The color I have in OpenMW right now with the above formula is (120, 81, 54).
suntest8.png
I changed the Sun Glare Fader Color to full white, then repeated the process. The resulting difference (from a shot with no glare) was gray, so I don't suppose that any other colors are coming into play here.

Any insight on how these INI settings are supposed to be used would be very helpful.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Reversing Morrowind's formulas

Post by scrawl »

Update:

I finally found the respective node in the Morrowind scene graph (it's under Morrowind Menu Scene Graph, for some reason). The color from the INI is being set on the ambient, diffuse and emissive properties, rather than just on emissive as you would expect. That is probably why there's less red in the resulting color on screen: the fixed pipeline is clamping the lighting to a total of (255,255,255). With the default color, the red component would hit this limit, the other components don't.

Also to note that the fading mechanism is using a material alpha value with the blending mode being set to SRC_ALPHA,ONE, rather than premultiplying the alpha value onto the lighting color and then simply using an additive blend of ONE,ONE (which would affect the light clamping discussed above).

The alpha value set is not exactly the Sun Glare Fader Max (0.26 when you look directly at the sun), but Sun Glare Fader Max does appear related to this alpha value. Hrnchamd is looking into the exact formula.
Post Reply