Shader library: Fix SH9 not working with some devices because of buggy vec3.
This commit is contained in:
parent
6d6c807ff2
commit
b4c7061fc9
5 changed files with 17 additions and 14 deletions
|
@ -79,7 +79,7 @@ template has_astc_support: bool = gl.GLAD_GL_OES_texture_compression_astc or
|
|||
const myouMinTextureChannels {.intdefine.} = 0
|
||||
const myouEngineNumTextureThreads {.intdefine.} = 4
|
||||
const myouBC7VerboseMode {.booldefine.} = false
|
||||
const myouAllCacheFilesExist {.booldefine.} = defined(myouUseAndroidAssets)
|
||||
const myouAllCacheFilesExist {.booldefine.} = false
|
||||
const myouLoadUncompressedTextures {.booldefine.} = false
|
||||
when defined(myouAllCacheFilesExist):
|
||||
import ../platform/platform
|
||||
|
|
|
@ -281,9 +281,11 @@ proc draw_mesh*(self: RenderManager, mesh: Mesh, mesh2world: Mat4, cam_data: Ren
|
|||
continue
|
||||
|
||||
var mat = if material_override == nil:
|
||||
amesh.materials.get_or_default(submesh_idx, self.no_material)
|
||||
amesh.materials.get_or_default(submesh_idx, nil)
|
||||
else:
|
||||
material_override
|
||||
if mat.isNil:
|
||||
mat = self.no_material
|
||||
|
||||
let shader {.cursor.} = mat.get_shader(mesh)
|
||||
let program = shader.use()
|
||||
|
|
|
@ -601,7 +601,7 @@ proc get_lighting_code*(self: Scene): string =
|
|||
uniform samplerCube cube_maps[MAX_CUBE_MAPS];
|
||||
#endif
|
||||
struct SH9 {
|
||||
vec3 c[9];
|
||||
vec4 c[9];
|
||||
};
|
||||
|
||||
#ifndef MAX_SPHERICAL_HARMONICS
|
||||
|
|
|
@ -286,7 +286,7 @@ vec4 principled_node(vec3 base, vec3 I, vec3 normal, vec3 pos, float metallic, f
|
|||
// these look good...
|
||||
vec3 env_specular = sample_environment(reflect(-I,N), pos, roughness) * (1.0 - roughness);
|
||||
#if MAX_SPHERICAL_HARMONICS
|
||||
vec3 env_diffuse = get_sh9(N, SH9_coefficients[0]) * 0.3;
|
||||
vec3 env_diffuse = get_sh9(N, 0) * 0.5;
|
||||
#else
|
||||
vec3 env_diffuse = sample_environment(N, pos, 1.0) * 0.1;
|
||||
#endif
|
||||
|
|
|
@ -3,18 +3,19 @@
|
|||
|
||||
#if MAX_SPHERICAL_HARMONICS
|
||||
|
||||
vec3 get_sh9(vec3 direction, SH9 sh)
|
||||
vec3 get_sh9(vec3 direction, int sh_index)
|
||||
{
|
||||
vec3 dir = SH9_rotation * direction;
|
||||
return sh.c[0] * 0.282095
|
||||
+ sh.c[1] * 0.488603 * dir.y
|
||||
+ sh.c[2] * 0.488603 * dir.z
|
||||
+ sh.c[3] * 0.488603 * dir.x
|
||||
+ sh.c[4] * 1.092548 * dir.x * dir.y
|
||||
+ sh.c[5] * 1.092548 * dir.y * dir.z
|
||||
+ sh.c[6] * 0.315392 * (3.0 * dir.z * dir.z - 1.0)
|
||||
+ sh.c[7] * 1.092548 * dir.x * dir.z
|
||||
+ sh.c[8] * 0.546274 * (dir.x * dir.x - dir.y * dir.y)
|
||||
SH9 sh = SH9_coefficients[0];
|
||||
return sh.c[0].rgb * 0.282095
|
||||
+ sh.c[1].rgb * 0.488603 * dir.y
|
||||
+ sh.c[2].rgb * 0.488603 * dir.z
|
||||
+ sh.c[3].rgb * 0.488603 * dir.x
|
||||
+ sh.c[4].rgb * 1.092548 * dir.x * dir.y
|
||||
+ sh.c[5].rgb * 1.092548 * dir.y * dir.z
|
||||
+ sh.c[6].rgb * 0.315392 * (3.0 * dir.z * dir.z - 1.0)
|
||||
+ sh.c[7].rgb * 1.092548 * dir.x * dir.z
|
||||
+ sh.c[8].rgb * 0.546274 * (dir.x * dir.x - dir.y * dir.y)
|
||||
;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue