From OpenMW Wiki
Jump to: navigation, search

Sun glare

Actions affected During day hours
Description Rendering the sun glare overlay
Implementation status Implemented
Analysis status Needs verification

TitleCaps variables indicate values taken from the morrowind.ini section related to that object.

Glare magnitude calculation

theta = angleBetween(camera view vector, camera to sun vector) # in degrees
peakHour = Weather.SunriseHour + (Weather.SunsetHour - Weather.SunriseHour) / 2

# Angular proximity
if theta <= Weather.SunGlareFaderAngleMax:
    a = 1 - theta / Weather.SunGlareFaderAngleMax
    a = 0

# Time of day, prevents glare interfering at sunrise/sunset
if gameHour < Weather.SunriseHour or gameHour > Weather.SunsetHour:
    b = 0
elif gameHour < peakHour:
    b = 1 - (peakHour - gameHour) / (peakHour - Weather.SunriseHour)
    b = 1 - (gameHour - peakHour) / (Weather.SunsetHour - peakHour)

b *= Weather.SunGlareFaderMax

# Specific weather variables

# transition is 0 at the start of a weather change and 1.0 at the end
# note that CloudsMaximumPercent is not actually a percentage
if weather is changing and transition < nextWeather.CloudsMaximumPercent:
    t = transition / nextWeather.CloudsMaximumPercent
    c = (1-t) * currentWeather.GlareView + t * nextWeather.GlareView
    c = currentWeather.GlareView

# Occlusion
d = time-averaged visibility of sun via raycast [range: 0-1]


Blend mode: src=SRC_ALPHA, dest=ONE

Material colour = saturate(2 * Weather.SunGlareFaderColor)    # design flaw
Material alpha = a * b * c * d


There is an issue with the colour specification. The default SunGlareFaderColor is sRGB [222,095,039], which is very red compared to the actual rendering. This is due to the game setting the ambient, diffuse and emissive materials to the SunGlareFaderColor, in combination with pure white ambient lighting for this effect (but no diffuse due to lack of normals). This essentially multiplies the colour by 2, which is then clamped by the fixed function pipeline, causing a final colour of light orange.