Skip to content

Commit

Permalink
Fixed fire billboard shader, work on Adal scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Timbles committed Mar 13, 2024
1 parent 5eb22fa commit a319230
Show file tree
Hide file tree
Showing 119 changed files with 65,762 additions and 405 deletions.
8 changes: 8 additions & 0 deletions Data/LevelNavmeshes/nothing.nav.xml
@@ -0,0 +1,8 @@
<?xml version="2.0" ?>
<NavMeshMeta>
<Level>nothing</Level>
<IgnoreHash>false</IgnoreHash>
<LevelHash>9c8611dc5c337cb2d0e0edc5b1d7928e</LevelHash>
<IgnoreVersion>false</IgnoreVersion>
<Version>1</Version>
</NavMeshMeta>
Binary file added Data/LevelNavmeshes/nothing.nav.zip
Binary file not shown.
8 changes: 8 additions & 0 deletions Data/LevelNavmeshes/ouruin/level1_b.nav.xml
@@ -0,0 +1,8 @@
<?xml version="2.0" ?>
<NavMeshMeta>
<Level>level1_b</Level>
<IgnoreHash>false</IgnoreHash>
<LevelHash>948f250f7ff67147709b0dbdfa41b631</LevelHash>
<IgnoreVersion>false</IgnoreVersion>
<Version>1</Version>
</NavMeshMeta>
Binary file added Data/LevelNavmeshes/ouruin/level1_b.nav.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion Data/LevelNavmeshes/ouruin/level1_explore.nav.xml
Expand Up @@ -2,7 +2,7 @@
<NavMeshMeta>
<Level>level1_explore</Level>
<IgnoreHash>false</IgnoreHash>
<LevelHash>ab41458c2157f2587d516866520bf417</LevelHash>
<LevelHash>157561f0efca5b977921133802af3cd</LevelHash>
<IgnoreVersion>false</IgnoreVersion>
<Version>1</Version>
</NavMeshMeta>
Binary file modified Data/LevelNavmeshes/ouruin/level1_explore.nav.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
34 changes: 22 additions & 12 deletions Data/Mods/constance_ouruin/Data/GLSL/fire_billboard.frag
Expand Up @@ -7,18 +7,28 @@ uniform vec3 cam_pos;
uniform sampler2D tex1; // Fire noise texture.
uniform sampler2D tex17; // Screen texture

const int kMaxInstances = 100;

struct Instance {
mat4 model_mat;
mat3 model_rotation_mat;
vec4 color_tint;
vec4 detail_scale;
};

uniform InstanceInfo {
Instance instances[kMaxInstances];
};
#if !defined(ATTRIB_ENVOBJ_INSTANCING)
#if defined(UBO_BATCH_SIZE_8X)
const int kMaxInstances = 256 * 8;
#elif defined(UBO_BATCH_SIZE_4X)
const int kMaxInstances = 256 * 4;
#elif defined(UBO_BATCH_SIZE_2X)
const int kMaxInstances = 256 * 2;
#else
const int kMaxInstances = 256 * 1;
#endif

struct Instance {
vec3 model_scale;
vec4 model_rotation_quat;
vec4 color_tint;
vec4 detail_scale; // TODO: DETAILMAP4 only?
};

uniform InstanceInfo {
Instance instances[kMaxInstances];
};
#endif

uniform mat4 projection_view_mat;

Expand Down
105 changes: 78 additions & 27 deletions Data/Mods/constance_ouruin/Data/GLSL/fire_billboard.vert
Expand Up @@ -3,18 +3,78 @@

#include "lighting150.glsl"

const int kMaxInstances = 100;
vec3 quat_mul_vec3(vec4 q, vec3 v) {
// Adapted from https://github.com/g-truc/glm/blob/master/glm/detail/type_quat.inl
// Also from Fabien Giesen, according to - https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/
vec3 quat_vector = q.xyz;
vec3 uv = cross(quat_vector, v);
vec3 uuv = cross(quat_vector, uv);
return v + ((uv * q.w) + uuv) * 2;
}

vec3 transform_vec3(vec3 scale, vec4 rotation_quat, vec3 translation, vec3 value) {
vec3 result = scale * value;
result = quat_mul_vec3(rotation_quat, result);
result += translation;
return result;
}

struct Instance {
mat4 model_mat;
mat3 model_rotation_mat;
vec4 color_tint;
vec4 detail_scale;
};
#if !defined(ATTRIB_ENVOBJ_INSTANCING)
#if defined(UBO_BATCH_SIZE_8X)
const int kMaxInstances = 256 * 8;
#elif defined(UBO_BATCH_SIZE_4X)
const int kMaxInstances = 256 * 4;
#elif defined(UBO_BATCH_SIZE_2X)
const int kMaxInstances = 256 * 2;
#else
const int kMaxInstances = 256 * 1;
#endif

uniform InstanceInfo {
Instance instances[kMaxInstances];
};
struct Instance {
vec3 model_scale;
vec4 model_rotation_quat;
vec4 color_tint;
vec4 detail_scale; // TODO: DETAILMAP4 only?
};

uniform InstanceInfo {
Instance instances[kMaxInstances];
};
#endif

vec3 GetInstancedModelScale(int instance_id) {
#if defined(ATTRIB_ENVOBJ_INSTANCING)
return model_scale_attrib;
#else
return instances[instance_id].model_scale;
#endif
}

vec4 GetInstancedModelRotationQuat(int instance_id) {
#if defined(ATTRIB_ENVOBJ_INSTANCING)
return model_rotation_quat_attrib;
#else
return instances[instance_id].model_rotation_quat;
#endif
}

vec4 GetInstancedColorTint(int instance_id) {
#if defined(ATTRIB_ENVOBJ_INSTANCING)
return color_tint_attrib;
#else
return instances[instance_id].color_tint;
#endif
}

#if defined(DETAILMAP4)
vec4 GetInstancedDetailScale(int instance_id) {
#if defined(ATTRIB_ENVOBJ_INSTANCING)
return detail_scale_attrib;
#else
return instances[instance_id].detail_scale;
#endif
}
#endif

uniform sampler2D tex1; // Fire noise texture.

Expand All @@ -30,14 +90,14 @@ out mat3 tangent_to_world;
out vec3 world_vert;
out vec3 model_position;
flat out int instance_id;
in vec3 model_translation_attrib; // set per-instance. separate from rest because it's not needed in the fragment shader, so is not slow on low-end GPUs

in vec3 vertex_attrib;
in vec2 tex_coord_attrib;

void main() {
instance_id = gl_InstanceID;

mat4 modelViewMatrix = instances[instance_id].model_mat;
vec3 position = vertex_attrib;

frag_tex_coords = tex_coord_attrib;
Expand All @@ -48,7 +108,7 @@ void main() {
float vertical_speed = 0.5;

vec4 noise_tex = texture(tex1, tex_coord + vec2(time * horizontal_speed, time * vertical_speed));
vec3 model_scale = vec3(length(modelViewMatrix[0]), length(modelViewMatrix[1]), length(modelViewMatrix[2]));
vec3 model_scale = GetInstancedModelScale(instance_id);
float height = frag_tex_coords.y;

// Move the vertices towards the middle of the model based on height to make it pointy.
Expand All @@ -60,7 +120,8 @@ void main() {
position.y += (noise_tex.r - 0.25) * 0.75 * min(1.0, height * 3.0);

// The model world position of the center of the object
vec3 model_position = (modelViewMatrix * vec4(vec3(0.0), 1.0)).xyz;
model_position = model_translation_attrib;
vec4 rotation_quat = GetInstancedModelRotationQuat(instance_id);

#if defined(BILLBOARD)
// Distance between the camera and the center.
Expand All @@ -81,21 +142,11 @@ void main() {
// The position of the vertex after the rotation.
position = rotMatrix * position;

// The model matrix without the rotation.
modelViewMatrix[0][0] = model_scale.x;
modelViewMatrix[0][1] = 0;
modelViewMatrix[0][2] = 0;

modelViewMatrix[1][0] = 0;
modelViewMatrix[1][1] = model_scale.y;
modelViewMatrix[1][2] = 0;

modelViewMatrix[2][0] = 0;
modelViewMatrix[2][1] = 0;
modelViewMatrix[2][2] = model_scale.z;
// Use an empty rotation quat when it's a billboard.
rotation_quat = vec4(0.0, 0.0, 0.0, 1.0);
#endif

vec4 transformed_vertex = modelViewMatrix * vec4(position, 1.0);
vec3 transformed_vertex = transform_vec3(GetInstancedModelScale(instance_id), rotation_quat, model_translation_attrib, position);
world_vert = transformed_vertex.xyz;
gl_Position = projection_view_mat * transformed_vertex;
gl_Position = projection_view_mat * vec4(transformed_vertex, 1.0);
}

0 comments on commit a319230

Please sign in to comment.