Skip to content

Commit

Permalink
Adjustments for using textures with tile 2d arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
KillzXGaming committed Nov 18, 2023
1 parent 0841898 commit a113aaa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
16 changes: 12 additions & 4 deletions Fushigi/gl/Bfres/BfresMaterialRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,24 @@ public void Render(GL gl, BfresRender renderer, BfresRender.BfresModel model, Sy

int unit_slot = 2;

bool isTile = false;

for (int i = 0; i < this.Material.Samplers.Count; i++)
{
var sampler = this.Material.Samplers.GetKey(i);
var texName = this.Material.Textures[i];

string varying = "";
string sampler_usage = "";
string uniform = "";

switch (sampler)
{
case "_a0":
varying = "hasAlbedoMap";
sampler_usage = "hasAlbedoMap";
uniform = "albedo_texture";
break;
case "_n0":
varying = "hasNormalMap";
sampler_usage = "hasNormalMap";
uniform = "normal_texture";
break;
}
Expand All @@ -80,7 +82,13 @@ public void Render(GL gl, BfresRender renderer, BfresRender.BfresModel model, Sy
var tex = TryBindTexture(gl, renderer, texName);
if (tex != null)
{
Shader.SetUniform(varying, 1);
if (tex.Target == TextureTarget.Texture2DArray)
{
sampler_usage += "Array"; //add array suffix used in shader
uniform += "_array";
}

Shader.SetUniform(sampler_usage, 1);
Shader.SetTexture(uniform, tex, unit_slot);
unit_slot++;
}
Expand Down
2 changes: 1 addition & 1 deletion Fushigi/gl/Bfres/BfresTextureRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Load(BntxTexture texture)

TextureState = State.Decoded;

//This clears any resources and frees memory from thread.
//This clears any resources.
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Expand Down
44 changes: 23 additions & 21 deletions Fushigi/res/shaders/Bfres.frag
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ in vec3 Normals;
in vec4 Tangents;

uniform int hasAlbedoMap;
uniform int hasAlbedoMapArray;

uniform int hasNormalMap;
uniform int hasEmissiveMap;
uniform int hasNormalMapArray;

uniform int hasAlphaMaskMap;
uniform int hasAlphaMaskMapArray;

uniform int hasMixMap;
uniform int hasMixMapArray;

uniform int hasEmissiveMap;

uniform vec4 const_color0;

Expand All @@ -18,10 +26,10 @@ uniform sampler2D alpha_mask_texture;
uniform sampler2D mix_texture;

//Array types for tiles
uniform sampler2DArray albedo_array_texture;
uniform sampler2DArray normal_array_texture;
uniform sampler2DArray alpha_mask_array_texture;
uniform sampler2DArray mix_array_texture;
uniform sampler2DArray albedo_texture_array;
uniform sampler2DArray normal_texture_array;
uniform sampler2DArray alpha_mask_texture_array;
uniform sampler2DArray mix_texture_array;

uniform int is_terrain_tile;
uniform int tile_id;
Expand Down Expand Up @@ -78,24 +86,18 @@ void main()

vec4 albedo = vec4(1.0);
vec3 normals = Normals;
vec3 coords_tile = vec3(TexCoords0, tile_id);

//Sampler data
if (is_terrain_tile == 1)
{
vec3 coords = vec3(TexCoords0, tile_id);
if (hasAlbedoMap == 1)
albedo = CalculateAlbedo(texture(albedo_array_texture, coords).rgba);
}
else
{
if (hasAlbedoMap == 1)
albedo = CalculateAlbedo(texture(albedo_texture, TexCoords0).rgba);
if (hasNormalMap == 1)
{
vec4 normal_map = texture(normal_texture, TexCoords0).rgba;
normals = CalcNormalMap(Normals, normal_map.xy);
}
}
if (hasAlbedoMap == 1)
albedo = CalculateAlbedo(texture(albedo_texture, TexCoords0).rgba);
else if (hasAlbedoMapArray == 1)
albedo = CalculateAlbedo(texture(albedo_texture_array, coords_tile).rgba);

if (hasNormalMap == 1)
normals = CalcNormalMap(Normals, texture(normal_texture, TexCoords0).rg);
else if (hasNormalMapArray == 1)
normals = CalcNormalMap(Normals, texture(normal_texture_array, coords_tile).rg);

float halfLambert = dot(difLightDirection, normals) * 0.5 + 0.5;

Expand Down

0 comments on commit a113aaa

Please sign in to comment.