Skip to content

Commit

Permalink
Merge branch 'main' into ouruin
Browse files Browse the repository at this point in the history
  • Loading branch information
Timbles committed Mar 10, 2024
2 parents 9cfd46d + c754100 commit 724c4a0
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 32 deletions.
11 changes: 10 additions & 1 deletion Data/GLSL/envobject.frag
Expand Up @@ -319,6 +319,10 @@ in vec3 world_vert;
#elif defined(CHARACTER)
in vec2 fur_tex_coord;

#if defined(TANGENT)
in mat3 tan_to_obj;
#endif

#if !defined(DEPTH_ONLY)
in vec3 concat_bone1;
in vec3 concat_bone2;
Expand Down Expand Up @@ -2460,7 +2464,12 @@ void main() {

// Get world space normal
vec4 normalmap = texture(normal_tex, tex_coord + tex_offset);
vec3 unrigged_normal = UnpackObjNormal(normalmap);
#if defined(TANGENT)
vec3 unpacked_normal = UnpackTanNormal(normalmap);
vec3 unrigged_normal = tan_to_obj * unpacked_normal;
#else
vec3 unrigged_normal = UnpackObjNormal(normalmap);
#endif
vec3 ws_normal = normalize(concat_bone1 * unrigged_normal.x +
concat_bone2 * unrigged_normal.y +
concat_bone3 * unrigged_normal.z);
Expand Down
14 changes: 14 additions & 0 deletions Data/GLSL/envobject.vert
Expand Up @@ -37,6 +37,12 @@ in vec2 tex_coord_attrib;
in vec3 normal_attrib;
#elif defined(SKY)
#elif defined(CHARACTER)
#ifdef TANGENT
in vec3 tangent_attrib;
in vec3 bitangent_attrib;
in vec3 normal_attrib;
#endif

in vec2 morph_tex_offset_attrib;
in vec2 fur_tex_coord_attrib;

Expand Down Expand Up @@ -278,6 +284,10 @@ out vec3 world_vert;
#elif defined(CHARACTER)
out vec2 fur_tex_coord;

#ifdef TANGENT
out mat3 tan_to_obj;
#endif

#ifndef DEPTH_ONLY
out vec3 concat_bone1;
out vec3 concat_bone2;
Expand Down Expand Up @@ -884,6 +894,10 @@ void main() {

#endif // GPU_SKINNING

#if defined(TANGENT)
tan_to_obj = mat3(tangent_attrib, bitangent_attrib, normal_attrib);
#endif

vec3 transformed_vertex = (concat_bone * vec4(vertex_attrib, 1.0)).xyz;

mat4 projection_view_mat = mvp;
Expand Down
4 changes: 2 additions & 2 deletions Docs/Markdown/Asset Spawner and Editor.md
Expand Up @@ -7,7 +7,7 @@ So it would be really cool I think if all of that could be done from within the

Since objects are taken straight from their folders instead of being hard coded in, we can use a folder tree as a quick and easy way to filter objects. If you click one of the folders in the tree, all objects in that folder and all its sub-folders are displayed on the right side.

![Mockup of browser](/item-spawner-editor-mockup.png)
![Mockup of browser](img/item-spawner-editor-mockup.png)

## Structure
There is a tab based interface like in the current spawner. Each tab is created by creating an XML file in a specific directory. This XML file specifies the following.
Expand Down Expand Up @@ -130,7 +130,7 @@ This eliminates the need to manually fill the spawn menu with items, which is an
### Editor mode
In this mode you can see all tabs, including those that contain XML files that cannot be spawned, such as levels and particle XMLs. If you click an item in this mode a new window opens up for that item where you can edit the elements that have been specified in the settings for this tab. A button can be pressed to open up elements that have not been specified in that XML for editing, just in case you want to edit something that is very uncommon to edit.

![mockup of xml editor](/xml-editor.png)
![mockup of xml editor](img/xml-editor.png)

## Mod support
It should be built with mods in mind, meaning it also looks for items in the same folders in mods as well. There should be a button in the browser that brings up a menu where you can choose what mods you want to display content from (including the main game).
14 changes: 7 additions & 7 deletions Docs/Markdown/Compiling Overgrowth on modern OS X.md
Expand Up @@ -33,7 +33,7 @@ to avoid having to manually change the Base SDK in Xcode.

So Configure to use Xcode and then generate into your choice of build directory.

![CMake GUI](/img/OSXCMake/1-OSXCMake-CMake.png)
![CMake GUI](img/OSXCMake/1-OSXCMake-CMake.png)

Now the fun begins.

Expand All @@ -43,15 +43,15 @@ Now the fun begins.

2. We need to change the target to Overgrowth as it'll build a bunch of superfluous projects instead.

![Change Target](/img/OSXCMake/2-OSXCMake-Target.png)
![Change Target](img/OSXCMake/2-OSXCMake-Target.png)

3. Note that by default it'll compile Debug, so you may want to change this to Release. To bring up scheme quickly hit **command-<**.

![alt text](/img/OSXCMake/3-OSXCMake-Release.png)
![alt text](img/OSXCMake/3-OSXCMake-Release.png)

4. If we built at this point we'd have a whole bunch of strange errors. Since the project CMake generates may as well have been written on cuneiform tablets from the point of view of Xcode, we have to update the project. First select the Overgrowth project from the lefthand column (or the menu item won't appear) and select **Editor|Validate Settings**. It'll present a long list of proposed changes -- accept them.

![Validate Settings](/img/OSXCMake/5-OSXCMake-Validate.png)
![Validate Settings](img/OSXCMake/5-OSXCMake-Validate.png)

5. Now we have to undo some of what the previous step did. Select the Overgrowth project from the lefthand column (**Project Navigator**). Again, select the the **Overgrowth** project from the lefthand column of the center pane and then change the view to **Combined**. Change the **Architectures** to **32-bit Intel (i386)** and for good measure remove **x86**64** from the **Valid Architectures. In order to remove another dumb bit of CMake screwup change the **Base SDK** to **Latest OS X**. If you added the Cmake command line option above this should not be necessary.
Don't worry about this restricting your build to the latest OS, Apple has changed the way the platform SDKs work. All the supported SDKs have been amalgamated. The actual OS X version is determined below by changing **OS X Deployment Target** in the **Deployment** section (this will default to 10.6). (Note that this is new in Xcode 7 -- things are a bit simpler in Xcode 6).
Expand All @@ -62,15 +62,15 @@ If you hit Build at this point -- you should get a successful compile. In order

1. First set we need to set a custom Working Directory. This is set in the scheme (again **command-<**). Under **Options** find **Working Directory** and select the root of Overgrowth Data folder (the one currently in Dropbox).

![Change Working Directory](/img/OSXCMake/7-OSXCMake-Working Directory.png)
![Change Working Directory](img/OSXCMake/7-OSXCMake-Working%20Directory.png)

2. Now for the biggest hack. Still in the scheme go back to **Info** and look at executable. This **looks** like it's the Overgrowth executable, but this is the one that's built original, not the one that CMake's custom scripts move into the application bundle. So we need to point this at the executable in the bundle. The annoying part is that we can't **Show Package Contents** in the selection dialog box -- so we need to work around this somehow. Go into finder, go to the Release directory in the root of your build directory. Assuming you've built the application you should see two executables and the actual app bundle. Right click and **Show Package Contents** and go into Contents and then (temporarily) drag the MacOS folder to Finder sidebar.

![Finder Hack](/img/OSXCMake/8-OSXCMake-Finder.png)
![Finder Hack](img/OSXCMake/8-OSXCMake-Finder.png)

3. Back in Xcode with scheme and **Info** and under **Executable** scroll down till you find **Other...**. A selection window will come up and you show the sidebar (if you need to) to find the MacOS folder from the last step. Selecting this will show inside the bundle and **now** you can select the overgrowth executable.

![Change Executable](/img/OSXCMake/9-OSXCMake-Executable.png)
![Change Executable](img/OSXCMake/9-OSXCMake-Executable.png)

4. Finally, if you haven't done so go to **/Users/*<username>*/Library/Application Support/Overgrowth** and fill in the **extra_data_path** in config.txt to be the root of your *source* directory (i.e. the one from git). On my system this is:

Expand Down
16 changes: 8 additions & 8 deletions Docs/Markdown/Technical Documentation.md
@@ -1,8 +1,8 @@
* [Compiling Overgrowth on modern OS X]()
* [Mod Loading Design]()
* [Logging Utility Design]()
* [Handling JSON]()
* [Decal Texture Atlas]()
* [Deployment Assistant]()
* [Level Format]()
* [Thoughts on How The AI Moves Around]()
* [Compiling Overgrowth on modern OS X](Compiling%20Overgrowth%20on%20modern%20OS%20X.md)
* [Mod Loading Design](Mod%20Loading%20Design.md)
* [Logging Utility Design](Logging%20Utility%20Design.md)
* [Handling JSON](Handling%20JSON.md)
* [Decal Texture Atlas](Decal%20Texture%20Atlas.md)
* [Deployment Assistant](Deployment%20Assistant.md)
* [Level Format](Level%20Format.md)
* [Thoughts on How The AI Moves Around](Thoughts%20on%20How%20The%20AI%20Moves%20Around.md)
4 changes: 4 additions & 0 deletions Source/Main/scenegraph.cpp
Expand Up @@ -666,6 +666,7 @@ void SceneGraph::Draw(SceneGraph::SceneDrawType scene_draw_type) {
batch_start = i;
}
}
EnvObject::AfterDrawInstances();
for (auto current : detail_objects_surfaces_to_draw) {
current.draw_owner->DrawDetailObjectInstances(current.instance_array, current.num_instances, Object::kFullDraw);
}
Expand Down Expand Up @@ -698,6 +699,7 @@ void SceneGraph::Draw(SceneGraph::SceneDrawType scene_draw_type) {
batch_start = i;
}
}
EnvObject::AfterDrawInstances();
}
PROFILER_LEAVE(g_profiler_ctx);
PROFILER_LEAVE(g_profiler_ctx);
Expand Down Expand Up @@ -820,6 +822,7 @@ void SceneGraph::Draw(SceneGraph::SceneDrawType scene_draw_type) {
// Avoid calling EnvObject::Draw repeatedly, so matrices etc can be shared instead of reacquired for every draw call
// TODO: last_ofr_is_valid is set to false in EnvObject::Draw - is it important?
obj.DrawInstances(&visible_static_meshe, 1, proj_view_mat, prev_proj_view_mat, &shadow_matrix, cam_pos, Object::kFullDraw);
EnvObject::AfterDrawInstances();
obj.DrawDetailObjectInstances(&visible_static_meshe, 1, Object::kFullDraw);
}
}
Expand Down Expand Up @@ -1765,6 +1768,7 @@ void SceneGraph::DrawDepthMap(const mat4& proj_view_matrix, const vec4* cull_pla
batch_start = i;
}
}
EnvObject::AfterDrawInstances();
if (object_draw_type != Object::kDrawDepthOnly) {
// Batch and draw detail objects
static std::vector<DetailObjectSurfaceDrawCall> detail_objects_surfaces_to_draw;
Expand Down
48 changes: 40 additions & 8 deletions Source/Objects/envobject.cpp
Expand Up @@ -82,6 +82,8 @@
#include <cmath>
#include <sstream>

#define AVOID_DRAW_INSTANCES_CLEANUP_OVERHEAD

extern Timer game_timer;
extern char* global_shader_suffix;
extern bool g_simple_shadows;
Expand All @@ -107,6 +109,7 @@ extern bool g_debug_runtime_disable_env_object_pre_draw_camera;
bool last_ofr_is_valid = false;
std::string last_ofr_shader_name;
int last_shader;
bool last_enable_alpha_to_coverage = false;

struct EnvObjectGLState {
GLState gl_state;
Expand Down Expand Up @@ -230,6 +233,7 @@ void EnvObject::Draw() {
}
last_ofr_is_valid = false;
DrawInstances(instances, 1, proj_view_mat, prev_proj_view_mat, &shadow_matrix, cam_pos, Object::kFullDraw);
AfterDrawInstances();
DrawDetailObjectInstances(instances, 1, Object::kFullDraw);
}

Expand Down Expand Up @@ -443,6 +447,8 @@ static void SetupAttribPointers(bool shader_changed, Model* model, VBORingContai
}
}

void AfterDrawInstancesImpl();

void EnvObject::DrawInstances(EnvObject** instance_array, int num_instances, const mat4& proj_view_matrix, const mat4& prev_proj_view_matrix, const std::vector<mat4>* shadow_matrix, const vec3& cam_pos, Object::DrawType type) {
if (g_debug_runtime_disable_env_object_draw_instances) {
return;
Expand Down Expand Up @@ -499,9 +505,18 @@ void EnvObject::DrawInstances(EnvObject** instance_array, int num_instances, con
}
graphics->setGLState(gl_state);

if (graphics->use_sample_alpha_to_coverage && !transparent) {
glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
if (graphics->use_sample_alpha_to_coverage) {
bool enable_alpha_to_coverage = !transparent;
if (last_enable_alpha_to_coverage != enable_alpha_to_coverage) {
if (enable_alpha_to_coverage) {
glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
} else {
glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
}
}
last_enable_alpha_to_coverage = enable_alpha_to_coverage;
}

PROFILER_LEAVE(g_profiler_ctx); // GL State

static int ubo_batch_size_multiplier = 1;
Expand Down Expand Up @@ -858,6 +873,26 @@ void EnvObject::DrawInstances(EnvObject** instance_array, int num_instances, con
}
}

#if !defined(AVOID_DRAW_INSTANCES_CLEANUP_OVERHEAD)
AfterDrawInstancesImpl();
#endif

last_ofr_is_valid = ofr.valid();
if (last_ofr_is_valid) {
last_ofr_shader_name = ofr->shader_name;
}
}

void EnvObject::AfterDrawInstances() {
#if defined(AVOID_DRAW_INSTANCES_CLEANUP_OVERHEAD)
AfterDrawInstancesImpl();
#endif
}

void AfterDrawInstancesImpl() {
Graphics* graphics = Graphics::Instance();
bool attrib_envobj_instancing = g_attrib_envobj_intancing_support && g_attrib_envobj_intancing_enabled;

graphics->ResetVertexAttribArrays();
graphics->BindArrayVBO(0);
graphics->BindElementVBO(0);
Expand All @@ -869,13 +904,9 @@ void EnvObject::DrawInstances(EnvObject** instance_array, int num_instances, con
}
}

if (graphics->use_sample_alpha_to_coverage) {
if (graphics->use_sample_alpha_to_coverage && last_enable_alpha_to_coverage) {
glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
}

last_ofr_is_valid = ofr.valid();
if (last_ofr_is_valid) {
last_ofr_shader_name = ofr->shader_name;
last_enable_alpha_to_coverage = false;
}
}

Expand Down Expand Up @@ -971,6 +1002,7 @@ void EnvObject::DrawDepthMap(const mat4& proj_view_matrix, const vec4* cull_plan
}
last_ofr_is_valid = false;
DrawInstances(instances, 1, proj_view_matrix, proj_view_matrix, &shadow_matrix, cam_pos, draw_type);
AfterDrawInstances();
}

void EnvObject::SetEnabled(bool val) {
Expand Down
1 change: 1 addition & 0 deletions Source/Objects/envobject.h
Expand Up @@ -148,6 +148,7 @@ class EnvObject : public Object {
// Drawing
void Draw() override;
void DrawInstances(EnvObject **instance_array, int num_instances, const mat4 &proj_view_matrix, const mat4 &prev_proj_view_matrix, const std::vector<mat4> *shadow_matrix, const vec3 &cam_pos, Object::DrawType type);
static void AfterDrawInstances();
bool HasDetailObjectSurfaces() const { return !detail_object_surfaces.empty(); }
void DrawDetailObjectInstances(EnvObject **instance_array, int num_instances, Object::DrawType type);
void PreDrawCamera(float curr_game_time) override;
Expand Down

0 comments on commit 724c4a0

Please sign in to comment.