implemented fog for gl3

This commit is contained in:
aap 2016-07-05 18:22:22 +02:00
parent abe0bba5af
commit dcbbdfe6b2
7 changed files with 78 additions and 21 deletions

View File

@ -124,6 +124,12 @@ Camera::destroy(void)
free(this);
}
void
Camera::clear(RGBA *col, uint32 mode)
{
DRIVER->clearCamera(this, col, mode);
}
struct CameraChunkData
{
V2d viewWindow;

View File

@ -230,7 +230,7 @@ beginUpdate(Camera *cam)
proj[12] = 0.0f;
proj[13] = 0.0f;
proj[14] = -this->nearPlane*this->projMat[10];
proj[14] = -this->nearPlane*proj[10];
proj[15] = 0.0f;
}else{
proj[8] = 0.0f;
@ -240,7 +240,7 @@ beginUpdate(Camera *cam)
proj[12] = this->viewOffset.x*invwx;
proj[13] = this->viewOffset.y*invwy;
proj[14] = -this->nearPlane*this->projMat[10];
proj[14] = -this->nearPlane*proj[10];
proj[15] = 1.0f;
}
device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)proj);

View File

@ -69,8 +69,8 @@ Driver::open(void)
namespace null {
void beginUpdate(Camera*) { }
void endUpdate(Camera*) { }
void clearCamera(Camera*,RGBA*,uint32) { }
void setRenderState(int32, uint32) { }
uint32 getRenderState(int32) { return 0; }

View File

@ -19,8 +19,13 @@ namespace gl3 {
struct UniformState
{
int alphaFunc;
int32 alphaFunc;
float32 alphaRef;
int32 fogEnable;
float32 fogStart;
float32 fogEnd;
int32 pad[3];
RGBAf fogColor;
};
struct UniformScene
@ -126,16 +131,29 @@ setRenderState(int32 state, uint32 value)
glDepthMask(zwrite);
}
break;
case FOGENABLE:
if(uniformState.fogEnable != value){
uniformState.fogEnable = value;
stateDirty = 1;
}
break;
case FOGCOLOR:
// no cache check here...too lazy
convColor(&uniformState.fogColor, (RGBA*)&value);
stateDirty = 1;
break;
case ALPHATESTFUNC:
if(uniformState.alphaFunc != value){
uniformState.alphaFunc = value;
stateDirty = 1;
}
break;
case ALPHATESTREF:
if(uniformState.alphaRef != value/255.0f){
uniformState.alphaRef = value/255.0f;
stateDirty = 1;
break;
case ZTESTFUNC:
}
break;
}
}
@ -143,6 +161,7 @@ setRenderState(int32 state, uint32 value)
uint32
getRenderState(int32 state)
{
RGBA rgba;
switch(state){
case VERTEXALPHA:
return vertexAlpha;
@ -154,14 +173,18 @@ getRenderState(int32 state)
return ztest;
case ZWRITEENABLE:
return zwrite;
case FOGENABLE:
return uniformState.fogEnable;
case FOGCOLOR:
convColor(&rgba, &uniformState.fogColor);
return *(uint32*)&rgba;
case ALPHATESTFUNC:
return uniformState.alphaFunc;
case ALPHATESTREF:
return uniformState.alphaRef*255.0f;
case ZTESTFUNC:
break;
}
return 0;
}
void
@ -169,6 +192,9 @@ resetRenderState(void)
{
uniformState.alphaFunc = ALPHAGREATERTHAN;
uniformState.alphaRef = 10.0f/255.0f;
uniformState.fogEnable = 0;
uniformState.fogStart = 0.0f;
uniformState.fogColor = { 1.0f, 1.0f, 1.0f, 1.0f };
stateDirty = 1;
vertexAlpha = 0;
@ -296,6 +322,22 @@ flushCache(void)
}
}
void
clearCamera(Camera *cam, RGBA *col, uint32 mode)
{
RGBAf colf;
GLbitfield mask;
convColor(&colf, col);
glClearColor(colf.red, colf.green, colf.blue, colf.alpha);
mask = 0;
if(mode & Camera::CLEARIMAGE)
mask |= GL_COLOR_BUFFER_BIT;
if(mode & Camera::CLEARZ)
mask |= GL_DEPTH_BUFFER_BIT;
glClear(mask);
}
void
beginUpdate(Camera *cam)
{
@ -353,12 +395,22 @@ beginUpdate(Camera *cam)
// TODO
}
setProjectionMatrix(proj);
if(uniformState.fogStart != cam->fogPlane){
uniformState.fogStart = cam->fogPlane;
stateDirty = 1;
}
if(uniformState.fogEnd != cam->farPlane){
uniformState.fogEnd = cam->farPlane;
stateDirty = 1;
}
}
void
initializeRender(void)
{
driver[PLATFORM_GL3]->beginUpdate = beginUpdate;
driver[PLATFORM_GL3]->clearCamera = clearCamera;
driver[PLATFORM_GL3]->setRenderState = setRenderState;
driver[PLATFORM_GL3]->getRenderState = getRenderState;

View File

@ -32,7 +32,7 @@ static void*
matfxOpen(void *o, int32, int32)
{
matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline();
envShader = Shader::fromFiles("matfx_env.vert", "simple.frag");
envShader = Shader::fromFiles("matfx_env.vert", "matfx_env.frag");
return o;
}

View File

@ -7,8 +7,10 @@ enum RenderState
DESTBLEND,
ZTESTENABLE,
ZWRITEENABLE,
FOGENABLE,
FOGCOLOR,
// TODO:
// fog enable, color, type, density
// fog type, density ?
// ? cullmode
// ? shademode
// ???? stencil
@ -16,7 +18,6 @@ enum RenderState
// platform specific or opaque?
ALPHATESTFUNC,
ALPHATESTREF,
ZTESTFUNC,
};
enum AlphaTestFunc
@ -42,10 +43,6 @@ enum BlendFunction
// TODO: add more perhaps
};
enum ZTestFunc
{
};
// This is for platform independent things
// TODO: move more stuff into this
struct Engine
@ -66,6 +63,7 @@ struct Driver
void (*beginUpdate)(Camera*);
void (*endUpdate)(Camera*);
void (*clearCamera)(Camera*, RGBA *col, uint32 mode);
void (*setRenderState)(int32 state, uint32 value);
uint32 (*getRenderState)(int32 state);
@ -97,6 +95,7 @@ inline uint32 getRenderState(int32 state){
namespace null {
void beginUpdate(Camera*);
void endUpdate(Camera*);
void clearCamera(Camera*, RGBA *col, uint32 mode);
void setRenderState(int32 state, uint32 value);
uint32 getRenderState(int32 state);

View File

@ -524,6 +524,7 @@ struct Camera : PluginBase<Camera>
{
enum { ID = 4 };
enum { PERSPECTIVE = 1, PARALLEL };
enum { CLEARIMAGE = 0x1, CLEARZ = 0x2};
ObjectWithFrame object;
void (*beginUpdateCB)(Camera*);
@ -533,8 +534,6 @@ struct Camera : PluginBase<Camera>
float32 nearPlane, farPlane;
float32 fogPlane;
int32 projection;
// TODO: remove this?
float32 projMat[16];
// clump link handled by plugin in RW
Clump *clump;
@ -556,6 +555,7 @@ struct Camera : PluginBase<Camera>
return LLLinkGetData(lnk, Camera, inClump); }
void beginUpdate(void) { this->beginUpdateCB(this); }
void endUpdate(void) { this->endUpdateCB(this); }
void clear(RGBA *col, uint32 mode);
static Camera *streamRead(Stream *stream);
bool streamWrite(Stream *stream);
uint32 streamGetSize(void);