Skip to content

Commit

Permalink
UPBGE: Fix wireframe color.
Browse files Browse the repository at this point in the history
Previously the wireframe render was interfered with the color used previously.
This color was set from the render of the debug lines and not unset before
render as wireframe.

In place of override the color, a shader is used to make sure that the color
will never depends of a correct or wrong state.
This shader is named the black shader and accesible at the enumerations:
GPU_SHADER_BLACK
GPU_SHADER_BLACK_INSTANCING

They are bind at the place of the old "basic" shader into RAS_BucketManager.

Bug reported by TwisterGE.
  • Loading branch information
panzergame committed Mar 2, 2017
1 parent e7f24cc commit 16914be
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 29 deletions.
8 changes: 4 additions & 4 deletions source/blender/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ set(SRC
shaders/gpu_shader_sep_gaussian_blur_frag.glsl
shaders/gpu_shader_sep_gaussian_blur_vert.glsl
shaders/gpu_shader_basic_frag.glsl
shaders/gpu_shader_basic_instancing_frag.glsl
shaders/gpu_shader_basic_instancing_vert.glsl
shaders/gpu_shader_black_frag.glsl
shaders/gpu_shader_black_vert.glsl
shaders/gpu_shader_basic_vert.glsl
shaders/gpu_shader_basic_geom.glsl
shaders/gpu_shader_vertex.glsl
Expand Down Expand Up @@ -109,8 +109,8 @@ data_to_c_simple(shaders/gpu_shader_material.glsl SRC)
data_to_c_simple(shaders/gpu_shader_sep_gaussian_blur_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_sep_gaussian_blur_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_basic_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_basic_instancing_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_basic_instancing_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_black_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_black_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_basic_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_basic_geom.glsl SRC)
data_to_c_simple(shaders/gpu_shader_frame_buffer_frag.glsl SRC)
Expand Down
9 changes: 5 additions & 4 deletions source/blender/gpu/GPU_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ typedef enum GPUBuiltinShader {
GPU_SHADER_SMOKE = 3,
GPU_SHADER_SMOKE_FIRE = 4,
GPU_SHADER_SMOKE_COBA = 5,
GPU_SHADER_INSTANCING = 6,
GPU_SHADER_DRAW_FRAME_BUFFER = 7,
GPU_SHADER_STEREO_STIPPLE = 8,
GPU_SHADER_STEREO_ANAGLYPH = 9,
GPU_SHADER_BLACK = 6,
GPU_SHADER_BLACK_INSTANCING = 7,
GPU_SHADER_DRAW_FRAME_BUFFER = 8,
GPU_SHADER_STEREO_STIPPLE = 9,
GPU_SHADER_STEREO_ANAGLYPH = 10,
} GPUBuiltinShader;

GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
Expand Down
35 changes: 24 additions & 11 deletions source/blender/gpu/intern/gpu_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
#define MAX_EXT_DEFINE_LENGTH 1024

/* Non-generated shaders */
extern char datatoc_gpu_shader_basic_instancing_frag_glsl[];
extern char datatoc_gpu_shader_basic_instancing_vert_glsl[];
extern char datatoc_gpu_shader_black_frag_glsl[];
extern char datatoc_gpu_shader_black_vert_glsl[];
extern char datatoc_gpu_shader_frame_buffer_frag_glsl[];
extern char datatoc_gpu_shader_frame_buffer_vert_glsl[];
extern char datatoc_gpu_shader_fire_frag_glsl[];
Expand Down Expand Up @@ -76,7 +76,8 @@ static struct GPUShadersGlobal {
GPUShader *smoke;
GPUShader *smoke_fire;
GPUShader *smoke_coba;
GPUShader *instancing;
GPUShader *black;
GPUShader *black_instancing;
GPUShader *draw_frame_buffer;
GPUShader *stereo_stipple;
GPUShader *stereo_anaglyph;
Expand Down Expand Up @@ -759,12 +760,19 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
NULL, NULL, "#define USE_COBA;\n", 0, 0, 0);
retval = GG.shaders.smoke_coba;
break;
case GPU_SHADER_INSTANCING:
if (!GG.shaders.instancing)
GG.shaders.instancing = GPU_shader_create(
datatoc_gpu_shader_basic_instancing_vert_glsl, datatoc_gpu_shader_basic_instancing_frag_glsl,
case GPU_SHADER_BLACK:
if (!GG.shaders.black)
GG.shaders.black = GPU_shader_create(
datatoc_gpu_shader_black_vert_glsl, datatoc_gpu_shader_black_frag_glsl,
NULL, NULL, NULL, 0, 0, 0);
retval = GG.shaders.instancing;
retval = GG.shaders.black;
break;
case GPU_SHADER_BLACK_INSTANCING:
if (!GG.shaders.black_instancing)
GG.shaders.black_instancing = GPU_shader_create(
datatoc_gpu_shader_black_vert_glsl, datatoc_gpu_shader_black_frag_glsl,
NULL, NULL, "#define USE_INSTANCING;\n", 0, 0, 0);
retval = GG.shaders.black_instancing;
break;
case GPU_SHADER_DRAW_FRAME_BUFFER:
if (!GG.shaders.draw_frame_buffer)
Expand Down Expand Up @@ -903,9 +911,14 @@ void GPU_shader_free_builtin_shaders(void)
GG.shaders.smoke_coba = NULL;
}

if (GG.shaders.instancing) {
GPU_shader_free(GG.shaders.instancing);
GG.shaders.instancing = NULL;
if (GG.shaders.black) {
GPU_shader_free(GG.shaders.black);
GG.shaders.black = NULL;
}

if (GG.shaders.black_instancing) {
GPU_shader_free(GG.shaders.black_instancing);
GG.shaders.black_instancing = NULL;
}

if (GG.shaders.draw_frame_buffer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#ifdef USE_INSTANCING
in mat3 ininstmatrix;
in vec3 ininstposition;
#endif

void main()
{
#ifdef USE_INSTANCING
mat4 instmat = mat4(vec4(ininstmatrix[0], ininstposition.x),
vec4(ininstmatrix[1], ininstposition.y),
vec4(ininstmatrix[2], ininstposition.z),
vec4(0.0, 0.0, 0.0, 1.0));

gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * (gl_Vertex * instmat);
#else
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
#endif
}
10 changes: 5 additions & 5 deletions source/gameengine/Rasterizer/RAS_BucketManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void RAS_BucketManager::Renderbuckets(const MT_Transform& cameratrans, RAS_IRast
if (m_buckets[SOLID_SHADOW_BUCKET].size() > 0) {
rasty->SetOverrideShader(isVarianceShadow ?
RAS_IRasterizer::RAS_OVERRIDE_SHADER_SHADOW_VARIANCE :
RAS_IRasterizer::RAS_OVERRIDE_SHADER_BASIC);
RAS_IRasterizer::RAS_OVERRIDE_SHADER_BLACK);
}
RenderBasicBuckets(cameratrans, rasty, SOLID_SHADOW_BUCKET);

Expand All @@ -163,7 +163,7 @@ void RAS_BucketManager::Renderbuckets(const MT_Transform& cameratrans, RAS_IRast
if (m_buckets[SOLID_SHADOW_INSTANCING_BUCKET].size() > 0) {
rasty->SetOverrideShader(isVarianceShadow ?
RAS_IRasterizer::RAS_OVERRIDE_SHADER_SHADOW_VARIANCE_INSTANCING :
RAS_IRasterizer::RAS_OVERRIDE_SHADER_BASIC_INSTANCING);
RAS_IRasterizer::RAS_OVERRIDE_SHADER_BLACK_INSTANCING);
}
RenderBasicBuckets(cameratrans, rasty, SOLID_SHADOW_INSTANCING_BUCKET);

Expand Down Expand Up @@ -208,7 +208,7 @@ void RAS_BucketManager::Renderbuckets(const MT_Transform& cameratrans, RAS_IRast
// Rendering solid regular materials with an empty override shader.

if (m_buckets[SOLID_BUCKET].size() > 0) {
rasty->SetOverrideShader(RAS_IRasterizer::RAS_OVERRIDE_SHADER_BASIC);
rasty->SetOverrideShader(RAS_IRasterizer::RAS_OVERRIDE_SHADER_BLACK);
}
RenderBasicBuckets(cameratrans, rasty, SOLID_BUCKET);

Expand All @@ -219,7 +219,7 @@ void RAS_BucketManager::Renderbuckets(const MT_Transform& cameratrans, RAS_IRast
if ((m_buckets[SOLID_INSTANCING_BUCKET].size() +
m_buckets[ALPHA_INSTANCING_BUCKET].size() +
m_buckets[ALPHA_DEPTH_INSTANCING_BUCKET].size()) != 0) {
rasty->SetOverrideShader(RAS_IRasterizer::RAS_OVERRIDE_SHADER_BASIC_INSTANCING);
rasty->SetOverrideShader(RAS_IRasterizer::RAS_OVERRIDE_SHADER_BLACK_INSTANCING);
}
RenderBasicBuckets(cameratrans, rasty, SOLID_INSTANCING_BUCKET);

Expand All @@ -234,7 +234,7 @@ void RAS_BucketManager::Renderbuckets(const MT_Transform& cameratrans, RAS_IRast
*/

if ((m_buckets[ALPHA_BUCKET].size() + m_buckets[ALPHA_DEPTH_BUCKET].size()) != 0) {
rasty->SetOverrideShader(RAS_IRasterizer::RAS_OVERRIDE_SHADER_BASIC);
rasty->SetOverrideShader(RAS_IRasterizer::RAS_OVERRIDE_SHADER_BLACK);
}
RenderSortedBuckets(cameratrans, rasty, ALPHA_BUCKET);
RenderSortedBuckets(cameratrans, rasty, ALPHA_DEPTH_BUCKET);
Expand Down
10 changes: 7 additions & 3 deletions source/gameengine/Rasterizer/RAS_IRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,13 +1319,17 @@ GPUShader *RAS_IRasterizer::GetOverrideGPUShader(OverrideShaderType type)
GPUShader *shader = nullptr;
switch (type) {
case RAS_OVERRIDE_SHADER_NONE:
case RAS_OVERRIDE_SHADER_BASIC:
{
break;
}
case RAS_OVERRIDE_SHADER_BASIC_INSTANCING:
case RAS_OVERRIDE_SHADER_BLACK:
{
shader = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCING);
shader = GPU_shader_get_builtin_shader(GPU_SHADER_BLACK);
break;
}
case RAS_OVERRIDE_SHADER_BLACK_INSTANCING:
{
shader = GPU_shader_get_builtin_shader(GPU_SHADER_BLACK_INSTANCING);
break;
}
case RAS_OVERRIDE_SHADER_SHADOW_VARIANCE:
Expand Down
4 changes: 2 additions & 2 deletions source/gameengine/Rasterizer/RAS_IRasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ class RAS_IRasterizer
*/
enum OverrideShaderType {
RAS_OVERRIDE_SHADER_NONE,
RAS_OVERRIDE_SHADER_BASIC,
RAS_OVERRIDE_SHADER_BASIC_INSTANCING,
RAS_OVERRIDE_SHADER_BLACK,
RAS_OVERRIDE_SHADER_BLACK_INSTANCING,
RAS_OVERRIDE_SHADER_SHADOW_VARIANCE,
RAS_OVERRIDE_SHADER_SHADOW_VARIANCE_INSTANCING,
};
Expand Down

0 comments on commit 16914be

Please sign in to comment.