Skip to content

Commit

Permalink
Add shadows settings, remove unused ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sisah2 committed Mar 23, 2024
1 parent f11be01 commit bdc823e
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 58 deletions.
8 changes: 0 additions & 8 deletions app/src/main/java/ui/activity/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ class GameActivity : SDLActivity() {
if (textureShrinkingOption == "medium") Os.setenv("LIBGL_SHRINK", "7", true)
if (textureShrinkingOption == "high") Os.setenv("LIBGL_SHRINK", "6", true)

val shaderDirOption = prefs!!.getString("pref_shadersDir_v2", "")
if (shaderDirOption == "modified") Os.setenv("OPENMW_SHADERS", "modified", true)
if (shaderDirOption == "zesterer") Os.setenv("OPENMW_SHADERS", "zesterer", true)

if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_nohighp", false) && shaderDirOption == "modified") {
Os.setenv("LIBGL_NOHIGHP", "1", true)
}

Os.setenv("OSG_VERTEX_BUFFER_HINT", "VBO", true)
Os.setenv("OPENMW_USER_FILE_STORAGE", Constants.USER_FILE_STORAGE + "/", true)
//Os.setenv("OSG_NOTIFY_LEVEL", "FATAL", true) //hide osg errors for now, gl4es bug.
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,19 @@ class MainActivity : AppCompatActivity() {
writeSetting("Post Processing", "soft particles", if(prefs.getBoolean("gs_soft_particles", false)) "true" else "false")
writeSetting("Post Processing", "transparent postpass", if(prefs.getBoolean("gs_transparent_postpass", false)) "true" else "false")

// Visuals Shadows
writeSetting("Shadows", "enable shadows", if(prefs.getBoolean("gs_enable_shadows", false)) "true" else "false")
writeSetting("Shadows", "object shadows", if(prefs.getBoolean("gs_object_shadows", false)) "true" else "false")
writeSetting("Shadows", "terrain shadows", if(prefs.getBoolean("gs_terrain_shadows", false)) "true" else "false")
writeSetting("Shadows", "actor shadows", if(prefs.getBoolean("gs_actor_shadows", false)) "true" else "false")
writeSetting("Shadows", "player shadows", if(prefs.getBoolean("gs_player_shadows", false)) "true" else "false")
writeSetting("Shadows", "indoor shadows", if(prefs.getBoolean("gs_indoor_shadows", true)) "true" else "false")
writeSetting("Shadows", "shadow map resolution", prefs.getString("gs_shadow_map_resolution", "1024").toString())
writeSetting("Shadows", "compute scene bounds", prefs.getString("gs_shadow_computation_method", "bounds").toString())
writeSetting("Shadows", "maximum shadow map distance", prefs.getString("gs_shadows_distance", "8192").toString())
writeSetting("Shadows", "shadow fade start", prefs.getString("gs_shadows_fade_start", "0.9").toString())
writeSetting("Shadows", "percentage closer filtering", prefs.getString("gs_shadows_pcf", "1").toString())

// Animations
writeSetting("Game", "use magic item animations", if(prefs.getBoolean("gs_use_magic_item_animation", false)) "true" else "false")
writeSetting("Game", "use additional anim sources", if(prefs.getBoolean("gs_use_additional_animation_sources", false)) "true" else "false")
Expand Down
65 changes: 64 additions & 1 deletion app/src/main/java/ui/activity/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ import android.preference.Preference
import android.preference.PreferenceFragment
import android.preference.PreferenceGroup

import constants.Constants
import android.opengl.EGL14.EGL_CONTEXT_CLIENT_VERSION
import android.opengl.EGL14.EGL_OPENGL_ES2_BIT
import android.opengl.GLES20
import javax.microedition.khronos.egl.EGL10
import javax.microedition.khronos.egl.EGL10.*
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.egl.EGLContext
import javax.microedition.khronos.egl.EGLDisplay

class FragmentGameSettings : PreferenceFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -154,7 +164,60 @@ class FragmentGameSettingsPage(val res: Int) : PreferenceFragment(), OnSharedPre
addPreferencesFromResource(res)
preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(this)

if (res == R.xml.gs_game_mechanics) findPreference("gs_always_allow_npc_to_follow_over_water_surface").isEnabled = preferenceScreen.sharedPreferences.getBoolean("gs_build_navmesh", true)
val config = intArrayOf(
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 0,
EGL_STENCIL_SIZE, 0,
EGL_NONE
)

fun chooseEglConfig(egl: EGL10, eglDisplay: EGLDisplay) : EGLConfig {
val configsCount = intArrayOf(0);
val configs = arrayOfNulls<EGLConfig>(1);
egl.eglChooseConfig(eglDisplay, config, configs, 1, configsCount)
return configs[0]!!
}

fun getExtensionList() {
val egl = EGLContext.getEGL() as EGL10
val eglDisplay = egl.eglGetDisplay(EGL_DEFAULT_DISPLAY)
egl.eglInitialize(eglDisplay, intArrayOf(0,0)) // getting OpenGL ES 2
val eglConfig = chooseEglConfig(egl, eglDisplay);
val eglContext = egl.eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, intArrayOf(EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE));

//FIXME: Create some surface to dont rely on extension
//val eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, texture_view.surfaceTexture, null)
if (egl.eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglContext) == true) {
val extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS)
File(Constants.USER_CONFIG + "/extensions.cfg").writeText(extensions.replace(" ", "\n"))

egl.eglDestroyContext(eglDisplay, eglContext)
//egl.eglDestroySurface(eglDisplay, eglSurface)

if (extensions.contains("GL_EXT_depth_clamp") == false) {
findPreference("gs_enable_shadows").isEnabled = false
findPreference("gs_object_shadows").isEnabled = false
findPreference("gs_terrain_shadows").isEnabled = false
findPreference("gs_actor_shadows").isEnabled = false
findPreference("gs_player_shadows").isEnabled = false
findPreference("gs_indoor_shadows").isEnabled = false
findPreference("gs_shadow_map_resolution").isEnabled = false
findPreference("gs_shadow_computation_method").isEnabled = false
findPreference("gs_shadows_distance").isEnabled = false
findPreference("gs_shadows_fade_start").isEnabled = false
findPreference("gs_shadows_pcf").isEnabled = false
}
}
}

if (res == R.xml.gs_visuals) getExtensionList()

// what is this?
//if (res == R.xml.gs_game_mechanics) findPreference("gs_always_allow_npc_to_follow_over_water_surface").isEnabled = preferenceScreen.sharedPreferences.getBoolean("gs_build_navmesh", true)

if (res == R.xml.gs_animations) updatePreference(preferenceScreen.sharedPreferences, "gs_use_additional_animation_sources")
if (res == R.xml.gs_engine) updatePreference(preferenceScreen.sharedPreferences, "gs_build_navmesh")
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/ui/fragments/FragmentSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,6 @@ class FragmentSettings : PreferenceFragment(), OnSharedPreferenceChangeListener
val sharedPref = preferenceScreen.sharedPreferences
findPreference("pref_gamma").isEnabled =
sharedPref.getString("pref_graphicsLibrary_v2", "") != "gles1"

var isnohighpenabled = false;
if(sharedPref.getString("pref_shadersDir_v2", "") == "modified")
isnohighpenabled = true
findPreference("pref_nohighp").isEnabled = isnohighpenabled
/*
var isAdditionalAnimSourcesEnabled = false;
if(sharedPref.getBoolean("gs_use_additional_animation_sources", false) == true) isAdditionalAnimSourcesEnabled = true
findPreference("gs_weapon_sheating").isEnabled = isAdditionalAnimSourcesEnabled
findPreference("gs_shield_sheating").isEnabled = isAdditionalAnimSourcesEnabled
*/
}

}
57 changes: 44 additions & 13 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,50 @@
<item>2</item>
</string-array>

<string-array name="gs_shadow_map_resolution_entries">
<item>512</item>
<item>1024</item>
<item>2048</item>
<item>4096</item>
</string-array>

<string-array name="gs_shadow_map_resolution_values">
<item>512</item>
<item>1024</item>
<item>2048</item>
<item>4096</item>
</string-array>

<string-array name="gs_shadow_planes_computation_method_entries">
<item>None</item>
<item>Bounds</item>
<item>Primitives</item>
</string-array>

<string-array name="gs_shadow_planes_computation_method_values">
<item>none</item>
<item>bounds</item>
<item>primitives</item>
</string-array>

<string-array name="gs_shadow_pcf_entries">
<item>Disabled</item>
<item>4 samples</item>
<item>2x2x4 samples</item>
<item>3x3x4 samples</item>
<item>4x4x4 samples</item>
<item>5x5x4 samples</item>
</string-array>

<string-array name="gs_shadow_pcf_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</string-array>

<string name="general_settings">Setup</string>
<string name="start_game_label">Start game</string>
<string name="closeDrawer">Navigation View</string>
Expand All @@ -81,7 +125,6 @@
<string name="pref_graphics">Graphics</string>
<string name="pref_commandLine">Custom command line arguments</string>
<string name="pref_envLine">Custom environment flags</string>
<string name="pref_nohighp">Medium shader precision</string>
<string name="pref_ui">User interface</string>
<string name="pref_textureShrinking">Texture shrinking</string>
<string name="pref_textureShrinking_default">none</string>
Expand Down Expand Up @@ -142,18 +185,6 @@
<item>high</item>
</string-array>

<string-array name="pref_shadersDir_entries">
<item>Original</item>
<item>Modified</item>
<item>Zesterer</item>
</string-array>

<string-array name="pref_shadersDir_values">
<item>none</item>
<item>modified</item>
<item>zesterer</item>
</string-array>

<string name="pref_physicsFPS2_default">30</string>


Expand Down
10 changes: 0 additions & 10 deletions app/src/main/res/xml/gs_animations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,4 @@
android:summary="Affects side and diagonal movement. Enabling this setting makes movement more realistic. If disabled then the whole character's body is pointed to the direction of view. Diagonal movement has no special animation and causes sliding. If enabled then the character turns lower body to the direction of movement. Upper body is turned partially. Head is always pointed to the direction of view. In combat mode it works only for diagonal movement. In non-combat mode it changes straight right and straight left movement as well. Also turns the whole body up or down when swimming according to the movement direction."/>

</PreferenceCategory>

<PreferenceCategory android:title="First person">

<CheckBoxPreference
android:key="gs_hand_inertia"
android:title="Hand Inertia"
android:summary="Causes hands to chase view direction slightly when turning, instead of matching the camera perfectly."/>

</PreferenceCategory>

</PreferenceScreen>
81 changes: 81 additions & 0 deletions app/src/main/res/xml/gs_visuals.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,85 @@

</PreferenceCategory>

<PreferenceCategory android:title="Shadows">

<CheckBoxPreference
android:key="gs_enable_shadows"
android:title="Enabled"
android:summary="Enable shadows, Require GL_EXT_depth_clamp extension."/>

<CheckBoxPreference
android:key="gs_object_shadows"
android:title="Object Shadows"
android:summary="Enable shadows for primarily inanimate objects. May have a significant performance impact."/>

<CheckBoxPreference
android:key="gs_terrain_shadows"
android:title="Terrain Shadows"
android:summary="Enable shadows for the terrain including distant terrain. May have a significant performance and shadow quality impact."/>

<CheckBoxPreference
android:key="gs_actor_shadows"
android:title="Actors Shadows"
android:summary="Enable shadows for NPCs and creatures besides the player character. May have a minor performance impact."/>

<CheckBoxPreference
android:key="gs_player_shadows"
android:title="Player Shadows"
android:summary="Enable shadows exclusively for the player character. May have a very minor performance impact."/>

<CheckBoxPreference
android:key="gs_indoor_shadows"
android:title="Indoor Shadows"
android:defaultValue="true"
android:summary="Due to limitations with Morrowind's data, only actors can cast shadows indoors, which some might feel is distracting."/>

<ListPreference
android:key="gs_shadow_map_resolution"
android:summary="%s \nThe resolution of each individual shadow map. Increasing it significantly improves shadow quality but may have a minor performance impact."
android:title="Shadow Map Resolution"
android:dialogTitle="Shadow Map Resolution"
android:entries="@array/gs_shadow_map_resolution_entries"
android:entryValues="@array/gs_shadow_map_resolution_values"
android:defaultValue="1024" />

<ListPreference
android:key="gs_shadow_computation_method"
android:summary="%s \nComputation method to be used. Bounds (default) for good balance between performance and shadow quality, primitives for better looking shadows or none for no computation"
android:title="Shadow Planes Computation Method"
android:dialogTitle="Shadow Planes Computation Method"
android:entries="@array/gs_shadow_planes_computation_method_entries"
android:entryValues="@array/gs_shadow_planes_computation_method_values"
android:defaultValue="bounds" />

<EditTextPreference
android:key="gs_shadows_distance"
android:title="Shadows Rendering Distance"
android:dialogTitle="Shadows Rendering Distance"
android:inputType="numberDecimal"
android:hint="8192"
android:defaultValue="8192"
android:summary="The distance from the camera at which shadows completely disappear."/>

<EditTextPreference
android:key="gs_shadows_fade_start"
android:title="Shadows Fade Start"
android:dialogTitle="Shadows Fade Start.\nShould be in 0.0 - 1.0 range"
android:inputType="numberDecimal"
android:hint="0.9"
android:defaultValue="0.9"
android:summary="The fraction of the limit above at which shadows begin to gradually fade away."/>

<ListPreference
android:key="gs_shadows_pcf"
android:summary="%s \nSmooth out shadows edges if small resolution is set. Higher values may have significant performance impact."
android:title="Shadows PCF Filter"
android:dialogTitle="Shadows PCF Filter"
android:entries="@array/gs_shadow_pcf_entries"
android:entryValues="@array/gs_shadow_pcf_values"
android:defaultValue="1" />


</PreferenceCategory>

</PreferenceScreen>
14 changes: 0 additions & 14 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@
android:summary="%s"
/>

<CheckBoxPreference
android:key="pref_nohighp"
android:title="@string/pref_nohighp"/>

</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_graphics">
Expand Down Expand Up @@ -122,16 +118,6 @@
android:defaultValue="@string/pref_textureShrinking_default"
android:summary="%s"
/>

<ListPreference
android:key="pref_shadersDir_v2"
android:title="@string/pref_shadersDir"
android:dialogTitle="@string/pref_shadersDir"
android:entries="@array/pref_shadersDir_entries"
android:entryValues="@array/pref_shadersDir_values"
android:defaultValue="@string/pref_shadersDir_default"
android:summary="%s"
/>
</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_advanced">
Expand Down
2 changes: 1 addition & 1 deletion buildscripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ set(LIBICU_VERSION 70-1)
set(LIBICU_HASH SHA256=4013d7aff8a34bae410664bdb16554d7eda03654b22627b9284ab55a685492d4)

# https://github.com/OpenMW/openmw/commits/master
set(OPENMW_VERSION 9da7c3861203a41d807f0725f732c8b638a5ec85)
set(OPENMW_VERSION 698d97ed3b319c0eaf3d885a2c22fadd4db5e577)
set(OPENMW_HASH SHA256=44d044ad0a5546216fe611fe92c37065bb07e2efeeeaac4f049dae03df313186)

# End of configurable options
Expand Down

0 comments on commit bdc823e

Please sign in to comment.