From 2ad1385fb495d8c24534fe1e38853b680dd3a3d3 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Mon, 23 Mar 2020 18:45:25 -0500 Subject: [PATCH] Fixed NVIDIA renderering errors, use 'flat in/out int integerValue' instead of 'in/out float integerValue' --- lib/renderer/opengl_renderer.rb | 2 +- shaders/fragment/default.glsl | 12 +++++++----- shaders/vertex/default.glsl | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/renderer/opengl_renderer.rb b/lib/renderer/opengl_renderer.rb index 4964df9..372c033 100644 --- a/lib/renderer/opengl_renderer.rb +++ b/lib/renderer/opengl_renderer.rb @@ -25,7 +25,7 @@ class IMICFPS shader.uniform_vec3("lights[#{i}].specular", light.specular) end - shader.uniform_float("totalLights", lights.size) + shader.uniform_integer("totalLights", lights.size) entities.each do |entity| next unless entity.visible && entity.renderable diff --git a/shaders/fragment/default.glsl b/shaders/fragment/default.glsl index 6dee361..3b2bd94 100644 --- a/shaders/fragment/default.glsl +++ b/shaders/fragment/default.glsl @@ -2,17 +2,19 @@ @include "light_struct" +layout(location = 0) out vec4 fragColor; + in vec3 outPosition; in vec3 outColor; in vec3 outNormal; in vec3 outUV; in float outTextureID; -in float outHasTexture; in Light outLights[MAX_LIGHTS]; -in float outTotalLights; +flat in int outTotalLights; in vec3 outFragPos; in vec3 outCameraPos; -in float outDisableLighting; +flat in int outHasTexture; +flat in int outDisableLighting; uniform sampler2D diffuse_texture; @@ -64,7 +66,7 @@ vec3 calculateBasicLight(Light light) { vec3 calculateLighting() { vec3 result = vec3(0.0, 0.0, 0.0); - for (int i = 0; i < min(int(outTotalLights), MAX_LIGHTS); i++) { + for (int i = 0; i < min(outTotalLights, MAX_LIGHTS); i++) { if (int(outLights[i].type) == 0) { result += calculateBasicLight(outLights[i]); } else if (int(outLights[i].type) == 1) { @@ -96,5 +98,5 @@ void main() { } } - gl_FragColor = vec4(result, 1.0); + fragColor = vec4(result, 1.0); } diff --git a/shaders/vertex/default.glsl b/shaders/vertex/default.glsl index 2ae3eea..f864df6 100644 --- a/shaders/vertex/default.glsl +++ b/shaders/vertex/default.glsl @@ -13,19 +13,19 @@ out vec3 outColor; out vec3 outNormal; out vec3 outUV; out float outTextureID; -out float outHasTexture; out Light outLights[MAX_LIGHTS]; -out float outTotalLights; +flat out int outTotalLights; out vec3 outFragPos; out vec3 outViewPos; out vec3 outCameraPos; -out float outDisableLighting; +flat out int outHasTexture; +flat out int outDisableLighting; uniform mat4 projection; uniform mat4 view; uniform mat4 model; uniform int hasTexture; -uniform float totalLights; +uniform int totalLights; uniform Light lights[MAX_LIGHTS]; uniform vec3 cameraPos; uniform int disableLighting;