Skip to content

Commit 530d282

Browse files
committed
Properly displaying texture color channels
Now displaying alpha with white color
1 parent a3adda6 commit 530d282

File tree

8 files changed

+92
-8
lines changed

8 files changed

+92
-8
lines changed

Core/CoreGL.h

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#define USE_SDL 1
1717
#include "GLBind.h"
1818

19+
// For CVec4 type
20+
#include "MathSSE.h"
21+
1922
bool QGL_Init(const char *libName);
2023
void QGL_Shutdown();
2124
void QGL_InitExtensions();
@@ -157,6 +160,13 @@ class CShader
157160
glUniform3fv(u, 1, value.v);
158161
return true;
159162
}
163+
inline bool SetUniform(const char *name, const CVec4& value) const
164+
{
165+
GLint u = glGetUniformLocation(PrObj, name);
166+
if (u == -1) return false;
167+
glUniform4fv(u, 1, value.v);
168+
return true;
169+
}
160170
// attributes
161171
inline GLint GetAttrib(const char *name) const
162172
{

Core/GL/funcs.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ void Uniform1i(GLint, GLint) ARGS
445445
//void Uniform1fv(GLint, GLsizei, const GLfloat *);
446446
//void Uniform2fv(GLint, GLsizei, const GLfloat *);
447447
void Uniform3fv(GLint, GLsizei, const GLfloat *v);
448-
//void Uniform4fv(GLint, GLsizei, const GLfloat *);
448+
void Uniform4fv(GLint, GLsizei, const GLfloat *);
449449
//void Uniform1iv(GLint, GLsizei, const GLint *);
450450
//void Uniform2iv(GLint, GLsizei, const GLint *);
451451
//void Uniform3iv(GLint, GLsizei, const GLint *);

Core/GLBind.h

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct GL_t
9090
void (APIENTRY * Uniform2f) (GLint, GLfloat, GLfloat);
9191
void (APIENTRY * Uniform1i) (GLint, GLint);
9292
void (APIENTRY * Uniform3fv) (GLint, GLsizei, const GLfloat *v);
93+
void (APIENTRY * Uniform4fv) (GLint, GLsizei, const GLfloat *);
9394
void (APIENTRY * VertexAttrib3fv) (GLuint index, const GLfloat *v);
9495
void (APIENTRY * VertexAttribPointer) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
9596
void (APIENTRY * BindRenderbufferEXT) (GLenum target, GLuint renderbuffer);
@@ -204,6 +205,7 @@ extern GL_t GL;
204205
#define glUniform2f GL.Uniform2f
205206
#define glUniform1i GL.Uniform1i
206207
#define glUniform3fv GL.Uniform3fv
208+
#define glUniform4fv GL.Uniform4fv
207209
#define glVertexAttrib3fv GL.VertexAttrib3fv
208210
#define glVertexAttribPointer GL.VertexAttribPointer
209211
#define glBindRenderbufferEXT GL.BindRenderbufferEXT

Core/GLBindImpl.h

+13-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
#if _WIN32
44
# define NUM_GLFUNCS 58
5-
# define NUM_EXTFUNCS 37
5+
# define NUM_EXTFUNCS 38
66
# define NUM_EXTENSIONS 11
77
#elif __linux__
88
# define NUM_GLFUNCS 58
9-
# define NUM_EXTFUNCS 37
9+
# define NUM_EXTFUNCS 38
1010
# define NUM_EXTENSIONS 11
1111
#else
1212
# define NUM_GLFUNCS 58
13-
# define NUM_EXTFUNCS 37
13+
# define NUM_EXTFUNCS 38
1414
# define NUM_EXTENSIONS 11
1515
#endif
1616

@@ -104,6 +104,7 @@ static const char *GLNames[NUM_GLFUNCS + NUM_EXTFUNCS] = {
104104
"glUniform2f",
105105
"glUniform1i",
106106
"glUniform3fv",
107+
"glUniform4fv",
107108
"glVertexAttrib3fv",
108109
"glVertexAttribPointer",
109110
"glBindRenderbufferEXT",
@@ -657,6 +658,12 @@ static void APIENTRY logUniform3fv(GLint arg1, GLsizei arg2, const GLfloat * v)
657658
lib.Uniform3fv(arg1, arg2, v);
658659
}
659660

661+
static void APIENTRY logUniform4fv(GLint arg1, GLsizei arg2, const GLfloat)
662+
{
663+
printf("%s\n", "glUniform4fv");
664+
lib.Uniform4fv(arg1, arg2, GLfloat);
665+
}
666+
660667
static void APIENTRY logVertexAttrib3fv(GLuint index, const GLfloat * v)
661668
{
662669
printf("%s\n", "glVertexAttrib3fv");
@@ -832,6 +839,7 @@ static const GL_t logFuncs = {
832839
logUniform2f,
833840
logUniform1i,
834841
logUniform3fv,
842+
logUniform4fv,
835843
logVertexAttrib3fv,
836844
logVertexAttribPointer,
837845
logBindRenderbufferEXT,
@@ -871,10 +879,10 @@ static extInfo_t extInfo[NUM_EXTENSIONS] = {
871879
{"1.2\0", NULL, NULL, 0, 0, 0, 0},
872880
{"1.3\0", NULL, NULL, NUM_GLFUNCS+0, 2, 0, 0},
873881
{"1.4\0", NULL, NULL, 0, 0, 0, 0},
874-
{"2.0\0", NULL, NULL, NUM_GLFUNCS+2, 24, 0, 0},
882+
{"2.0\0", NULL, NULL, NUM_GLFUNCS+2, 25, 0, 0},
875883
{"3.1\0", NULL, NULL, 0, 0, 0, 0},
876884
{"GL_EXT_texture_compression_s3tc\0", NULL, NULL, 0, 0, 0, 0},
877-
{"GL_EXT_framebuffer_object\0", NULL, NULL, NUM_GLFUNCS+26, 11, 0, 0},
885+
{"GL_EXT_framebuffer_object\0", NULL, NULL, NUM_GLFUNCS+27, 11, 0, 0},
878886
{"GL_ARB_half_float_pixel\0", NULL, NULL, 0, 0, 0, 0},
879887
{"GL_ARB_texture_float\0", NULL, NULL, 0, 0, 0, 0},
880888
{"GL_ARB_texture_compression_rgtc\0" "GL_EXT_texture_compression_rgtc\0", NULL, NULL, 0, 0, 0, 0},

Core/MathSSE.h

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ struct CVec4
3232
v[3] = 0;
3333
}
3434

35+
inline void Set(float x, float y, float z, float w)
36+
{
37+
v[0] = x; v[1] = y; v[2] = z; v[3] = w;
38+
}
39+
3540
FORCEINLINE CVec4& operator=(const CVec3 &src)
3641
{
3742
Set(src);

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Using IDE
100100
As UE Viewer is using custom cross-platform build system, there's no MSBuild support. However we have a simple Visual Studio
101101
project which allows to use this IDE to edit, compile, run and debug the project. Project files are located in `.vs` directory.
102102
In order to open the project, you should start Visual Studio, use "Open a local folder" command, and then choose root project's
103-
directory. Please note: there's .sln file somewhere in *Tools* folder, don't use it - it is intended for UI framewwork testing.
103+
directory. Please note: there's .sln file somewhere in *Tools* folder, don't use it - it is intended for UI framework testing.
104104

105105
Please note that you should use Visual Studio 2019 or newer, otherwise [some features will not work](https://www.gildor.org/smf/index.php/topic,7419.0.html).
106106

Unreal/Shaders/ColorFilter.ush

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/******************************************************************************
2+
* This shader allows to extract specific color channel from texture
3+
*****************************************************************************/
4+
5+
uniform sampler2D Tex;
6+
uniform vec4 FilterValue;
7+
uniform vec4 Colorizer;
8+
9+
void VertexShaderMain()
10+
{
11+
gl_TexCoord[0] = gl_MultiTexCoord0;
12+
gl_Position = ftransform();
13+
}
14+
15+
16+
void PixelShaderMain()
17+
{
18+
vec4 c;
19+
vec2 TexCoord = gl_TexCoord[0].st;
20+
c = texture2D(Tex, TexCoord);
21+
float d = dot(c, FilterValue);
22+
c = vec4(d, d, d, 1.0) * Colorizer;
23+
gl_FragColor = c;
24+
}

Viewers/MaterialViewer.cpp

+36-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
#include "ObjectViewer.h"
1313

14+
// For ColorFilter_ush
15+
#include "Shaders.h"
16+
1417

1518
#define NEW_OUTLINE 1
1619

@@ -385,6 +388,14 @@ void CMaterialViewer::Draw2D()
385388
int width, height;
386389
Window->GetWindowSize(width, height);
387390
int w = min(width, height) / 2;
391+
392+
static CShader shader;
393+
if (GUseGLSL)
394+
{
395+
if (!shader.IsValid()) shader.Make(ColorFilter_ush);
396+
shader.Use();
397+
}
398+
388399
for (int i = 0; i < 4; i++)
389400
{
390401
int x0 = (i & 1) * w;
@@ -393,7 +404,29 @@ void CMaterialViewer::Draw2D()
393404
{
394405
{ 1, 1, 1 }, { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } // normal, red, green, blue
395406
};
396-
glColor3fv(colors[i].v);
407+
if (GUseGLSL)
408+
{
409+
// Use color filter, so we could display RGB channels as colors, and alpha as white
410+
CVec4 filter, colorizer;
411+
filter.Set(0, 0, 0, 0);
412+
filter.v[i] = 1.0f;
413+
colorizer.Set(0, 0, 0, 0);
414+
if (i < 3)
415+
{
416+
colorizer.v[i] = 1.0f;
417+
}
418+
else
419+
{
420+
colorizer.Set(1, 1, 1, 1);
421+
}
422+
shader.SetUniform("FilterValue", filter);
423+
shader.SetUniform("Colorizer", colorizer);
424+
shader.SetUniform("Tex", 0);
425+
}
426+
else
427+
{
428+
glColor3fv(colors[i].v);
429+
}
397430
glBegin(GL_QUADS);
398431
glTexCoord2f(1, 0);
399432
glVertex2f(x0+w, y0);
@@ -405,6 +438,8 @@ void CMaterialViewer::Draw2D()
405438
glVertex2f(x0+w, y0+w);
406439
glEnd();
407440
}
441+
442+
BindDefaultMaterial();
408443
}
409444

410445
// UE1 and UE2

0 commit comments

Comments
 (0)