mirror of https://github.com/aap/librw.git
changes to gl shaders
This commit is contained in:
parent
427b67c14c
commit
af20de4522
|
@ -137,6 +137,7 @@ int32 u_matColor;
|
||||||
int32 u_surfProps;
|
int32 u_surfProps;
|
||||||
|
|
||||||
Shader *defaultShader, *defaultShader_noAT;
|
Shader *defaultShader, *defaultShader_noAT;
|
||||||
|
Shader *defaultShader_fullLight, *defaultShader_fullLight_noAT;
|
||||||
|
|
||||||
static bool32 stateDirty = 1;
|
static bool32 stateDirty = 1;
|
||||||
static bool32 sceneDirty = 1;
|
static bool32 sceneDirty = 1;
|
||||||
|
@ -996,7 +997,7 @@ setLights(WorldLights *lightData)
|
||||||
uniformObject.lightParams[n].type = 1.0f;
|
uniformObject.lightParams[n].type = 1.0f;
|
||||||
uniformObject.lightColor[n] = l->color;
|
uniformObject.lightColor[n] = l->color;
|
||||||
memcpy(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
|
memcpy(&uniformObject.lightDirection[n], &l->getFrame()->getLTM()->at, sizeof(V3d));
|
||||||
bits |= VSLIGHT_POINT;
|
bits |= VSLIGHT_DIRECT;
|
||||||
n++;
|
n++;
|
||||||
if(n >= MAX_LIGHTS)
|
if(n >= MAX_LIGHTS)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -1833,13 +1834,20 @@ initOpenGL(void)
|
||||||
#include "shaders/default_vs_gl.inc"
|
#include "shaders/default_vs_gl.inc"
|
||||||
#include "shaders/simple_fs_gl.inc"
|
#include "shaders/simple_fs_gl.inc"
|
||||||
const char *vs[] = { shaderDecl, header_vert_src, default_vert_src, nil };
|
const char *vs[] = { shaderDecl, header_vert_src, default_vert_src, nil };
|
||||||
|
const char *vs_fullLight[] = { shaderDecl, "#define DIRECTIONALS\n#define POINTLIGHTS\n#define SPOTLIGHTS\n", header_vert_src, default_vert_src, nil };
|
||||||
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
|
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
|
||||||
|
const char *fs_noAT[] = { shaderDecl, "#define NO_ALPHATEST\n", header_frag_src, simple_frag_src, nil };
|
||||||
|
|
||||||
defaultShader = Shader::create(vs, fs);
|
defaultShader = Shader::create(vs, fs);
|
||||||
assert(defaultShader);
|
assert(defaultShader);
|
||||||
const char *fs_noAT[] = { shaderDecl, "#define NO_ALPHATEST\n", header_frag_src, simple_frag_src, nil };
|
|
||||||
defaultShader_noAT = Shader::create(vs, fs_noAT);
|
defaultShader_noAT = Shader::create(vs, fs_noAT);
|
||||||
assert(defaultShader_noAT);
|
assert(defaultShader_noAT);
|
||||||
|
|
||||||
|
defaultShader_fullLight = Shader::create(vs_fullLight, fs);
|
||||||
|
assert(defaultShader_fullLight);
|
||||||
|
defaultShader_fullLight_noAT = Shader::create(vs_fullLight, fs_noAT);
|
||||||
|
assert(defaultShader_fullLight_noAT);
|
||||||
|
|
||||||
openIm2D();
|
openIm2D();
|
||||||
openIm3D();
|
openIm3D();
|
||||||
|
|
||||||
|
@ -1856,6 +1864,10 @@ termOpenGL(void)
|
||||||
defaultShader = nil;
|
defaultShader = nil;
|
||||||
defaultShader_noAT->destroy();
|
defaultShader_noAT->destroy();
|
||||||
defaultShader_noAT = nil;
|
defaultShader_noAT = nil;
|
||||||
|
defaultShader_fullLight->destroy();
|
||||||
|
defaultShader_fullLight = nil;
|
||||||
|
defaultShader_fullLight_noAT->destroy();
|
||||||
|
defaultShader_fullLight_noAT = nil;
|
||||||
|
|
||||||
glDeleteTextures(1, &whitetex);
|
glDeleteTextures(1, &whitetex);
|
||||||
whitetex = nil;
|
whitetex = nil;
|
||||||
|
|
|
@ -24,26 +24,37 @@ namespace gl3 {
|
||||||
|
|
||||||
#ifdef RW_OPENGL
|
#ifdef RW_OPENGL
|
||||||
|
|
||||||
static Shader *envShader;
|
static Shader *envShader, *envShader_noAT;
|
||||||
|
static Shader *envShader_fullLight, *envShader_fullLight_noAT;
|
||||||
static int32 u_texMatrix;
|
static int32 u_texMatrix;
|
||||||
static int32 u_fxparams;
|
static int32 u_fxparams;
|
||||||
static int32 u_colorClamp;
|
static int32 u_colorClamp;
|
||||||
static int32 u_envColor;
|
static int32 u_envColor;
|
||||||
|
|
||||||
void
|
void
|
||||||
matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst, uint32 flags)
|
matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst, int32 vsBits, uint32 flags)
|
||||||
{
|
{
|
||||||
Material *m;
|
Material *m;
|
||||||
m = inst->material;
|
m = inst->material;
|
||||||
|
|
||||||
defaultShader->use();
|
|
||||||
|
|
||||||
setMaterial(flags, m->color, m->surfaceProps);
|
setMaterial(flags, m->color, m->surfaceProps);
|
||||||
|
|
||||||
setTexture(0, m->texture);
|
setTexture(0, m->texture);
|
||||||
|
|
||||||
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
||||||
|
|
||||||
|
if((vsBits & VSLIGHT_MASK) == 0){
|
||||||
|
if(getAlphaTest())
|
||||||
|
defaultShader->use();
|
||||||
|
else
|
||||||
|
defaultShader_noAT->use();
|
||||||
|
}else{
|
||||||
|
if(getAlphaTest())
|
||||||
|
defaultShader_fullLight->use();
|
||||||
|
else
|
||||||
|
defaultShader_fullLight_noAT->use();
|
||||||
|
}
|
||||||
|
|
||||||
drawInst(header, inst);
|
drawInst(header, inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,18 +93,16 @@ uploadEnvMatrix(Frame *frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, uint32 flags, MatFX::Env *env)
|
matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, int32 vsBits, uint32 flags, MatFX::Env *env)
|
||||||
{
|
{
|
||||||
Material *m;
|
Material *m;
|
||||||
m = inst->material;
|
m = inst->material;
|
||||||
|
|
||||||
if(env->tex == nil || env->coefficient == 0.0f){
|
if(env->tex == nil || env->coefficient == 0.0f){
|
||||||
matfxDefaultRender(header, inst, flags);
|
matfxDefaultRender(header, inst, vsBits, flags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
envShader->use();
|
|
||||||
|
|
||||||
setTexture(0, m->texture);
|
setTexture(0, m->texture);
|
||||||
setTexture(1, env->tex);
|
setTexture(1, env->tex);
|
||||||
uploadEnvMatrix(env->frame);
|
uploadEnvMatrix(env->frame);
|
||||||
|
@ -123,6 +132,18 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, uint32 flags, Mat
|
||||||
rw::SetRenderState(VERTEXALPHA, 1);
|
rw::SetRenderState(VERTEXALPHA, 1);
|
||||||
rw::SetRenderState(SRCBLEND, BLENDONE);
|
rw::SetRenderState(SRCBLEND, BLENDONE);
|
||||||
|
|
||||||
|
if((vsBits & VSLIGHT_MASK) == 0){
|
||||||
|
if(getAlphaTest())
|
||||||
|
envShader->use();
|
||||||
|
else
|
||||||
|
envShader_noAT->use();
|
||||||
|
}else{
|
||||||
|
if(getAlphaTest())
|
||||||
|
envShader_fullLight->use();
|
||||||
|
else
|
||||||
|
envShader_fullLight_noAT->use();
|
||||||
|
}
|
||||||
|
|
||||||
drawInst(header, inst);
|
drawInst(header, inst);
|
||||||
|
|
||||||
rw::SetRenderState(SRCBLEND, BLENDSRCALPHA);
|
rw::SetRenderState(SRCBLEND, BLENDSRCALPHA);
|
||||||
|
@ -133,7 +154,7 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
||||||
{
|
{
|
||||||
uint32 flags = atomic->geometry->flags;
|
uint32 flags = atomic->geometry->flags;
|
||||||
setWorldMatrix(atomic->getFrame()->getLTM());
|
setWorldMatrix(atomic->getFrame()->getLTM());
|
||||||
lightingCB(atomic);
|
int32 vsBits = lightingCB(atomic);
|
||||||
|
|
||||||
setupVertexInput(header);
|
setupVertexInput(header);
|
||||||
|
|
||||||
|
@ -146,13 +167,13 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
||||||
MatFX *matfx = MatFX::get(inst->material);
|
MatFX *matfx = MatFX::get(inst->material);
|
||||||
|
|
||||||
if(matfx == nil)
|
if(matfx == nil)
|
||||||
matfxDefaultRender(header, inst, flags);
|
matfxDefaultRender(header, inst, vsBits, flags);
|
||||||
else switch(matfx->type){
|
else switch(matfx->type){
|
||||||
case MatFX::ENVMAP:
|
case MatFX::ENVMAP:
|
||||||
matfxEnvRender(header, inst, flags, &matfx->fx[0].env);
|
matfxEnvRender(header, inst, vsBits, flags, &matfx->fx[0].env);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
matfxDefaultRender(header, inst, flags);
|
matfxDefaultRender(header, inst, vsBits, flags);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
inst++;
|
inst++;
|
||||||
|
@ -179,9 +200,19 @@ matfxOpen(void *o, int32, int32)
|
||||||
|
|
||||||
#include "shaders/matfx_gl.inc"
|
#include "shaders/matfx_gl.inc"
|
||||||
const char *vs[] = { shaderDecl, header_vert_src, matfx_env_vert_src, nil };
|
const char *vs[] = { shaderDecl, header_vert_src, matfx_env_vert_src, nil };
|
||||||
|
const char *vs_fullLight[] = { shaderDecl, "#define DIRECTIONALS\n#define POINTLIGHTS\n#define SPOTLIGHTS\n", header_vert_src, matfx_env_vert_src, nil };
|
||||||
const char *fs[] = { shaderDecl, header_frag_src, matfx_env_frag_src, nil };
|
const char *fs[] = { shaderDecl, header_frag_src, matfx_env_frag_src, nil };
|
||||||
|
const char *fs_noAT[] = { shaderDecl, "#define NO_ALPHATEST\n", header_frag_src, matfx_env_frag_src, nil };
|
||||||
|
|
||||||
envShader = Shader::create(vs, fs);
|
envShader = Shader::create(vs, fs);
|
||||||
assert(envShader);
|
assert(envShader);
|
||||||
|
envShader_noAT = Shader::create(vs, fs_noAT);
|
||||||
|
assert(envShader_noAT);
|
||||||
|
|
||||||
|
envShader_fullLight = Shader::create(vs_fullLight, fs);
|
||||||
|
assert(envShader_fullLight);
|
||||||
|
envShader_fullLight_noAT = Shader::create(vs_fullLight, fs_noAT);
|
||||||
|
assert(envShader_fullLight_noAT);
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
@ -194,6 +225,12 @@ matfxClose(void *o, int32, int32)
|
||||||
|
|
||||||
envShader->destroy();
|
envShader->destroy();
|
||||||
envShader = nil;
|
envShader = nil;
|
||||||
|
envShader_noAT->destroy();
|
||||||
|
envShader_noAT = nil;
|
||||||
|
envShader_fullLight->destroy();
|
||||||
|
envShader_fullLight = nil;
|
||||||
|
envShader_fullLight_noAT->destroy();
|
||||||
|
envShader_fullLight_noAT = nil;
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
||||||
|
|
||||||
uint32 flags = atomic->geometry->flags;
|
uint32 flags = atomic->geometry->flags;
|
||||||
setWorldMatrix(atomic->getFrame()->getLTM());
|
setWorldMatrix(atomic->getFrame()->getLTM());
|
||||||
lightingCB(atomic);
|
int32 vsBits = lightingCB(atomic);
|
||||||
|
|
||||||
setupVertexInput(header);
|
setupVertexInput(header);
|
||||||
|
|
||||||
|
@ -158,10 +158,17 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
||||||
|
|
||||||
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
||||||
|
|
||||||
if(getAlphaTest())
|
if((vsBits & VSLIGHT_MASK) == 0){
|
||||||
defaultShader->use();
|
if(getAlphaTest())
|
||||||
else
|
defaultShader->use();
|
||||||
defaultShader_noAT->use();
|
else
|
||||||
|
defaultShader_noAT->use();
|
||||||
|
}else{
|
||||||
|
if(getAlphaTest())
|
||||||
|
defaultShader_fullLight->use();
|
||||||
|
else
|
||||||
|
defaultShader_fullLight_noAT->use();
|
||||||
|
}
|
||||||
|
|
||||||
drawInst(header, inst);
|
drawInst(header, inst);
|
||||||
inst++;
|
inst++;
|
||||||
|
|
|
@ -24,7 +24,8 @@ namespace gl3 {
|
||||||
|
|
||||||
#ifdef RW_OPENGL
|
#ifdef RW_OPENGL
|
||||||
|
|
||||||
static Shader *skinShader;
|
static Shader *skinShader, *skinShader_noAT;
|
||||||
|
static Shader *skinShader_fullLight, *skinShader_fullLight_noAT;
|
||||||
static int32 u_boneMatrices;
|
static int32 u_boneMatrices;
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -254,15 +255,13 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
||||||
|
|
||||||
uint32 flags = atomic->geometry->flags;
|
uint32 flags = atomic->geometry->flags;
|
||||||
setWorldMatrix(atomic->getFrame()->getLTM());
|
setWorldMatrix(atomic->getFrame()->getLTM());
|
||||||
lightingCB(atomic);
|
int32 vsBits = lightingCB(atomic);
|
||||||
|
|
||||||
setupVertexInput(header);
|
setupVertexInput(header);
|
||||||
|
|
||||||
InstanceData *inst = header->inst;
|
InstanceData *inst = header->inst;
|
||||||
int32 n = header->numMeshes;
|
int32 n = header->numMeshes;
|
||||||
|
|
||||||
skinShader->use();
|
|
||||||
|
|
||||||
uploadSkinMatrices(atomic);
|
uploadSkinMatrices(atomic);
|
||||||
|
|
||||||
while(n--){
|
while(n--){
|
||||||
|
@ -274,6 +273,18 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
||||||
|
|
||||||
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
||||||
|
|
||||||
|
if((vsBits & VSLIGHT_MASK) == 0){
|
||||||
|
if(getAlphaTest())
|
||||||
|
skinShader->use();
|
||||||
|
else
|
||||||
|
skinShader_noAT->use();
|
||||||
|
}else{
|
||||||
|
if(getAlphaTest())
|
||||||
|
skinShader_fullLight->use();
|
||||||
|
else
|
||||||
|
skinShader_fullLight_noAT->use();
|
||||||
|
}
|
||||||
|
|
||||||
drawInst(header, inst);
|
drawInst(header, inst);
|
||||||
inst++;
|
inst++;
|
||||||
}
|
}
|
||||||
|
@ -288,9 +299,19 @@ skinOpen(void *o, int32, int32)
|
||||||
#include "shaders/simple_fs_gl.inc"
|
#include "shaders/simple_fs_gl.inc"
|
||||||
#include "shaders/skin_gl.inc"
|
#include "shaders/skin_gl.inc"
|
||||||
const char *vs[] = { shaderDecl, header_vert_src, skin_vert_src, nil };
|
const char *vs[] = { shaderDecl, header_vert_src, skin_vert_src, nil };
|
||||||
|
const char *vs_fullLight[] = { shaderDecl, "#define DIRECTIONALS\n#define POINTLIGHTS\n#define SPOTLIGHTS\n", header_vert_src, skin_vert_src, nil };
|
||||||
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
|
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
|
||||||
|
const char *fs_noAT[] = { shaderDecl, "#define NO_ALPHATEST\n", header_frag_src, simple_frag_src, nil };
|
||||||
|
|
||||||
skinShader = Shader::create(vs, fs);
|
skinShader = Shader::create(vs, fs);
|
||||||
assert(skinShader);
|
assert(skinShader);
|
||||||
|
skinShader_noAT = Shader::create(vs, fs_noAT);
|
||||||
|
assert(skinShader_noAT);
|
||||||
|
|
||||||
|
skinShader_fullLight = Shader::create(vs_fullLight, fs);
|
||||||
|
assert(skinShader_fullLight);
|
||||||
|
skinShader_fullLight_noAT = Shader::create(vs_fullLight, fs_noAT);
|
||||||
|
assert(skinShader_fullLight_noAT);
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
@ -303,6 +324,12 @@ skinClose(void *o, int32, int32)
|
||||||
|
|
||||||
skinShader->destroy();
|
skinShader->destroy();
|
||||||
skinShader = nil;
|
skinShader = nil;
|
||||||
|
skinShader_noAT->destroy();
|
||||||
|
skinShader_noAT = nil;
|
||||||
|
skinShader_fullLight->destroy();
|
||||||
|
skinShader_fullLight = nil;
|
||||||
|
skinShader_fullLight_noAT->destroy();
|
||||||
|
skinShader_fullLight_noAT = nil;
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,7 @@ struct InstanceDataHeader : rw::InstanceDataHeader
|
||||||
struct Shader;
|
struct Shader;
|
||||||
|
|
||||||
extern Shader *defaultShader, *defaultShader_noAT;
|
extern Shader *defaultShader, *defaultShader_noAT;
|
||||||
|
extern Shader *defaultShader_fullLight, *defaultShader_fullLight_noAT;
|
||||||
|
|
||||||
struct Im3DVertex
|
struct Im3DVertex
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
#define DIRECTIONALS
|
//#define DIRECTIONALS
|
||||||
//#define POINTLIGHTS
|
//#define POINTLIGHTS
|
||||||
//#define SPOTLIGHTS
|
//#define SPOTLIGHTS
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const char *header_vert_src =
|
const char *header_vert_src =
|
||||||
|
|
||||||
"#define DIRECTIONALS\n"
|
"//#define DIRECTIONALS\n"
|
||||||
"//#define POINTLIGHTS\n"
|
"//#define POINTLIGHTS\n"
|
||||||
"//#define SPOTLIGHTS\n"
|
"//#define SPOTLIGHTS\n"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue