mirror of
https://github.com/aap/librw.git
synced 2024-11-28 22:55:42 +00:00
fixes for gl3
This commit is contained in:
parent
43190a51f7
commit
09b0b36e7d
@ -56,7 +56,9 @@ void
|
|||||||
Charset::close(void)
|
Charset::close(void)
|
||||||
{
|
{
|
||||||
rwFree(indices);
|
rwFree(indices);
|
||||||
|
indices = nil;
|
||||||
rwFree(vertices);
|
rwFree(vertices);
|
||||||
|
vertices = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
Charset*
|
Charset*
|
||||||
|
@ -159,7 +159,7 @@ matfxRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
bool normals = !!(atomic->geometry->flags & Geometry::NORMALS);
|
bool normals = !!(atomic->geometry->flags & Geometry::NORMALS);
|
||||||
|
|
||||||
float surfProps[4];
|
float surfProps[4];
|
||||||
surfProps[3] = atomic->geometry->flags&Geometry::PRELIT ? 1.0f : 0.0f;
|
surfProps[3] = 0.0f;
|
||||||
|
|
||||||
InstanceData *inst = header->inst;
|
InstanceData *inst = header->inst;
|
||||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||||
|
@ -89,10 +89,9 @@ defaultRenderCB_Fix(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
convMatrix(&world, f->getLTM());
|
convMatrix(&world, f->getLTM());
|
||||||
d3ddevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&world);
|
d3ddevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&world);
|
||||||
|
|
||||||
setStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer,
|
setStreamSource(0, header->vertexStream[0].vertexBuffer, 0, header->vertexStream[0].stride);
|
||||||
0, header->vertexStream[0].stride);
|
setIndices(header->indexBuffer);
|
||||||
setIndices((IDirect3DIndexBuffer9*)header->indexBuffer);
|
setVertexDeclaration(header->vertexDeclaration);
|
||||||
setVertexDeclaration((IDirect3DVertexDeclaration9*)header->vertexDeclaration);
|
|
||||||
|
|
||||||
InstanceData *inst = header->inst;
|
InstanceData *inst = header->inst;
|
||||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||||
@ -145,10 +144,9 @@ void
|
|||||||
defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
|
defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
|
||||||
{
|
{
|
||||||
int vsBits;
|
int vsBits;
|
||||||
setStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer,
|
setStreamSource(0, header->vertexStream[0].vertexBuffer, 0, header->vertexStream[0].stride);
|
||||||
0, header->vertexStream[0].stride);
|
setIndices(header->indexBuffer);
|
||||||
setIndices((IDirect3DIndexBuffer9*)header->indexBuffer);
|
setVertexDeclaration(header->vertexDeclaration);
|
||||||
setVertexDeclaration((IDirect3DVertexDeclaration9*)header->vertexDeclaration);
|
|
||||||
|
|
||||||
vsBits = lightingCB_Shader(atomic);
|
vsBits = lightingCB_Shader(atomic);
|
||||||
uploadMatrices(atomic->getFrame()->getLTM());
|
uploadMatrices(atomic->getFrame()->getLTM());
|
||||||
@ -165,7 +163,7 @@ defaultRenderCB_Shader(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
setVertexShader(default_all_VS);
|
setVertexShader(default_all_VS);
|
||||||
|
|
||||||
float surfProps[4];
|
float surfProps[4];
|
||||||
surfProps[3] = atomic->geometry->flags&Geometry::PRELIT ? 1.0f : 0.0f;
|
surfProps[3] = 0.0f;
|
||||||
|
|
||||||
InstanceData *inst = header->inst;
|
InstanceData *inst = header->inst;
|
||||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||||
|
@ -288,7 +288,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
setVertexShader(skin_all_VS);
|
setVertexShader(skin_all_VS);
|
||||||
|
|
||||||
float surfProps[4];
|
float surfProps[4];
|
||||||
surfProps[3] = atomic->geometry->flags&Geometry::PRELIT ? 1.0f : 0.0f;
|
surfProps[3] = 0.0f;
|
||||||
|
|
||||||
InstanceData *inst = header->inst;
|
InstanceData *inst = header->inst;
|
||||||
for(uint32 i = 0; i < header->numMeshes; i++){
|
for(uint32 i = 0; i < header->numMeshes; i++){
|
||||||
|
@ -37,6 +37,8 @@ static IDirect3DVertexDeclaration9 *im2ddecl;
|
|||||||
static IDirect3DVertexBuffer9 *im2dvertbuf;
|
static IDirect3DVertexBuffer9 *im2dvertbuf;
|
||||||
static IDirect3DIndexBuffer9 *im2dindbuf;
|
static IDirect3DIndexBuffer9 *im2dindbuf;
|
||||||
|
|
||||||
|
void *im2dOverridePS;
|
||||||
|
|
||||||
void
|
void
|
||||||
openIm2D(void)
|
openIm2D(void)
|
||||||
{
|
{
|
||||||
@ -111,7 +113,9 @@ im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices)
|
|||||||
setStreamSource(0, im2dvertbuf, 0, sizeof(Im2DVertex));
|
setStreamSource(0, im2dvertbuf, 0, sizeof(Im2DVertex));
|
||||||
setVertexDeclaration(im2ddecl);
|
setVertexDeclaration(im2ddecl);
|
||||||
|
|
||||||
if(engine->device.getRenderState(TEXTURERASTER))
|
if(im2dOverridePS)
|
||||||
|
setPixelShader(im2dOverridePS);
|
||||||
|
else if(engine->device.getRenderState(TEXTURERASTER))
|
||||||
setPixelShader(im2d_tex_PS);
|
setPixelShader(im2d_tex_PS);
|
||||||
else
|
else
|
||||||
setPixelShader(im2d_PS);
|
setPixelShader(im2d_PS);
|
||||||
@ -163,7 +167,9 @@ im2DRenderIndexedPrimitive(PrimitiveType primType,
|
|||||||
setIndices(im2dindbuf);
|
setIndices(im2dindbuf);
|
||||||
setVertexDeclaration(im2ddecl);
|
setVertexDeclaration(im2ddecl);
|
||||||
|
|
||||||
if(engine->device.getRenderState(TEXTURERASTER))
|
if(im2dOverridePS)
|
||||||
|
setPixelShader(im2dOverridePS);
|
||||||
|
else if(engine->device.getRenderState(TEXTURERASTER))
|
||||||
setPixelShader(im2d_tex_PS);
|
setPixelShader(im2d_tex_PS);
|
||||||
else
|
else
|
||||||
setPixelShader(im2d_PS);
|
setPixelShader(im2d_PS);
|
||||||
|
@ -263,6 +263,8 @@ void uploadMatrices(void); // no world transform
|
|||||||
void uploadMatrices(Matrix *worldMat);
|
void uploadMatrices(Matrix *worldMat);
|
||||||
int32 uploadLights(WorldLights *lightData); // called by lightingCB_Shader
|
int32 uploadLights(WorldLights *lightData); // called by lightingCB_Shader
|
||||||
|
|
||||||
|
extern void *im2dOverridePS;
|
||||||
|
|
||||||
extern void *default_amb_VS;
|
extern void *default_amb_VS;
|
||||||
extern void *default_amb_dir_VS;
|
extern void *default_amb_dir_VS;
|
||||||
extern void *default_all_VS;
|
extern void *default_all_VS;
|
||||||
|
@ -23,11 +23,11 @@ VS_out main(in VS_in input)
|
|||||||
VS_out output;
|
VS_out output;
|
||||||
|
|
||||||
output.Position = mul(combinedMat, input.Position);
|
output.Position = mul(combinedMat, input.Position);
|
||||||
float3 Vertex = mul(worldMat, input.Position).xyz;
|
float3 V = mul(worldMat, input.Position).xyz;
|
||||||
float3 Normal = mul(normalMat, input.Normal);
|
float3 N = mul(normalMat, input.Normal);
|
||||||
|
|
||||||
output.TexCoord0.xy = input.TexCoord;
|
output.TexCoord0.xy = input.TexCoord;
|
||||||
output.TexCoord1 = mul(texMat, float4(Normal, 1.0)).xy;
|
output.TexCoord1 = mul(texMat, float4(N, 1.0)).xy;
|
||||||
|
|
||||||
output.Color = input.Prelight;
|
output.Color = input.Prelight;
|
||||||
output.Color.rgb += ambientLight.rgb * surfAmbient;
|
output.Color.rgb += ambientLight.rgb * surfAmbient;
|
||||||
@ -35,15 +35,15 @@ VS_out main(in VS_in input)
|
|||||||
int i;
|
int i;
|
||||||
#ifdef DIRECTIONALS
|
#ifdef DIRECTIONALS
|
||||||
for(i = 0; i < numDirLights; i++)
|
for(i = 0; i < numDirLights; i++)
|
||||||
output.Color.xyz += DoDirLight(lights[i+firstDirLight], Normal)*surfDiffuse;
|
output.Color.xyz += DoDirLight(lights[i+firstDirLight], N)*surfDiffuse;
|
||||||
#endif
|
#endif
|
||||||
#ifdef POINTLIGHTS
|
#ifdef POINTLIGHTS
|
||||||
for(i = 0; i < numPointLights; i++)
|
for(i = 0; i < numPointLights; i++)
|
||||||
output.Color.xyz += DoPointLight(lights[i+firstPointLight], Vertex.xyz, Normal)*surfDiffuse;
|
output.Color.xyz += DoPointLight(lights[i+firstPointLight], V, N)*surfDiffuse;
|
||||||
#endif
|
#endif
|
||||||
#ifdef SPOTLIGHTS
|
#ifdef SPOTLIGHTS
|
||||||
for(i = 0; i < numSpotLights; i++)
|
for(i = 0; i < numSpotLights; i++)
|
||||||
output.Color.xyz += DoSpotLight(lights[i+firstSpotLight], Vertex.xyz, Normal)*surfDiffuse;
|
output.Color.xyz += DoSpotLight(lights[i+firstSpotLight], V, N)*surfDiffuse;
|
||||||
#endif
|
#endif
|
||||||
// PS2 clamps before material color
|
// PS2 clamps before material color
|
||||||
output.Color = clamp(output.Color, 0.0, 1.0);
|
output.Color = clamp(output.Color, 0.0, 1.0);
|
||||||
|
@ -293,6 +293,10 @@ Engine::term(void)
|
|||||||
|
|
||||||
PluginList::close();
|
PluginList::close();
|
||||||
|
|
||||||
|
// This has to be reset because it won't be opened again otherwise
|
||||||
|
// TODO: maybe reset more stuff here?
|
||||||
|
d3d::nativeRasterOffset = 0;
|
||||||
|
|
||||||
#ifdef TRACK_ALLOCATIONS
|
#ifdef TRACK_ALLOCATIONS
|
||||||
FORLIST(lnk, allocations){
|
FORLIST(lnk, allocations){
|
||||||
MemoryBlock *mem = LLLinkGetData(lnk, MemoryBlock, inAllocList);
|
MemoryBlock *mem = LLLinkGetData(lnk, MemoryBlock, inAllocList);
|
||||||
|
@ -62,10 +62,13 @@ struct UniformState
|
|||||||
{
|
{
|
||||||
int32 alphaFunc;
|
int32 alphaFunc;
|
||||||
float32 alphaRef;
|
float32 alphaRef;
|
||||||
int32 fogEnable;
|
|
||||||
float32 fogStart;
|
float32 fogStart;
|
||||||
float32 fogEnd;
|
float32 fogEnd;
|
||||||
int32 pad[3];
|
|
||||||
|
float32 fogRange;
|
||||||
|
float32 fogDisable;
|
||||||
|
int32 pad[2];
|
||||||
|
|
||||||
RGBAf fogColor;
|
RGBAf fogColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,14 +80,10 @@ struct UniformScene
|
|||||||
|
|
||||||
struct UniformLight
|
struct UniformLight
|
||||||
{
|
{
|
||||||
V3d position;
|
float32 enabled, radius, minusCosAngle, hardSpot;
|
||||||
float32 w;
|
V3d position; int32 pad0;
|
||||||
V3d direction;
|
V3d direction; int32 pad1;
|
||||||
int32 pad1;
|
RGBAf color;
|
||||||
RGBAf color;
|
|
||||||
float32 radius;
|
|
||||||
float32 minusCosAngle;
|
|
||||||
int32 pad2[2];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_LIGHTS 8
|
#define MAX_LIGHTS 8
|
||||||
@ -93,9 +92,9 @@ struct UniformObject
|
|||||||
{
|
{
|
||||||
RawMatrix world;
|
RawMatrix world;
|
||||||
RGBAf ambLight;
|
RGBAf ambLight;
|
||||||
int32 numLights;
|
UniformLight directLights[MAX_LIGHTS];
|
||||||
int32 pad[3];
|
UniformLight pointLights[MAX_LIGHTS];
|
||||||
UniformLight lights[MAX_LIGHTS];
|
UniformLight spotLights[MAX_LIGHTS];
|
||||||
};
|
};
|
||||||
|
|
||||||
static GLuint vao;
|
static GLuint vao;
|
||||||
@ -106,9 +105,9 @@ static UniformScene uniformScene;
|
|||||||
static UniformObject uniformObject;
|
static UniformObject uniformObject;
|
||||||
|
|
||||||
int32 u_matColor;
|
int32 u_matColor;
|
||||||
int32 u_surfaceProps;
|
int32 u_surfProps;
|
||||||
|
|
||||||
Shader *simpleShader;
|
Shader *defaultShader;
|
||||||
|
|
||||||
static bool32 stateDirty = 1;
|
static bool32 stateDirty = 1;
|
||||||
static bool32 sceneDirty = 1;
|
static bool32 sceneDirty = 1;
|
||||||
@ -133,6 +132,9 @@ struct RwStateCache {
|
|||||||
uint32 zwrite;
|
uint32 zwrite;
|
||||||
uint32 ztest;
|
uint32 ztest;
|
||||||
uint32 cullmode;
|
uint32 cullmode;
|
||||||
|
uint32 fogEnable;
|
||||||
|
float32 fogStart;
|
||||||
|
float32 fogEnd;
|
||||||
RwRasterStateCache texstage[MAXNUMSTAGES];
|
RwRasterStateCache texstage[MAXNUMSTAGES];
|
||||||
};
|
};
|
||||||
static RwStateCache rwStateCache;
|
static RwStateCache rwStateCache;
|
||||||
@ -155,6 +157,41 @@ static uint32 blendMap[] = {
|
|||||||
GL_SRC_ALPHA_SATURATE,
|
GL_SRC_ALPHA_SATURATE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
setDepthTest(bool32 enable)
|
||||||
|
{
|
||||||
|
if(rwStateCache.ztest != enable){
|
||||||
|
rwStateCache.ztest = enable;
|
||||||
|
if(rwStateCache.zwrite && !enable){
|
||||||
|
// If we still want to write, enable but set mode to always
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_ALWAYS);
|
||||||
|
}else{
|
||||||
|
if(rwStateCache.ztest)
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
else
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
setDepthWrite(bool32 enable)
|
||||||
|
{
|
||||||
|
enable = enable ? GL_TRUE : GL_FALSE;
|
||||||
|
if(rwStateCache.zwrite != enable){
|
||||||
|
rwStateCache.zwrite = enable;
|
||||||
|
if(enable && !rwStateCache.ztest){
|
||||||
|
// Have to switch on ztest so writing can work
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_ALWAYS);
|
||||||
|
}
|
||||||
|
glDepthMask(rwStateCache.zwrite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setAlphaTest(bool32 enable)
|
setAlphaTest(bool32 enable)
|
||||||
{
|
{
|
||||||
@ -412,23 +449,14 @@ setRenderState(int32 state, void *pvalue)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ZTESTENABLE:
|
case ZTESTENABLE:
|
||||||
if(rwStateCache.ztest != value){
|
setDepthTest(value);
|
||||||
rwStateCache.ztest = value;
|
|
||||||
if(rwStateCache.ztest)
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
else
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ZWRITEENABLE:
|
case ZWRITEENABLE:
|
||||||
if(rwStateCache.zwrite != (value ? GL_TRUE : GL_FALSE)){
|
setDepthWrite(value);
|
||||||
rwStateCache.zwrite = value ? GL_TRUE : GL_FALSE;
|
|
||||||
glDepthMask(rwStateCache.zwrite);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case FOGENABLE:
|
case FOGENABLE:
|
||||||
if(uniformState.fogEnable != value){
|
if(rwStateCache.fogEnable != value){
|
||||||
uniformState.fogEnable = value;
|
rwStateCache.fogEnable = value;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -506,7 +534,7 @@ getRenderState(int32 state)
|
|||||||
val = rwStateCache.zwrite;
|
val = rwStateCache.zwrite;
|
||||||
break;
|
break;
|
||||||
case FOGENABLE:
|
case FOGENABLE:
|
||||||
val = uniformState.fogEnable;
|
val = rwStateCache.fogEnable;
|
||||||
break;
|
break;
|
||||||
case FOGCOLOR:
|
case FOGCOLOR:
|
||||||
convColor(&rgba, &uniformState.fogColor);
|
convColor(&rgba, &uniformState.fogColor);
|
||||||
@ -534,8 +562,10 @@ resetRenderState(void)
|
|||||||
rwStateCache.alphaFunc = ALPHAGREATEREQUAL;
|
rwStateCache.alphaFunc = ALPHAGREATEREQUAL;
|
||||||
uniformState.alphaFunc = 0;
|
uniformState.alphaFunc = 0;
|
||||||
uniformState.alphaRef = 10.0f/255.0f;
|
uniformState.alphaRef = 10.0f/255.0f;
|
||||||
uniformState.fogEnable = 0;
|
uniformState.fogDisable = 1.0f;
|
||||||
uniformState.fogStart = 0.0f;
|
uniformState.fogStart = 0.0f;
|
||||||
|
uniformState.fogEnd = 0.0f;
|
||||||
|
uniformState.fogRange = 0.0f;
|
||||||
uniformState.fogColor = { 1.0f, 1.0f, 1.0f, 1.0f };
|
uniformState.fogColor = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
|
|
||||||
@ -573,40 +603,66 @@ setWorldMatrix(Matrix *mat)
|
|||||||
objectDirty = 1;
|
objectDirty = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int32
|
||||||
setAmbientLight(RGBAf *amb)
|
setLights(WorldLights *lightData)
|
||||||
{
|
{
|
||||||
uniformObject.ambLight = *amb;
|
int i, np, ns;
|
||||||
objectDirty = 1;
|
Light *l;
|
||||||
}
|
int32 bits;
|
||||||
|
|
||||||
void
|
uniformObject.ambLight = lightData->ambient;
|
||||||
setNumLights(int32 n)
|
memset(uniformObject.directLights, 0, sizeof(uniformObject.directLights));
|
||||||
{
|
memset(uniformObject.pointLights, 0, sizeof(uniformObject.pointLights));
|
||||||
uniformObject.numLights = n;
|
memset(uniformObject.spotLights, 0, sizeof(uniformObject.spotLights));
|
||||||
objectDirty = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
bits = 0;
|
||||||
setLight(int32 n, Light *light)
|
|
||||||
{
|
|
||||||
UniformLight *l;
|
|
||||||
Frame *f;
|
|
||||||
Matrix *m;
|
|
||||||
|
|
||||||
l = &uniformObject.lights[n];
|
for(i = 0; i < lightData->numDirectionals && i < 8; i++){
|
||||||
f = light->getFrame();
|
l = lightData->directionals[i];
|
||||||
if(f){
|
uniformObject.directLights[i].enabled = 1.0f;
|
||||||
m = f->getLTM();
|
uniformObject.directLights[i].color = l->color;
|
||||||
l->position = m->pos;
|
uniformObject.directLights[i].direction = l->getFrame()->getLTM()->at;
|
||||||
l->direction = m->at;
|
bits |= VSLIGHT_POINT;
|
||||||
}
|
}
|
||||||
// light has position
|
|
||||||
l->w = light->getType() >= Light::POINT ? 1.0f : 0.0f;
|
np = 0;
|
||||||
l->color = light->color;
|
ns = 0;
|
||||||
l->radius = light->radius;
|
for(i = 0; i < lightData->numLocals; i++){
|
||||||
l->minusCosAngle = light->minusCosAngle;
|
l = lightData->locals[i];
|
||||||
|
switch(l->getType()){
|
||||||
|
case Light::POINT:
|
||||||
|
if(np >= 8)
|
||||||
|
continue;
|
||||||
|
uniformObject.pointLights[np].enabled = 1.0f;
|
||||||
|
uniformObject.pointLights[np].color = l->color;
|
||||||
|
uniformObject.pointLights[np].position = l->getFrame()->getLTM()->pos;
|
||||||
|
uniformObject.pointLights[np].radius = l->radius;
|
||||||
|
np++;
|
||||||
|
bits |= VSLIGHT_POINT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Light::SPOT:
|
||||||
|
case Light::SOFTSPOT:
|
||||||
|
if(np >= 8)
|
||||||
|
continue;
|
||||||
|
uniformObject.spotLights[ns].enabled = 1.0f;
|
||||||
|
uniformObject.spotLights[ns].color = l->color;
|
||||||
|
uniformObject.spotLights[ns].position = l->getFrame()->getLTM()->pos;
|
||||||
|
uniformObject.spotLights[ns].direction = l->getFrame()->getLTM()->at;
|
||||||
|
uniformObject.spotLights[ns].radius = l->radius;
|
||||||
|
uniformObject.spotLights[ns].minusCosAngle = l->minusCosAngle;
|
||||||
|
if(l->getType() == Light::SOFTSPOT)
|
||||||
|
uniformObject.spotLights[ns].hardSpot = 0.0f;
|
||||||
|
else
|
||||||
|
uniformObject.spotLights[ns].hardSpot = 1.0f;
|
||||||
|
ns++;
|
||||||
|
bits |= VSLIGHT_SPOT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
objectDirty = 1;
|
objectDirty = 1;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -639,6 +695,10 @@ flushCache(void)
|
|||||||
sceneDirty = 0;
|
sceneDirty = 0;
|
||||||
}
|
}
|
||||||
if(stateDirty){
|
if(stateDirty){
|
||||||
|
uniformState.fogDisable = rwStateCache.fogEnable ? 0.0f : 1.0f;
|
||||||
|
uniformState.fogStart = rwStateCache.fogStart;
|
||||||
|
uniformState.fogEnd = rwStateCache.fogEnd;
|
||||||
|
uniformState.fogRange = 1.0f/(rwStateCache.fogStart - rwStateCache.fogEnd);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, ubo_state);
|
glBindBuffer(GL_UNIFORM_BUFFER, ubo_state);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(UniformState),
|
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(UniformState),
|
||||||
&uniformState);
|
&uniformState);
|
||||||
@ -762,12 +822,12 @@ beginUpdate(Camera *cam)
|
|||||||
memcpy(&cam->devProj, &proj, sizeof(RawMatrix));
|
memcpy(&cam->devProj, &proj, sizeof(RawMatrix));
|
||||||
setProjectionMatrix(proj);
|
setProjectionMatrix(proj);
|
||||||
|
|
||||||
if(uniformState.fogStart != cam->fogPlane){
|
if(rwStateCache.fogStart != cam->fogPlane){
|
||||||
uniformState.fogStart = cam->fogPlane;
|
rwStateCache.fogStart = cam->fogPlane;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
if(uniformState.fogEnd != cam->farPlane){
|
if(rwStateCache.fogEnd != cam->farPlane){
|
||||||
uniformState.fogEnd = cam->farPlane;
|
rwStateCache.fogEnd = cam->farPlane;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -993,7 +1053,7 @@ initOpenGL(void)
|
|||||||
registerBlock("Object");
|
registerBlock("Object");
|
||||||
registerBlock("State");
|
registerBlock("State");
|
||||||
u_matColor = registerUniform("u_matColor");
|
u_matColor = registerUniform("u_matColor");
|
||||||
u_surfaceProps = registerUniform("u_surfaceProps");
|
u_surfProps = registerUniform("u_surfProps");
|
||||||
|
|
||||||
glClearColor(0.25, 0.25, 0.25, 1.0);
|
glClearColor(0.25, 0.25, 0.25, 1.0);
|
||||||
|
|
||||||
@ -1031,9 +1091,12 @@ initOpenGL(void)
|
|||||||
GL_DYNAMIC_DRAW);
|
GL_DYNAMIC_DRAW);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
#include "shaders/simple_vs_gl3.inc"
|
#include "shaders/default_vs_gl3.inc"
|
||||||
#include "shaders/simple_fs_gl3.inc"
|
#include "shaders/simple_fs_gl3.inc"
|
||||||
simpleShader = Shader::fromStrings(simple_vert_src, simple_frag_src);
|
const char *vs[] = { header_vert_src, default_vert_src, nil };
|
||||||
|
const char *fs[] = { simple_frag_src, nil };
|
||||||
|
defaultShader = Shader::create(vs, fs);
|
||||||
|
assert(defaultShader);
|
||||||
|
|
||||||
openIm2D();
|
openIm2D();
|
||||||
openIm3D();
|
openIm3D();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "../rwbase.h"
|
#include "../rwbase.h"
|
||||||
#include "../rwerror.h"
|
#include "../rwerror.h"
|
||||||
@ -50,7 +51,10 @@ openIm2D(void)
|
|||||||
|
|
||||||
#include "shaders/im2d_gl3.inc"
|
#include "shaders/im2d_gl3.inc"
|
||||||
#include "shaders/simple_fs_gl3.inc"
|
#include "shaders/simple_fs_gl3.inc"
|
||||||
im2dShader = Shader::fromStrings(im2d_vert_src, simple_frag_src);
|
const char *vs[] = { header_vert_src, im2d_vert_src, nil };
|
||||||
|
const char *fs[] = { simple_frag_src, nil };
|
||||||
|
im2dShader = Shader::create(vs, fs);
|
||||||
|
assert(im2dShader);
|
||||||
|
|
||||||
glGenBuffers(1, &im2DIbo);
|
glGenBuffers(1, &im2DIbo);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im2DIbo);
|
||||||
@ -176,7 +180,10 @@ openIm3D(void)
|
|||||||
{
|
{
|
||||||
#include "shaders/im3d_gl3.inc"
|
#include "shaders/im3d_gl3.inc"
|
||||||
#include "shaders/simple_fs_gl3.inc"
|
#include "shaders/simple_fs_gl3.inc"
|
||||||
im3dShader = Shader::fromStrings(im3d_vert_src, simple_frag_src);
|
const char *vs[] = { header_vert_src, im3d_vert_src, nil };
|
||||||
|
const char *fs[] = { simple_frag_src, nil };
|
||||||
|
im3dShader = Shader::create(vs, fs);
|
||||||
|
assert(im3dShader);
|
||||||
|
|
||||||
glGenBuffers(1, &im3DIbo);
|
glGenBuffers(1, &im3DIbo);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, im3DIbo);
|
||||||
|
@ -37,9 +37,14 @@ matfxOpen(void *o, int32, int32)
|
|||||||
{
|
{
|
||||||
u_texMatrix = registerUniform("u_texMatrix");
|
u_texMatrix = registerUniform("u_texMatrix");
|
||||||
u_coefficient = registerUniform("u_coefficient");
|
u_coefficient = registerUniform("u_coefficient");
|
||||||
#include "shaders/matfx_gl3.inc"
|
|
||||||
matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline();
|
matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline();
|
||||||
envShader = Shader::fromStrings(matfx_env_vert_src, matfx_env_frag_src);
|
|
||||||
|
#include "shaders/matfx_gl3.inc"
|
||||||
|
const char *vs[] = { header_vert_src, matfx_env_vert_src, nil };
|
||||||
|
const char *fs[] = { matfx_env_frag_src, nil };
|
||||||
|
envShader = Shader::create(vs, fs);
|
||||||
|
assert(envShader);
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +70,7 @@ matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst)
|
|||||||
GLfloat surfProps[4];
|
GLfloat surfProps[4];
|
||||||
m = inst->material;
|
m = inst->material;
|
||||||
|
|
||||||
simpleShader->use();
|
defaultShader->use();
|
||||||
|
|
||||||
convColor(&col, &m->color);
|
convColor(&col, &m->color);
|
||||||
glUniform4fv(U(u_matColor), 1, (GLfloat*)&col);
|
glUniform4fv(U(u_matColor), 1, (GLfloat*)&col);
|
||||||
@ -74,7 +79,7 @@ matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst)
|
|||||||
surfProps[1] = m->surfaceProps.specular;
|
surfProps[1] = m->surfaceProps.specular;
|
||||||
surfProps[2] = m->surfaceProps.diffuse;
|
surfProps[2] = m->surfaceProps.diffuse;
|
||||||
surfProps[3] = 0.0f;
|
surfProps[3] = 0.0f;
|
||||||
glUniform4fv(U(u_surfaceProps), 1, surfProps);
|
glUniform4fv(U(u_surfProps), 1, surfProps);
|
||||||
|
|
||||||
setTexture(0, m->texture);
|
setTexture(0, m->texture);
|
||||||
|
|
||||||
@ -85,82 +90,54 @@ matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst)
|
|||||||
GL_UNSIGNED_SHORT, (void*)(uintptr)inst->offset);
|
GL_UNSIGNED_SHORT, (void*)(uintptr)inst->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Frame *lastEnvFrame;
|
||||||
|
|
||||||
|
static RawMatrix normal2texcoord = {
|
||||||
|
{ 0.5f, 0.0f, 0.0f }, 0.0f,
|
||||||
|
{ 0.0f, -0.5f, 0.0f }, 0.0f,
|
||||||
|
{ 0.0f, 0.0f, 1.0f }, 0.0f,
|
||||||
|
{ 0.5f, 0.5f, 0.0f }, 1.0f
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
calcEnvTexMatrix(Frame *f, float32 *mat)
|
uploadEnvMatrix(Frame *frame)
|
||||||
{
|
{
|
||||||
Matrix cam;
|
Matrix invMat;
|
||||||
if(f){
|
if(frame == nil)
|
||||||
// PS2 style - could be simplified by the shader
|
frame = engine->currentCamera->getFrame();
|
||||||
cam = *((Camera*)engine->currentCamera)->getFrame()->getLTM();
|
|
||||||
cam.pos = { 0.0, 0.0, 0.0 };
|
|
||||||
cam.right.x = -cam.right.x;
|
|
||||||
cam.right.y = -cam.right.y;
|
|
||||||
cam.right.z = -cam.right.z;
|
|
||||||
|
|
||||||
Matrix inv;
|
// cache the matrix across multiple meshes
|
||||||
Matrix::invert(&inv, f->getLTM());
|
static RawMatrix envMtx;
|
||||||
inv.pos = { -1.0, -1.0, -1.0 };
|
if(frame != lastEnvFrame){
|
||||||
inv.right.x *= -0.5f;
|
lastEnvFrame = frame;
|
||||||
inv.right.y *= -0.5f;
|
|
||||||
inv.right.z *= -0.5f;
|
|
||||||
inv.up.x *= -0.5f;
|
|
||||||
inv.up.y *= -0.5f;
|
|
||||||
inv.up.z *= -0.5f;
|
|
||||||
inv.at.x *= -0.5f;
|
|
||||||
inv.at.y *= -0.5f;
|
|
||||||
inv.at.z *= -0.5f;
|
|
||||||
inv.pos.x *= -0.5f;
|
|
||||||
inv.pos.y *= -0.5f;
|
|
||||||
inv.pos.z *= -0.5f;
|
|
||||||
|
|
||||||
Matrix m;
|
RawMatrix invMtx;
|
||||||
Matrix::mult(&m, &cam, &inv);
|
Matrix::invert(&invMat, frame->getLTM());
|
||||||
|
convMatrix(&invMtx, &invMat);
|
||||||
memcpy(mat, &m, 64);
|
RawMatrix::mult(&envMtx, &invMtx, &normal2texcoord);
|
||||||
mat[3] = mat[7] = mat[11] = 0.0f;
|
|
||||||
mat[15] = 1.0f;
|
|
||||||
|
|
||||||
}else{
|
|
||||||
// D3D - TODO: find out what PS2 does
|
|
||||||
mat[0] = 0.5f;
|
|
||||||
mat[1] = 0.0f;
|
|
||||||
mat[2] = 0.0f;
|
|
||||||
mat[3] = 0.0f;
|
|
||||||
|
|
||||||
mat[4] = 0.0f;
|
|
||||||
mat[5] = -0.5f;
|
|
||||||
mat[6] = 0.0f;
|
|
||||||
mat[7] = 0.0f;
|
|
||||||
|
|
||||||
mat[8] = 0.0f;
|
|
||||||
mat[9] = 0.0f;
|
|
||||||
mat[10] = 1.0f;
|
|
||||||
mat[11] = 0.0f;
|
|
||||||
|
|
||||||
mat[12] = 0.5f;
|
|
||||||
mat[13] = 0.5f;
|
|
||||||
mat[14] = 0.0f;
|
|
||||||
mat[15] = 0.0f;
|
|
||||||
}
|
}
|
||||||
|
glUniformMatrix4fv(U(u_texMatrix), 1, GL_FALSE, (float*)&envMtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
matfxEnvRender(InstanceDataHeader *header, InstanceData *inst)
|
matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env)
|
||||||
{
|
{
|
||||||
Material *m;
|
Material *m;
|
||||||
RGBAf col;
|
RGBAf col;
|
||||||
GLfloat surfProps[4];
|
GLfloat surfProps[4];
|
||||||
float32 texMat[16];
|
|
||||||
m = inst->material;
|
m = inst->material;
|
||||||
|
|
||||||
matfxDefaultRender(header, inst);
|
if(env->tex == nil || env->coefficient == 0.0f){
|
||||||
|
matfxDefaultRender(header, inst);
|
||||||
MatFX *fx = MatFX::get(m);
|
return;
|
||||||
int32 idx = fx->getEffectIndex(MatFX::ENVMAP);
|
}
|
||||||
MatFX::Env *env = &fx->fx[idx].env;
|
|
||||||
|
|
||||||
envShader->use();
|
envShader->use();
|
||||||
|
|
||||||
|
setTexture(0, m->texture);
|
||||||
|
setTexture(1, env->tex);
|
||||||
|
uploadEnvMatrix(env->frame);
|
||||||
|
|
||||||
convColor(&col, &m->color);
|
convColor(&col, &m->color);
|
||||||
glUniform4fv(U(u_matColor), 1, (GLfloat*)&col);
|
glUniform4fv(U(u_matColor), 1, (GLfloat*)&col);
|
||||||
|
|
||||||
@ -168,52 +145,47 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst)
|
|||||||
surfProps[1] = m->surfaceProps.specular;
|
surfProps[1] = m->surfaceProps.specular;
|
||||||
surfProps[2] = m->surfaceProps.diffuse;
|
surfProps[2] = m->surfaceProps.diffuse;
|
||||||
surfProps[3] = 0.0f;
|
surfProps[3] = 0.0f;
|
||||||
glUniform4fv(U(u_surfaceProps), 1, surfProps);
|
glUniform4fv(U(u_surfProps), 1, surfProps);
|
||||||
|
|
||||||
glUniform1fv(U(u_coefficient), 1, &env->coefficient);
|
glUniform1fv(U(u_coefficient), 1, &env->coefficient);
|
||||||
|
|
||||||
calcEnvTexMatrix(env->frame, texMat);
|
|
||||||
glUniformMatrix4fv(U(u_texMatrix), 1, GL_FALSE, texMat);
|
|
||||||
|
|
||||||
setTexture(0, env->tex);
|
|
||||||
|
|
||||||
rw::SetRenderState(VERTEXALPHA, 1);
|
rw::SetRenderState(VERTEXALPHA, 1);
|
||||||
rw::SetRenderState(SRCBLEND, BLENDONE);
|
rw::SetRenderState(SRCBLEND, BLENDONE);
|
||||||
rw::SetRenderState(DESTBLEND, BLENDONE);
|
|
||||||
|
|
||||||
flushCache();
|
flushCache();
|
||||||
glDrawElements(header->primType, inst->numIndex,
|
glDrawElements(header->primType, inst->numIndex,
|
||||||
GL_UNSIGNED_SHORT, (void*)(uintptr)inst->offset);
|
GL_UNSIGNED_SHORT, (void*)(uintptr)inst->offset);
|
||||||
|
|
||||||
rw::SetRenderState(SRCBLEND, BLENDSRCALPHA);
|
rw::SetRenderState(SRCBLEND, BLENDSRCALPHA);
|
||||||
rw::SetRenderState(DESTBLEND, BLENDINVSRCALPHA);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
matfxRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
matfxRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
||||||
{
|
{
|
||||||
setWorldMatrix(atomic->getFrame()->getLTM());
|
setWorldMatrix(atomic->getFrame()->getLTM());
|
||||||
lightingCB(!!(atomic->geometry->flags & Geometry::NORMALS));
|
lightingCB(atomic);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
|
||||||
setAttribPointers(header->attribDesc, header->numAttribs);
|
setAttribPointers(header->attribDesc, header->numAttribs);
|
||||||
|
|
||||||
|
lastEnvFrame = nil;
|
||||||
|
|
||||||
InstanceData *inst = header->inst;
|
InstanceData *inst = header->inst;
|
||||||
int32 n = header->numMeshes;
|
int32 n = header->numMeshes;
|
||||||
|
|
||||||
// rw::SetRenderState(ALPHATESTFUNC, 1);
|
|
||||||
// rw::SetRenderState(ALPHATESTREF, 50);
|
|
||||||
|
|
||||||
int32 fx;
|
|
||||||
while(n--){
|
while(n--){
|
||||||
fx = MatFX::getEffects(inst->material);
|
MatFX *matfx = MatFX::get(inst->material);
|
||||||
switch(fx){
|
|
||||||
|
if(matfx == nil)
|
||||||
|
matfxDefaultRender(header, inst);
|
||||||
|
else switch(matfx->type){
|
||||||
case MatFX::ENVMAP:
|
case MatFX::ENVMAP:
|
||||||
matfxEnvRender(header, inst);
|
matfxEnvRender(header, inst, &matfx->fx[0].env);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
matfxDefaultRender(header, inst);
|
matfxDefaultRender(header, inst);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
inst++;
|
inst++;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ rasterCreateTexture(Raster *raster)
|
|||||||
// TODO: check if this is correct
|
// TODO: check if this is correct
|
||||||
natras->internalFormat = GL_RGBA;
|
natras->internalFormat = GL_RGBA;
|
||||||
natras->format = GL_RGBA;
|
natras->format = GL_RGBA;
|
||||||
natras->type = GL_UNSIGNED_SHORT_5_5_5_1;
|
natras->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||||
natras->hasAlpha = 1;
|
natras->hasAlpha = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -96,7 +96,7 @@ rasterCreateCameraTexture(Raster *raster)
|
|||||||
// TODO: check if this is correct
|
// TODO: check if this is correct
|
||||||
natras->internalFormat = GL_RGBA;
|
natras->internalFormat = GL_RGBA;
|
||||||
natras->format = GL_RGBA;
|
natras->format = GL_RGBA;
|
||||||
natras->type = GL_UNSIGNED_SHORT_5_5_5_1;
|
natras->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||||
natras->hasAlpha = 1;
|
natras->hasAlpha = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -242,12 +242,23 @@ imageFindRasterFormat(Image *img, int32 type,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8*
|
||||||
|
flipImage(Image *image)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
uint8 *newPx = (uint8*)rwMalloc(image->stride*image->height, 0);
|
||||||
|
for(i = 0; i < image->height; i++)
|
||||||
|
memcpy(&newPx[i*image->stride], &image->pixels[(image->height-1-i)*image->stride], image->stride);
|
||||||
|
return newPx;
|
||||||
|
}
|
||||||
|
|
||||||
bool32
|
bool32
|
||||||
rasterFromImage(Raster *raster, Image *image)
|
rasterFromImage(Raster *raster, Image *image)
|
||||||
{
|
{
|
||||||
if((raster->type&0xF) != Raster::TEXTURE)
|
if((raster->type&0xF) != Raster::TEXTURE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#ifdef RW_OPENGL
|
||||||
// Unpalettize image if necessary but don't change original
|
// Unpalettize image if necessary but don't change original
|
||||||
Image *truecolimg = nil;
|
Image *truecolimg = nil;
|
||||||
if(image->depth <= 8){
|
if(image->depth <= 8){
|
||||||
@ -259,18 +270,28 @@ rasterFromImage(Raster *raster, Image *image)
|
|||||||
image = truecolimg;
|
image = truecolimg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NB: important to set the format of the input data here!
|
||||||
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
||||||
switch(image->depth){
|
switch(image->depth){
|
||||||
case 32:
|
case 32:
|
||||||
if(raster->format != Raster::C8888 &&
|
if(raster->format != Raster::C8888 &&
|
||||||
raster->format != Raster::C888)
|
raster->format != Raster::C888)
|
||||||
goto err;
|
goto err;
|
||||||
|
natras->format = GL_RGBA;
|
||||||
|
natras->type = GL_UNSIGNED_BYTE;
|
||||||
|
natras->hasAlpha = 1;
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
if(raster->format != Raster::C888) goto err;
|
if(raster->format != Raster::C888) goto err;
|
||||||
|
natras->format = GL_RGB;
|
||||||
|
natras->type = GL_UNSIGNED_BYTE;
|
||||||
|
natras->hasAlpha = 0;
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
if(raster->format != Raster::C1555) goto err;
|
if(raster->format != Raster::C1555) goto err;
|
||||||
|
natras->format = GL_RGBA;
|
||||||
|
natras->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
||||||
|
natras->hasAlpha = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
@ -283,12 +304,16 @@ rasterFromImage(Raster *raster, Image *image)
|
|||||||
|
|
||||||
natras->hasAlpha = image->hasAlpha();
|
natras->hasAlpha = image->hasAlpha();
|
||||||
|
|
||||||
#ifdef RW_OPENGL
|
|
||||||
|
uint8 *flipped = flipImage(image);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, natras->texid);
|
glBindTexture(GL_TEXTURE_2D, natras->texid);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
||||||
raster->width, raster->height,
|
raster->width, raster->height,
|
||||||
0, natras->format, natras->type, image->pixels);
|
0, natras->format, natras->type, flipped);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
rwFree(flipped);
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -40,31 +40,29 @@ disableAttribPointers(AttribDesc *attribDescs, int32 numAttribs)
|
|||||||
glDisableVertexAttribArray(a->index);
|
glDisableVertexAttribArray(a->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int32
|
||||||
lightingCB(bool32 normals)
|
lightingCB(Atomic *atomic)
|
||||||
{
|
{
|
||||||
World *world;
|
WorldLights lightData;
|
||||||
RGBAf ambLight = { 0.0, 0.0, 0.0, 1.0 };
|
Light *directionals[8];
|
||||||
int n = 0;
|
Light *locals[8];
|
||||||
|
lightData.directionals = directionals;
|
||||||
|
lightData.numDirectionals = 8;
|
||||||
|
lightData.locals = locals;
|
||||||
|
lightData.numLocals = 8;
|
||||||
|
|
||||||
world = (World*)engine->currentWorld;
|
if(atomic->geometry->flags & rw::Geometry::LIGHT){
|
||||||
// only unpositioned lights right now
|
((World*)engine->currentWorld)->enumerateLights(atomic, &lightData);
|
||||||
FORLIST(lnk, world->globalLights){
|
if((atomic->geometry->flags & rw::Geometry::NORMALS) == 0){
|
||||||
Light *l = Light::fromWorld(lnk);
|
// Get rid of lights that need normals when we don't have any
|
||||||
if(normals &&
|
lightData.numDirectionals = 0;
|
||||||
l->getType() == Light::DIRECTIONAL &&
|
lightData.numLocals = 0;
|
||||||
l->getFlags() & Light::LIGHTATOMICS){
|
|
||||||
if(n >= MAX_LIGHTS)
|
|
||||||
continue;
|
|
||||||
setLight(n++, l);
|
|
||||||
}else if(l->getType() == Light::AMBIENT){
|
|
||||||
ambLight.red += l->color.red;
|
|
||||||
ambLight.green += l->color.green;
|
|
||||||
ambLight.blue += l->color.blue;
|
|
||||||
}
|
}
|
||||||
|
return setLights(&lightData);
|
||||||
|
}else{
|
||||||
|
memset(&lightData, 0, sizeof(lightData));
|
||||||
|
return setLights(&lightData);
|
||||||
}
|
}
|
||||||
setNumLights(n);
|
|
||||||
setAmbientLight(&ambLight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define U(i) currentShader->uniformLocations[i]
|
#define U(i) currentShader->uniformLocations[i]
|
||||||
@ -77,7 +75,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
GLfloat surfProps[4];
|
GLfloat surfProps[4];
|
||||||
|
|
||||||
setWorldMatrix(atomic->getFrame()->getLTM());
|
setWorldMatrix(atomic->getFrame()->getLTM());
|
||||||
lightingCB(!!(atomic->geometry->flags & Geometry::NORMALS));
|
lightingCB(atomic);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
|
||||||
@ -86,7 +84,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
InstanceData *inst = header->inst;
|
InstanceData *inst = header->inst;
|
||||||
int32 n = header->numMeshes;
|
int32 n = header->numMeshes;
|
||||||
|
|
||||||
simpleShader->use();
|
defaultShader->use();
|
||||||
|
|
||||||
while(n--){
|
while(n--){
|
||||||
m = inst->material;
|
m = inst->material;
|
||||||
@ -98,7 +96,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
surfProps[1] = m->surfaceProps.specular;
|
surfProps[1] = m->surfaceProps.specular;
|
||||||
surfProps[2] = m->surfaceProps.diffuse;
|
surfProps[2] = m->surfaceProps.diffuse;
|
||||||
surfProps[3] = 0.0f;
|
surfProps[3] = 0.0f;
|
||||||
glUniform4fv(U(u_surfaceProps), 1, surfProps);
|
glUniform4fv(U(u_surfProps), 1, surfProps);
|
||||||
|
|
||||||
setTexture(0, m->texture);
|
setTexture(0, m->texture);
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
namespace rw {
|
namespace rw {
|
||||||
namespace gl3 {
|
namespace gl3 {
|
||||||
|
|
||||||
|
#include "shaders/header_vs.inc"
|
||||||
|
|
||||||
UniformRegistry uniformRegistry;
|
UniformRegistry uniformRegistry;
|
||||||
|
|
||||||
int32
|
int32
|
||||||
@ -89,14 +91,17 @@ loadfile(const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
compileshader(GLenum type, const char *src, GLuint *shader)
|
compileshader(GLenum type, const char **src, GLuint *shader)
|
||||||
{
|
{
|
||||||
|
GLint n;
|
||||||
GLint shdr, success;
|
GLint shdr, success;
|
||||||
GLint len;
|
GLint len;
|
||||||
char *log;
|
char *log;
|
||||||
|
|
||||||
|
for(n = 0; src[n]; n++);
|
||||||
|
|
||||||
shdr = glCreateShader(type);
|
shdr = glCreateShader(type);
|
||||||
glShaderSource(shdr, 1, &src, nil);
|
glShaderSource(shdr, n, src, nil);
|
||||||
glCompileShader(shdr);
|
glCompileShader(shdr);
|
||||||
glGetShaderiv(shdr, GL_COMPILE_STATUS, &success);
|
glGetShaderiv(shdr, GL_COMPILE_STATUS, &success);
|
||||||
if(!success){
|
if(!success){
|
||||||
@ -139,6 +144,58 @@ linkprogram(GLint vs, GLint fs, GLuint *program)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Shader*
|
||||||
|
Shader::create(const char **vsrc, const char **fsrc)
|
||||||
|
{
|
||||||
|
GLuint vs, fs, program;
|
||||||
|
int i;
|
||||||
|
int fail;
|
||||||
|
|
||||||
|
fail = compileshader(GL_VERTEX_SHADER, vsrc, &vs);
|
||||||
|
if(fail)
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
fail = compileshader(GL_FRAGMENT_SHADER, fsrc, &fs);
|
||||||
|
if(fail)
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
fail = linkprogram(vs, fs, &program);
|
||||||
|
if(fail)
|
||||||
|
return nil;
|
||||||
|
glDeleteProgram(vs);
|
||||||
|
glDeleteProgram(fs);
|
||||||
|
|
||||||
|
Shader *sh = rwNewT(Shader, 1, MEMDUR_EVENT | ID_DRIVER); // or global?
|
||||||
|
|
||||||
|
// set uniform block binding
|
||||||
|
for(i = 0; i < uniformRegistry.numBlocks; i++){
|
||||||
|
int idx = glGetUniformBlockIndex(program,
|
||||||
|
uniformRegistry.blockNames[i]);
|
||||||
|
if(idx >= 0)
|
||||||
|
glUniformBlockBinding(program, idx, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// query uniform locations
|
||||||
|
sh->program = program;
|
||||||
|
sh->uniformLocations = rwNewT(GLint, uniformRegistry.numUniforms, MEMDUR_EVENT | ID_DRIVER);
|
||||||
|
for(i = 0; i < uniformRegistry.numUniforms; i++)
|
||||||
|
sh->uniformLocations[i] = glGetUniformLocation(program,
|
||||||
|
uniformRegistry.uniformNames[i]);
|
||||||
|
|
||||||
|
// set samplers
|
||||||
|
glUseProgram(program);
|
||||||
|
char name[64];
|
||||||
|
GLint loc;
|
||||||
|
for(i = 0; i < 4; i++){
|
||||||
|
sprintf(name, "tex%d", i);
|
||||||
|
loc = glGetUniformLocation(program, name);
|
||||||
|
glUniform1i(loc, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sh;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
Shader*
|
Shader*
|
||||||
Shader::fromStrings(const char *vsrc, const char *fsrc)
|
Shader::fromStrings(const char *vsrc, const char *fsrc)
|
||||||
{
|
{
|
||||||
@ -191,6 +248,7 @@ Shader::fromFiles(const char *vspath, const char *fspath)
|
|||||||
rwFree(fsrc);
|
rwFree(fsrc);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
Shader::use(void)
|
Shader::use(void)
|
||||||
|
@ -35,10 +35,15 @@ static void*
|
|||||||
skinOpen(void *o, int32, int32)
|
skinOpen(void *o, int32, int32)
|
||||||
{
|
{
|
||||||
u_boneMatrices = registerUniform("u_boneMatrices");
|
u_boneMatrices = registerUniform("u_boneMatrices");
|
||||||
|
skinGlobals.pipelines[PLATFORM_GL3] = makeSkinPipeline();
|
||||||
|
|
||||||
#include "shaders/simple_fs_gl3.inc"
|
#include "shaders/simple_fs_gl3.inc"
|
||||||
#include "shaders/skin_gl3.inc"
|
#include "shaders/skin_gl3.inc"
|
||||||
skinGlobals.pipelines[PLATFORM_GL3] = makeSkinPipeline();
|
const char *vs[] = { header_vert_src, skin_vert_src, nil };
|
||||||
skinShader = Shader::fromStrings(skin_vert_src, simple_frag_src);
|
const char *fs[] = { simple_frag_src, nil };
|
||||||
|
skinShader = Shader::create(vs, fs);
|
||||||
|
assert(skinShader);
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,23 +221,34 @@ skinUninstanceCB(Geometry *geo, InstanceDataHeader *header)
|
|||||||
static float skinMatrices[64*16];
|
static float skinMatrices[64*16];
|
||||||
|
|
||||||
void
|
void
|
||||||
updateSkinMatrices(Atomic *a)
|
uploadSkinMatrices(Atomic *a)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
Skin *skin = Skin::get(a->geometry);
|
Skin *skin = Skin::get(a->geometry);
|
||||||
HAnimHierarchy *hier = Skin::getHierarchy(a);
|
HAnimHierarchy *hier = Skin::getHierarchy(a);
|
||||||
Matrix *invMats = (Matrix*)skin->inverseMatrices;
|
Matrix *invMats = (Matrix*)skin->inverseMatrices;
|
||||||
|
Matrix tmp;
|
||||||
|
|
||||||
float *m;
|
Matrix *m = (Matrix*)skinMatrices;
|
||||||
m = (float*)skinMatrices;
|
|
||||||
for(int i = 0; i < hier->numNodes; i++){
|
if(hier->flags & HAnimHierarchy::LOCALSPACEMATRICES){
|
||||||
invMats[i].flags = 0;
|
for(i = 0; i < hier->numNodes; i++){
|
||||||
Matrix::mult((Matrix*)m, &invMats[i], &hier->matrices[i]);
|
invMats[i].flags = 0;
|
||||||
m[3] = 0.0f;
|
Matrix::mult(m, &invMats[i], &hier->matrices[i]);
|
||||||
m[7] = 0.0f;
|
m++;
|
||||||
m[11] = 0.0f;
|
}
|
||||||
m[15] = 1.0f;
|
}else{
|
||||||
m += 16;
|
Matrix invAtmMat;
|
||||||
|
Matrix::invert(&invAtmMat, a->getFrame()->getLTM());
|
||||||
|
for(i = 0; i < hier->numNodes; i++){
|
||||||
|
invMats[i].flags = 0;
|
||||||
|
Matrix::mult(&tmp, &hier->matrices[i], &invAtmMat);
|
||||||
|
Matrix::mult(m, &invMats[i], &tmp);
|
||||||
|
m++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
glUniformMatrix4fv(U(u_boneMatrices), 64, GL_FALSE,
|
||||||
|
(GLfloat*)skinMatrices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -243,7 +259,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
GLfloat surfProps[4];
|
GLfloat surfProps[4];
|
||||||
|
|
||||||
setWorldMatrix(atomic->getFrame()->getLTM());
|
setWorldMatrix(atomic->getFrame()->getLTM());
|
||||||
lightingCB(!!(atomic->geometry->flags & Geometry::NORMALS));
|
lightingCB(atomic);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
|
||||||
@ -252,14 +268,9 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
InstanceData *inst = header->inst;
|
InstanceData *inst = header->inst;
|
||||||
int32 n = header->numMeshes;
|
int32 n = header->numMeshes;
|
||||||
|
|
||||||
// rw::setRenderState(ALPHATESTFUNC, 1);
|
|
||||||
// rw::setRenderState(ALPHATESTREF, 50);
|
|
||||||
|
|
||||||
skinShader->use();
|
skinShader->use();
|
||||||
|
|
||||||
updateSkinMatrices(atomic);
|
uploadSkinMatrices(atomic);
|
||||||
glUniformMatrix4fv(U(u_boneMatrices), 64, GL_FALSE,
|
|
||||||
(GLfloat*)skinMatrices);
|
|
||||||
|
|
||||||
while(n--){
|
while(n--){
|
||||||
m = inst->material;
|
m = inst->material;
|
||||||
@ -271,7 +282,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||||||
surfProps[1] = m->surfaceProps.specular;
|
surfProps[1] = m->surfaceProps.specular;
|
||||||
surfProps[2] = m->surfaceProps.diffuse;
|
surfProps[2] = m->surfaceProps.diffuse;
|
||||||
surfProps[3] = 0.0f;
|
surfProps[3] = 0.0f;
|
||||||
glUniform4fv(U(u_surfaceProps), 1, surfProps);
|
glUniform4fv(U(u_surfProps), 1, surfProps);
|
||||||
|
|
||||||
setTexture(0, m->texture);
|
setTexture(0, m->texture);
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ enum AttribIndices
|
|||||||
|
|
||||||
// default uniform indices
|
// default uniform indices
|
||||||
extern int32 u_matColor;
|
extern int32 u_matColor;
|
||||||
extern int32 u_surfaceProps;
|
extern int32 u_surfProps;
|
||||||
|
|
||||||
struct InstanceData
|
struct InstanceData
|
||||||
{
|
{
|
||||||
@ -92,7 +92,7 @@ struct InstanceDataHeader : rw::InstanceDataHeader
|
|||||||
|
|
||||||
struct Shader;
|
struct Shader;
|
||||||
|
|
||||||
extern Shader *simpleShader;
|
extern Shader *defaultShader;
|
||||||
|
|
||||||
struct Im3DVertex
|
struct Im3DVertex
|
||||||
{
|
{
|
||||||
@ -146,15 +146,27 @@ void disableAttribPointers(AttribDesc *attribDescs, int32 numAttribs);
|
|||||||
|
|
||||||
// Render state
|
// Render state
|
||||||
|
|
||||||
|
// Vertex shader bits
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
// These should be low so they could be used as indices
|
||||||
|
VSLIGHT_DIRECT = 1,
|
||||||
|
VSLIGHT_POINT = 2,
|
||||||
|
VSLIGHT_SPOT = 4,
|
||||||
|
VSLIGHT_MASK = 7, // all the above
|
||||||
|
// less critical
|
||||||
|
VSLIGHT_AMBIENT = 8,
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const char *header_vert_src;
|
||||||
|
|
||||||
// per Scene
|
// per Scene
|
||||||
void setProjectionMatrix(float32*);
|
void setProjectionMatrix(float32*);
|
||||||
void setViewMatrix(float32*);
|
void setViewMatrix(float32*);
|
||||||
|
|
||||||
// per Object
|
// per Object
|
||||||
void setWorldMatrix(Matrix*);
|
void setWorldMatrix(Matrix*);
|
||||||
void setAmbientLight(RGBAf*);
|
int32 setLights(WorldLights *lightData);
|
||||||
void setNumLights(int32 n);
|
|
||||||
void setLight(int32 n, Light*);
|
|
||||||
|
|
||||||
// per Mesh
|
// per Mesh
|
||||||
void setTexture(int32 n, Texture *tex);
|
void setTexture(int32 n, Texture *tex);
|
||||||
@ -176,7 +188,7 @@ public:
|
|||||||
void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header);
|
void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header);
|
||||||
void defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header);
|
void defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header);
|
||||||
void defaultRenderCB(Atomic *atomic, InstanceDataHeader *header);
|
void defaultRenderCB(Atomic *atomic, InstanceDataHeader *header);
|
||||||
void lightingCB(bool32 normals);
|
int32 lightingCB(Atomic *atomic);
|
||||||
|
|
||||||
ObjPipeline *makeDefaultPipeline(void);
|
ObjPipeline *makeDefaultPipeline(void);
|
||||||
|
|
||||||
|
@ -31,8 +31,9 @@ struct Shader
|
|||||||
// same number of elements as UniformRegistry::numUniforms
|
// same number of elements as UniformRegistry::numUniforms
|
||||||
GLint *uniformLocations;
|
GLint *uniformLocations;
|
||||||
|
|
||||||
static Shader *fromFiles(const char *vs, const char *fs);
|
static Shader *create(const char **vsrc, const char **fsrc);
|
||||||
static Shader *fromStrings(const char *vsrc, const char *fsrc);
|
// static Shader *fromFiles(const char *vs, const char *fs);
|
||||||
|
// static Shader *fromStrings(const char *vsrc, const char *fsrc);
|
||||||
void use(void);
|
void use(void);
|
||||||
void destroy(void);
|
void destroy(void);
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
all: im2d_gl3.inc im3d_gl3.inc simple_vs_gl3.inc simple_fs_gl3.inc matfx_gl3.inc skin_gl3.inc
|
all: header_vs.inc im2d_gl3.inc im3d_gl3.inc default_vs_gl3.inc simple_fs_gl3.inc matfx_gl3.inc skin_gl3.inc
|
||||||
|
|
||||||
|
header_vs.inc: header.vert
|
||||||
|
(echo 'const char *header_vert_src =';\
|
||||||
|
sed 's/..*/"&\\n"/' header.vert;\
|
||||||
|
echo ';') >header_vs.inc
|
||||||
|
|
||||||
im2d_gl3.inc: im2d.vert
|
im2d_gl3.inc: im2d.vert
|
||||||
(echo 'const char *im2d_vert_src =';\
|
(echo 'const char *im2d_vert_src =';\
|
||||||
@ -10,10 +15,10 @@ im3d_gl3.inc: im3d.vert
|
|||||||
sed 's/..*/"&\\n"/' im3d.vert;\
|
sed 's/..*/"&\\n"/' im3d.vert;\
|
||||||
echo ';') >im3d_gl3.inc
|
echo ';') >im3d_gl3.inc
|
||||||
|
|
||||||
simple_vs_gl3.inc: simple.vert
|
default_vs_gl3.inc: default.vert
|
||||||
(echo 'const char *simple_vert_src =';\
|
(echo 'const char *default_vert_src =';\
|
||||||
sed 's/..*/"&\\n"/' simple.vert;\
|
sed 's/..*/"&\\n"/' default.vert;\
|
||||||
echo ';') >simple_vs_gl3.inc
|
echo ';') >default_vs_gl3.inc
|
||||||
|
|
||||||
simple_fs_gl3.inc: simple.frag
|
simple_fs_gl3.inc: simple.frag
|
||||||
(echo 'const char *simple_frag_src =';\
|
(echo 'const char *simple_frag_src =';\
|
||||||
|
48
src/gl/shaders/default.vert
Normal file
48
src/gl/shaders/default.vert
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
layout(location = 0) in vec3 in_pos;
|
||||||
|
layout(location = 1) in vec3 in_normal;
|
||||||
|
layout(location = 2) in vec4 in_color;
|
||||||
|
layout(location = 3) in vec2 in_tex0;
|
||||||
|
|
||||||
|
out vec4 v_color;
|
||||||
|
out vec2 v_tex0;
|
||||||
|
out float v_fog;
|
||||||
|
|
||||||
|
void
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
vec4 V = u_world * vec4(in_pos, 1.0);
|
||||||
|
gl_Position = u_proj * u_view * V;
|
||||||
|
vec3 N = mat3(u_world) * in_normal;
|
||||||
|
|
||||||
|
v_tex0 = in_tex0;
|
||||||
|
|
||||||
|
v_color = in_color;
|
||||||
|
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
||||||
|
|
||||||
|
#ifdef DIRECTIONALS
|
||||||
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
|
if(u_directLights[i].enabled == 0.0)
|
||||||
|
break;
|
||||||
|
v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef POINTLIGHTS
|
||||||
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
|
if(u_pointLights[i].enabled == 0.0)
|
||||||
|
break;
|
||||||
|
v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef SPOTLIGHTS
|
||||||
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
|
if(u_spotLights[i].enabled == 0.0)
|
||||||
|
break;
|
||||||
|
v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
v_color = clamp(v_color, 0.0f, 1.0);
|
||||||
|
v_color *= u_matColor;
|
||||||
|
|
||||||
|
v_fog = DoFog(gl_Position.w);
|
||||||
|
}
|
50
src/gl/shaders/default_vs_gl3.inc
Normal file
50
src/gl/shaders/default_vs_gl3.inc
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
const char *default_vert_src =
|
||||||
|
"layout(location = 0) in vec3 in_pos;\n"
|
||||||
|
"layout(location = 1) in vec3 in_normal;\n"
|
||||||
|
"layout(location = 2) in vec4 in_color;\n"
|
||||||
|
"layout(location = 3) in vec2 in_tex0;\n"
|
||||||
|
|
||||||
|
"out vec4 v_color;\n"
|
||||||
|
"out vec2 v_tex0;\n"
|
||||||
|
"out float v_fog;\n"
|
||||||
|
|
||||||
|
"void\n"
|
||||||
|
"main(void)\n"
|
||||||
|
"{\n"
|
||||||
|
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
|
||||||
|
" gl_Position = u_proj * u_view * V;\n"
|
||||||
|
" vec3 N = mat3(u_world) * in_normal;\n"
|
||||||
|
|
||||||
|
" v_tex0 = in_tex0;\n"
|
||||||
|
|
||||||
|
" v_color = in_color;\n"
|
||||||
|
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
||||||
|
|
||||||
|
"#ifdef DIRECTIONALS\n"
|
||||||
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
|
" if(u_directLights[i].enabled == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
|
" v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;\n"
|
||||||
|
" }\n"
|
||||||
|
"#endif\n"
|
||||||
|
"#ifdef POINTLIGHTS\n"
|
||||||
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
|
" if(u_pointLights[i].enabled == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
|
" v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||||
|
" }\n"
|
||||||
|
"#endif\n"
|
||||||
|
"#ifdef SPOTLIGHTS\n"
|
||||||
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
|
" if(u_spotLights[i].enabled == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
|
" v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||||
|
" }\n"
|
||||||
|
"#endif\n"
|
||||||
|
|
||||||
|
" v_color = clamp(v_color, 0.0f, 1.0);\n"
|
||||||
|
" v_color *= u_matColor;\n"
|
||||||
|
|
||||||
|
" v_fog = DoFog(gl_Position.w);\n"
|
||||||
|
"}\n"
|
||||||
|
;
|
88
src/gl/shaders/header.vert
Normal file
88
src/gl/shaders/header.vert
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
layout(std140) uniform State
|
||||||
|
{
|
||||||
|
int u_alphaTest;
|
||||||
|
float u_alphaRef;
|
||||||
|
|
||||||
|
float u_fogStart;
|
||||||
|
float u_fogEnd;
|
||||||
|
float u_fogRange;
|
||||||
|
float u_fogDisable;
|
||||||
|
vec4 u_fogColor;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(std140) uniform Scene
|
||||||
|
{
|
||||||
|
mat4 u_proj;
|
||||||
|
mat4 u_view;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 8
|
||||||
|
struct Light {
|
||||||
|
float enabled;
|
||||||
|
float radius;
|
||||||
|
float minusCosAngle;
|
||||||
|
float hardSpot;
|
||||||
|
vec4 position;
|
||||||
|
vec4 direction;
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
layout(std140) uniform Object
|
||||||
|
{
|
||||||
|
mat4 u_world;
|
||||||
|
vec4 u_ambLight;
|
||||||
|
Light u_directLights[MAX_LIGHTS];
|
||||||
|
Light u_pointLights[MAX_LIGHTS];
|
||||||
|
Light u_spotLights[MAX_LIGHTS];
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform vec4 u_matColor;
|
||||||
|
uniform vec4 u_surfProps; // amb, spec, diff, extra
|
||||||
|
|
||||||
|
#define surfAmbient (u_surfProps.x)
|
||||||
|
#define surfSpecular (u_surfProps.y)
|
||||||
|
#define surfDiffuse (u_surfProps.z)
|
||||||
|
|
||||||
|
vec3 DoDirLight(Light L, vec3 N)
|
||||||
|
{
|
||||||
|
float l = max(0.0, dot(N, -L.direction.xyz));
|
||||||
|
return l*L.color.rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 DoPointLight(Light L, vec3 V, vec3 N)
|
||||||
|
{
|
||||||
|
// As on PS2
|
||||||
|
vec3 dir = V - L.position.xyz;
|
||||||
|
float dist = length(dir);
|
||||||
|
float atten = max(0.0, (1.0 - dist/L.radius));
|
||||||
|
float l = max(0.0, dot(N, -normalize(dir)));
|
||||||
|
return l*L.color.rgb*atten;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 DoSpotLight(Light L, vec3 V, vec3 N)
|
||||||
|
{
|
||||||
|
// As on PS2
|
||||||
|
vec3 dir = V - L.position.xyz;
|
||||||
|
float dist = length(dir);
|
||||||
|
float atten = max(0.0, (1.0 - dist/L.radius));
|
||||||
|
dir /= dist;
|
||||||
|
float l = max(0.0, dot(N, -dir));
|
||||||
|
float pcos = dot(dir, L.direction.xyz); // cos to point
|
||||||
|
float ccos = -L.minusCosAngle;
|
||||||
|
float falloff = (pcos-ccos)/(1.0-ccos);
|
||||||
|
if(falloff < 0) // outside of cone
|
||||||
|
l = 0;
|
||||||
|
l *= max(falloff, L.hardSpot);
|
||||||
|
return l*L.color.xyz*atten;
|
||||||
|
}
|
||||||
|
|
||||||
|
float DoFog(float w)
|
||||||
|
{
|
||||||
|
return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DIRECTIONALS
|
||||||
|
//#define POINTLIGHTS
|
||||||
|
//#define SPOTLIGHTS
|
89
src/gl/shaders/header_vs.inc
Normal file
89
src/gl/shaders/header_vs.inc
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
const char *header_vert_src =
|
||||||
|
"#version 330\n"
|
||||||
|
|
||||||
|
"layout(std140) uniform State\n"
|
||||||
|
"{\n"
|
||||||
|
" int u_alphaTest;\n"
|
||||||
|
" float u_alphaRef;\n"
|
||||||
|
|
||||||
|
" float u_fogStart;\n"
|
||||||
|
" float u_fogEnd;\n"
|
||||||
|
" float u_fogRange;\n"
|
||||||
|
" float u_fogDisable;\n"
|
||||||
|
" vec4 u_fogColor;\n"
|
||||||
|
"};\n"
|
||||||
|
|
||||||
|
"layout(std140) uniform Scene\n"
|
||||||
|
"{\n"
|
||||||
|
" mat4 u_proj;\n"
|
||||||
|
" mat4 u_view;\n"
|
||||||
|
"};\n"
|
||||||
|
|
||||||
|
"#define MAX_LIGHTS 8\n"
|
||||||
|
"struct Light {\n"
|
||||||
|
" float enabled;\n"
|
||||||
|
" float radius;\n"
|
||||||
|
" float minusCosAngle;\n"
|
||||||
|
" float hardSpot;\n"
|
||||||
|
" vec4 position;\n"
|
||||||
|
" vec4 direction;\n"
|
||||||
|
" vec4 color;\n"
|
||||||
|
"};\n"
|
||||||
|
|
||||||
|
"layout(std140) uniform Object\n"
|
||||||
|
"{\n"
|
||||||
|
" mat4 u_world;\n"
|
||||||
|
" vec4 u_ambLight;\n"
|
||||||
|
" Light u_directLights[MAX_LIGHTS];\n"
|
||||||
|
" Light u_pointLights[MAX_LIGHTS];\n"
|
||||||
|
" Light u_spotLights[MAX_LIGHTS];\n"
|
||||||
|
"};\n"
|
||||||
|
|
||||||
|
"uniform vec4 u_matColor;\n"
|
||||||
|
"uniform vec4 u_surfProps; // amb, spec, diff, extra\n"
|
||||||
|
|
||||||
|
"#define surfAmbient (u_surfProps.x)\n"
|
||||||
|
"#define surfSpecular (u_surfProps.y)\n"
|
||||||
|
"#define surfDiffuse (u_surfProps.z)\n"
|
||||||
|
|
||||||
|
"vec3 DoDirLight(Light L, vec3 N)\n"
|
||||||
|
"{\n"
|
||||||
|
" float l = max(0.0, dot(N, -L.direction.xyz));\n"
|
||||||
|
" return l*L.color.rgb;\n"
|
||||||
|
"}\n"
|
||||||
|
|
||||||
|
"vec3 DoPointLight(Light L, vec3 V, vec3 N)\n"
|
||||||
|
"{\n"
|
||||||
|
" // As on PS2\n"
|
||||||
|
" vec3 dir = V - L.position.xyz;\n"
|
||||||
|
" float dist = length(dir);\n"
|
||||||
|
" float atten = max(0.0, (1.0 - dist/L.radius));\n"
|
||||||
|
" float l = max(0.0, dot(N, -normalize(dir)));\n"
|
||||||
|
" return l*L.color.rgb*atten;\n"
|
||||||
|
"}\n"
|
||||||
|
|
||||||
|
"vec3 DoSpotLight(Light L, vec3 V, vec3 N)\n"
|
||||||
|
"{\n"
|
||||||
|
" // As on PS2\n"
|
||||||
|
" vec3 dir = V - L.position.xyz;\n"
|
||||||
|
" float dist = length(dir);\n"
|
||||||
|
" float atten = max(0.0, (1.0 - dist/L.radius));\n"
|
||||||
|
" dir /= dist;\n"
|
||||||
|
" float l = max(0.0, dot(N, -dir));\n"
|
||||||
|
" float pcos = dot(dir, L.direction.xyz); // cos to point\n"
|
||||||
|
" float ccos = -L.minusCosAngle;\n"
|
||||||
|
" float falloff = (pcos-ccos)/(1.0-ccos);\n"
|
||||||
|
" if(falloff < 0) // outside of cone\n"
|
||||||
|
" l = 0;\n"
|
||||||
|
" l *= max(falloff, L.hardSpot);\n"
|
||||||
|
" return l*L.color.xyz*atten;\n"
|
||||||
|
"}\n"
|
||||||
|
|
||||||
|
"float DoFog(float w)\n"
|
||||||
|
"{\n"
|
||||||
|
" return clamp((w - u_fogEnd)*u_fogRange, u_fogDisable, 1.0);\n"
|
||||||
|
"}\n"
|
||||||
|
|
||||||
|
"#define DIRECTIONALS\n"
|
||||||
|
"//#define POINTLIGHTS\n"
|
||||||
|
"//#define SPOTLIGHTS\n";
|
@ -1,16 +1,3 @@
|
|||||||
#version 330
|
|
||||||
|
|
||||||
layout(std140) uniform State
|
|
||||||
{
|
|
||||||
int u_alphaTest;
|
|
||||||
float u_alphaRef;
|
|
||||||
|
|
||||||
int u_fogEnable;
|
|
||||||
float u_fogStart;
|
|
||||||
float u_fogEnd;
|
|
||||||
vec4 u_fogColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform vec4 u_xform;
|
uniform vec4 u_xform;
|
||||||
|
|
||||||
layout(location = 0) in vec4 in_pos;
|
layout(location = 0) in vec4 in_pos;
|
||||||
@ -26,8 +13,8 @@ main(void)
|
|||||||
{
|
{
|
||||||
gl_Position = in_pos;
|
gl_Position = in_pos;
|
||||||
gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw;
|
gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw;
|
||||||
|
v_fog = DoFog(gl_Position.z);
|
||||||
gl_Position.xyz *= gl_Position.w;
|
gl_Position.xyz *= gl_Position.w;
|
||||||
v_color = in_color;
|
v_color = in_color;
|
||||||
v_tex0 = in_tex0;
|
v_tex0 = in_tex0;
|
||||||
v_fog = clamp((gl_Position.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,4 @@
|
|||||||
const char *im2d_vert_src =
|
const char *im2d_vert_src =
|
||||||
"#version 330\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform State\n"
|
|
||||||
"{\n"
|
|
||||||
" int u_alphaTest;\n"
|
|
||||||
" float u_alphaRef;\n"
|
|
||||||
|
|
||||||
" int u_fogEnable;\n"
|
|
||||||
" float u_fogStart;\n"
|
|
||||||
" float u_fogEnd;\n"
|
|
||||||
" vec4 u_fogColor;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"uniform vec4 u_xform;\n"
|
"uniform vec4 u_xform;\n"
|
||||||
|
|
||||||
"layout(location = 0) in vec4 in_pos;\n"
|
"layout(location = 0) in vec4 in_pos;\n"
|
||||||
@ -27,9 +14,9 @@ const char *im2d_vert_src =
|
|||||||
"{\n"
|
"{\n"
|
||||||
" gl_Position = in_pos;\n"
|
" gl_Position = in_pos;\n"
|
||||||
" gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw;\n"
|
" gl_Position.xy = gl_Position.xy * u_xform.xy + u_xform.zw;\n"
|
||||||
|
" v_fog = DoFog(gl_Position.z);\n"
|
||||||
" gl_Position.xyz *= gl_Position.w;\n"
|
" gl_Position.xyz *= gl_Position.w;\n"
|
||||||
" v_color = in_color;\n"
|
" v_color = in_color;\n"
|
||||||
" v_tex0 = in_tex0;\n"
|
" v_tex0 = in_tex0;\n"
|
||||||
" v_fog = clamp((gl_Position.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
|
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
|
@ -1,27 +1,3 @@
|
|||||||
#version 330
|
|
||||||
|
|
||||||
layout(std140) uniform State
|
|
||||||
{
|
|
||||||
int u_alphaTest;
|
|
||||||
float u_alphaRef;
|
|
||||||
|
|
||||||
int u_fogEnable;
|
|
||||||
float u_fogStart;
|
|
||||||
float u_fogEnd;
|
|
||||||
vec4 u_fogColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform Scene
|
|
||||||
{
|
|
||||||
mat4 u_proj;
|
|
||||||
mat4 u_view;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform Object
|
|
||||||
{
|
|
||||||
mat4 u_world;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 in_pos;
|
layout(location = 0) in vec3 in_pos;
|
||||||
layout(location = 2) in vec4 in_color;
|
layout(location = 2) in vec4 in_color;
|
||||||
layout(location = 3) in vec2 in_tex0;
|
layout(location = 3) in vec2 in_tex0;
|
||||||
@ -38,5 +14,5 @@ main(void)
|
|||||||
gl_Position = u_proj * cV;
|
gl_Position = u_proj * cV;
|
||||||
v_color = in_color;
|
v_color = in_color;
|
||||||
v_tex0 = in_tex0;
|
v_tex0 = in_tex0;
|
||||||
v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
|
v_fog = DoFog(gl_Position.w);
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,4 @@
|
|||||||
const char *im3d_vert_src =
|
const char *im3d_vert_src =
|
||||||
"#version 330\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform State\n"
|
|
||||||
"{\n"
|
|
||||||
" int u_alphaTest;\n"
|
|
||||||
" float u_alphaRef;\n"
|
|
||||||
|
|
||||||
" int u_fogEnable;\n"
|
|
||||||
" float u_fogStart;\n"
|
|
||||||
" float u_fogEnd;\n"
|
|
||||||
" vec4 u_fogColor;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform Scene\n"
|
|
||||||
"{\n"
|
|
||||||
" mat4 u_proj;\n"
|
|
||||||
" mat4 u_view;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform Object\n"
|
|
||||||
"{\n"
|
|
||||||
" mat4 u_world;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"layout(location = 0) in vec3 in_pos;\n"
|
"layout(location = 0) in vec3 in_pos;\n"
|
||||||
"layout(location = 2) in vec4 in_color;\n"
|
"layout(location = 2) in vec4 in_color;\n"
|
||||||
"layout(location = 3) in vec2 in_tex0;\n"
|
"layout(location = 3) in vec2 in_tex0;\n"
|
||||||
@ -35,10 +11,10 @@ const char *im3d_vert_src =
|
|||||||
"main(void)\n"
|
"main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
|
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
|
||||||
" vec4 cV = u_view * V; \n"
|
" vec4 cV = u_view * V;\n"
|
||||||
" gl_Position = u_proj * cV;\n"
|
" gl_Position = u_proj * cV;\n"
|
||||||
" v_color = in_color;\n"
|
" v_color = in_color;\n"
|
||||||
" v_tex0 = in_tex0;\n"
|
" v_tex0 = in_tex0;\n"
|
||||||
" v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
|
" v_fog = DoFog(gl_Position.w);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
|
@ -4,20 +4,38 @@ layout(std140) uniform State
|
|||||||
{
|
{
|
||||||
int u_alphaTest;
|
int u_alphaTest;
|
||||||
float u_alphaRef;
|
float u_alphaRef;
|
||||||
// fog etc.
|
|
||||||
|
float u_fogStart;
|
||||||
|
float u_fogEnd;
|
||||||
|
float u_fogRange;
|
||||||
|
float u_fogDisable;
|
||||||
|
vec4 u_fogColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex0;
|
||||||
|
uniform sampler2D tex1;
|
||||||
|
|
||||||
|
uniform float u_coefficient;
|
||||||
|
|
||||||
in vec4 v_color;
|
in vec4 v_color;
|
||||||
in vec2 v_tex0;
|
in vec2 v_tex0;
|
||||||
|
in vec2 v_tex1;
|
||||||
|
in float v_fog;
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
void
|
void
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
color = v_color*texture(tex, vec2(v_tex0.x, v_tex0.y));
|
vec4 pass1 = v_color;
|
||||||
|
vec4 envColor = pass1; // TODO: colorClamp
|
||||||
|
|
||||||
|
pass1 *= texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
|
||||||
|
vec4 pass2 = envColor*u_coefficient*texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y));
|
||||||
|
|
||||||
|
color.rgb = pass1.rgb*pass1.a + pass2.rgb;
|
||||||
|
color.a = pass1.a;
|
||||||
|
|
||||||
switch(u_alphaTest){
|
switch(u_alphaTest){
|
||||||
default:
|
default:
|
||||||
case 0: break;
|
case 0: break;
|
||||||
@ -31,4 +49,3 @@ main(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,33 +1,4 @@
|
|||||||
#version 330
|
|
||||||
|
|
||||||
layout(std140) uniform Scene
|
|
||||||
{
|
|
||||||
mat4 u_proj;
|
|
||||||
mat4 u_view;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAX_LIGHTS 8
|
|
||||||
struct Light {
|
|
||||||
vec4 position;
|
|
||||||
vec4 direction;
|
|
||||||
vec4 color;
|
|
||||||
float radius;
|
|
||||||
float minusCosAngle;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform Object
|
|
||||||
{
|
|
||||||
mat4 u_world;
|
|
||||||
vec4 u_ambLight;
|
|
||||||
int u_numLights;
|
|
||||||
Light u_lights[MAX_LIGHTS];
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform vec4 u_matColor;
|
|
||||||
uniform vec4 u_surfaceProps; // amb, spec, diff, extra
|
|
||||||
|
|
||||||
uniform mat4 u_texMatrix;
|
uniform mat4 u_texMatrix;
|
||||||
uniform float u_coefficient;
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 in_pos;
|
layout(location = 0) in vec3 in_pos;
|
||||||
layout(location = 1) in vec3 in_normal;
|
layout(location = 1) in vec3 in_normal;
|
||||||
@ -36,6 +7,8 @@ layout(location = 3) in vec2 in_tex0;
|
|||||||
|
|
||||||
out vec4 v_color;
|
out vec4 v_color;
|
||||||
out vec2 v_tex0;
|
out vec2 v_tex0;
|
||||||
|
out vec2 v_tex1;
|
||||||
|
out float v_fog;
|
||||||
|
|
||||||
void
|
void
|
||||||
main(void)
|
main(void)
|
||||||
@ -44,15 +17,36 @@ main(void)
|
|||||||
gl_Position = u_proj * u_view * V;
|
gl_Position = u_proj * u_view * V;
|
||||||
vec3 N = mat3(u_world) * in_normal;
|
vec3 N = mat3(u_world) * in_normal;
|
||||||
|
|
||||||
|
v_tex0 = in_tex0;
|
||||||
|
v_tex1 = (u_texMatrix * vec4(N, 1.0)).xy;
|
||||||
|
|
||||||
v_color = in_color;
|
v_color = in_color;
|
||||||
for(int i = 0; i < u_numLights; i++){
|
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
||||||
float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));
|
|
||||||
v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;
|
#ifdef DIRECTIONALS
|
||||||
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
|
if(u_directLights[i].enabled == 0.0)
|
||||||
|
break;
|
||||||
|
v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;
|
||||||
}
|
}
|
||||||
v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;
|
#endif
|
||||||
|
#ifdef POINTLIGHTS
|
||||||
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
|
if(u_pointLights[i].enabled == 0.0)
|
||||||
|
break;
|
||||||
|
v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef SPOTLIGHTS
|
||||||
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
|
if(u_spotLights[i].enabled == 0.0)
|
||||||
|
break;
|
||||||
|
v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
v_color = clamp(v_color, 0.0f, 1.0);
|
||||||
v_color *= u_matColor;
|
v_color *= u_matColor;
|
||||||
|
|
||||||
v_color *= u_coefficient;
|
v_fog = DoFog(gl_Position.w);
|
||||||
vec3 cN = mat3(u_view) * in_normal;
|
|
||||||
v_tex0 = (u_texMatrix * vec4(cN, 1.0)).xy;
|
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,5 @@
|
|||||||
const char *matfx_env_vert_src =
|
const char *matfx_env_vert_src =
|
||||||
"#version 330\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform Scene\n"
|
|
||||||
"{\n"
|
|
||||||
" mat4 u_proj;\n"
|
|
||||||
" mat4 u_view;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"#define MAX_LIGHTS 8\n"
|
|
||||||
"struct Light {\n"
|
|
||||||
" vec4 position;\n"
|
|
||||||
" vec4 direction;\n"
|
|
||||||
" vec4 color;\n"
|
|
||||||
" float radius;\n"
|
|
||||||
" float minusCosAngle;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform Object\n"
|
|
||||||
"{\n"
|
|
||||||
" mat4 u_world;\n"
|
|
||||||
" vec4 u_ambLight;\n"
|
|
||||||
" int u_numLights;\n"
|
|
||||||
" Light u_lights[MAX_LIGHTS];\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"uniform vec4 u_matColor;\n"
|
|
||||||
"uniform vec4 u_surfaceProps; // amb, spec, diff, extra\n"
|
|
||||||
|
|
||||||
"uniform mat4 u_texMatrix;\n"
|
"uniform mat4 u_texMatrix;\n"
|
||||||
"uniform float u_coefficient;\n"
|
|
||||||
|
|
||||||
"layout(location = 0) in vec3 in_pos;\n"
|
"layout(location = 0) in vec3 in_pos;\n"
|
||||||
"layout(location = 1) in vec3 in_normal;\n"
|
"layout(location = 1) in vec3 in_normal;\n"
|
||||||
@ -37,6 +8,8 @@ const char *matfx_env_vert_src =
|
|||||||
|
|
||||||
"out vec4 v_color;\n"
|
"out vec4 v_color;\n"
|
||||||
"out vec2 v_tex0;\n"
|
"out vec2 v_tex0;\n"
|
||||||
|
"out vec2 v_tex1;\n"
|
||||||
|
"out float v_fog;\n"
|
||||||
|
|
||||||
"void\n"
|
"void\n"
|
||||||
"main(void)\n"
|
"main(void)\n"
|
||||||
@ -45,17 +18,38 @@ const char *matfx_env_vert_src =
|
|||||||
" gl_Position = u_proj * u_view * V;\n"
|
" gl_Position = u_proj * u_view * V;\n"
|
||||||
" vec3 N = mat3(u_world) * in_normal;\n"
|
" vec3 N = mat3(u_world) * in_normal;\n"
|
||||||
|
|
||||||
|
" v_tex0 = in_tex0;\n"
|
||||||
|
" v_tex1 = (u_texMatrix * vec4(N, 1.0)).xy;\n"
|
||||||
|
|
||||||
" v_color = in_color;\n"
|
" v_color = in_color;\n"
|
||||||
" for(int i = 0; i < u_numLights; i++){\n"
|
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
||||||
" float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));\n"
|
|
||||||
" v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;\n"
|
"#ifdef DIRECTIONALS\n"
|
||||||
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
|
" if(u_directLights[i].enabled == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
|
" v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;\n"
|
"#endif\n"
|
||||||
|
"#ifdef POINTLIGHTS\n"
|
||||||
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
|
" if(u_pointLights[i].enabled == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
|
" v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||||
|
" }\n"
|
||||||
|
"#endif\n"
|
||||||
|
"#ifdef SPOTLIGHTS\n"
|
||||||
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
|
" if(u_spotLights[i].enabled == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
|
" v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||||
|
" }\n"
|
||||||
|
"#endif\n"
|
||||||
|
|
||||||
|
" v_color = clamp(v_color, 0.0f, 1.0);\n"
|
||||||
" v_color *= u_matColor;\n"
|
" v_color *= u_matColor;\n"
|
||||||
|
|
||||||
" v_color *= u_coefficient;\n"
|
" v_fog = DoFog(gl_Position.w);\n"
|
||||||
" vec3 cN = mat3(u_view) * in_normal;\n"
|
|
||||||
" v_tex0 = (u_texMatrix * vec4(cN, 1.0)).xy;\n"
|
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
const char *matfx_env_frag_src =
|
const char *matfx_env_frag_src =
|
||||||
@ -65,20 +59,38 @@ const char *matfx_env_frag_src =
|
|||||||
"{\n"
|
"{\n"
|
||||||
" int u_alphaTest;\n"
|
" int u_alphaTest;\n"
|
||||||
" float u_alphaRef;\n"
|
" float u_alphaRef;\n"
|
||||||
" // fog etc.\n"
|
|
||||||
|
" float u_fogStart;\n"
|
||||||
|
" float u_fogEnd;\n"
|
||||||
|
" float u_fogRange;\n"
|
||||||
|
" float u_fogDisable;\n"
|
||||||
|
" vec4 u_fogColor;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
|
|
||||||
"uniform sampler2D tex;\n"
|
"uniform sampler2D tex0;\n"
|
||||||
|
"uniform sampler2D tex1;\n"
|
||||||
|
|
||||||
|
"uniform float u_coefficient;\n"
|
||||||
|
|
||||||
"in vec4 v_color;\n"
|
"in vec4 v_color;\n"
|
||||||
"in vec2 v_tex0;\n"
|
"in vec2 v_tex0;\n"
|
||||||
|
"in vec2 v_tex1;\n"
|
||||||
|
"in float v_fog;\n"
|
||||||
|
|
||||||
"out vec4 color;\n"
|
"out vec4 color;\n"
|
||||||
|
|
||||||
"void\n"
|
"void\n"
|
||||||
"main(void)\n"
|
"main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" color = v_color*texture(tex, vec2(v_tex0.x, v_tex0.y));\n"
|
" vec4 pass1 = v_color;\n"
|
||||||
|
" vec4 envColor = pass1; // TODO: colorClamp\n"
|
||||||
|
|
||||||
|
" pass1 *= texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n"
|
||||||
|
" vec4 pass2 = envColor*u_coefficient*texture(tex1, vec2(v_tex1.x, 1.0-v_tex1.y));\n"
|
||||||
|
|
||||||
|
" color.rgb = pass1.rgb*pass1.a + pass2.rgb;\n"
|
||||||
|
" color.a = pass1.a;\n"
|
||||||
|
|
||||||
" switch(u_alphaTest){\n"
|
" switch(u_alphaTest){\n"
|
||||||
" default:\n"
|
" default:\n"
|
||||||
" case 0: break;\n"
|
" case 0: break;\n"
|
||||||
@ -92,5 +104,4 @@ const char *matfx_env_frag_src =
|
|||||||
" break;\n"
|
" break;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
|
|
||||||
;
|
;
|
||||||
|
@ -5,13 +5,14 @@ layout(std140) uniform State
|
|||||||
int u_alphaTest;
|
int u_alphaTest;
|
||||||
float u_alphaRef;
|
float u_alphaRef;
|
||||||
|
|
||||||
int u_fogEnable;
|
|
||||||
float u_fogStart;
|
float u_fogStart;
|
||||||
float u_fogEnd;
|
float u_fogEnd;
|
||||||
|
float u_fogRange;
|
||||||
|
float u_fogDisable;
|
||||||
vec4 u_fogColor;
|
vec4 u_fogColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex0;
|
||||||
|
|
||||||
in vec4 v_color;
|
in vec4 v_color;
|
||||||
in vec2 v_tex0;
|
in vec2 v_tex0;
|
||||||
@ -22,9 +23,8 @@ out vec4 color;
|
|||||||
void
|
void
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
color = v_color*texture(tex, vec2(v_tex0.x, v_tex0.y));
|
color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));
|
||||||
if(u_fogEnable != 0)
|
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
|
||||||
color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);
|
|
||||||
switch(u_alphaTest){
|
switch(u_alphaTest){
|
||||||
default:
|
default:
|
||||||
case 0: break;
|
case 0: break;
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
#version 330
|
|
||||||
|
|
||||||
layout(std140) uniform State
|
|
||||||
{
|
|
||||||
int u_alphaTest;
|
|
||||||
float u_alphaRef;
|
|
||||||
|
|
||||||
int u_fogEnable;
|
|
||||||
float u_fogStart;
|
|
||||||
float u_fogEnd;
|
|
||||||
vec4 u_fogColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform Scene
|
|
||||||
{
|
|
||||||
mat4 u_proj;
|
|
||||||
mat4 u_view;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAX_LIGHTS 8
|
|
||||||
struct Light {
|
|
||||||
vec4 position;
|
|
||||||
vec4 direction;
|
|
||||||
vec4 color;
|
|
||||||
float radius;
|
|
||||||
float minusCosAngle;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform Object
|
|
||||||
{
|
|
||||||
mat4 u_world;
|
|
||||||
vec4 u_ambLight;
|
|
||||||
int u_numLights;
|
|
||||||
Light u_lights[MAX_LIGHTS];
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform vec4 u_matColor;
|
|
||||||
uniform vec4 u_surfaceProps; // amb, spec, diff, extra
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 in_pos;
|
|
||||||
layout(location = 1) in vec3 in_normal;
|
|
||||||
layout(location = 2) in vec4 in_color;
|
|
||||||
layout(location = 3) in vec2 in_tex0;
|
|
||||||
|
|
||||||
out vec4 v_color;
|
|
||||||
out vec2 v_tex0;
|
|
||||||
out float v_fog;
|
|
||||||
|
|
||||||
void
|
|
||||||
main(void)
|
|
||||||
{
|
|
||||||
vec4 V = u_world * vec4(in_pos, 1.0);
|
|
||||||
vec4 cV = u_view * V;
|
|
||||||
gl_Position = u_proj * cV;
|
|
||||||
vec3 N = mat3(u_world) * in_normal;
|
|
||||||
|
|
||||||
v_color = in_color;
|
|
||||||
for(int i = 0; i < u_numLights; i++){
|
|
||||||
float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));
|
|
||||||
v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;
|
|
||||||
}
|
|
||||||
v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;
|
|
||||||
v_color *= u_matColor;
|
|
||||||
|
|
||||||
v_tex0 = in_tex0;
|
|
||||||
|
|
||||||
v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
|
|
||||||
}
|
|
@ -6,13 +6,14 @@ const char *simple_frag_src =
|
|||||||
" int u_alphaTest;\n"
|
" int u_alphaTest;\n"
|
||||||
" float u_alphaRef;\n"
|
" float u_alphaRef;\n"
|
||||||
|
|
||||||
" int u_fogEnable;\n"
|
|
||||||
" float u_fogStart;\n"
|
" float u_fogStart;\n"
|
||||||
" float u_fogEnd;\n"
|
" float u_fogEnd;\n"
|
||||||
|
" float u_fogRange;\n"
|
||||||
|
" float u_fogDisable;\n"
|
||||||
" vec4 u_fogColor;\n"
|
" vec4 u_fogColor;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
|
|
||||||
"uniform sampler2D tex;\n"
|
"uniform sampler2D tex0;\n"
|
||||||
|
|
||||||
"in vec4 v_color;\n"
|
"in vec4 v_color;\n"
|
||||||
"in vec2 v_tex0;\n"
|
"in vec2 v_tex0;\n"
|
||||||
@ -23,9 +24,8 @@ const char *simple_frag_src =
|
|||||||
"void\n"
|
"void\n"
|
||||||
"main(void)\n"
|
"main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" color = v_color*texture(tex, vec2(v_tex0.x, v_tex0.y));\n"
|
" color = v_color*texture(tex0, vec2(v_tex0.x, 1.0-v_tex0.y));\n"
|
||||||
" if(u_fogEnable != 0)\n"
|
" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n"
|
||||||
" color.rgb = mix(u_fogColor.rgb, color.rgb, v_fog);\n"
|
|
||||||
" switch(u_alphaTest){\n"
|
" switch(u_alphaTest){\n"
|
||||||
" default:\n"
|
" default:\n"
|
||||||
" case 0: break;\n"
|
" case 0: break;\n"
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
const char *simple_vert_src =
|
|
||||||
"#version 330\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform State\n"
|
|
||||||
"{\n"
|
|
||||||
" int u_alphaTest;\n"
|
|
||||||
" float u_alphaRef;\n"
|
|
||||||
|
|
||||||
" int u_fogEnable;\n"
|
|
||||||
" float u_fogStart;\n"
|
|
||||||
" float u_fogEnd;\n"
|
|
||||||
" vec4 u_fogColor;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform Scene\n"
|
|
||||||
"{\n"
|
|
||||||
" mat4 u_proj;\n"
|
|
||||||
" mat4 u_view;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"#define MAX_LIGHTS 8\n"
|
|
||||||
"struct Light {\n"
|
|
||||||
" vec4 position;\n"
|
|
||||||
" vec4 direction;\n"
|
|
||||||
" vec4 color;\n"
|
|
||||||
" float radius;\n"
|
|
||||||
" float minusCosAngle;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform Object\n"
|
|
||||||
"{\n"
|
|
||||||
" mat4 u_world;\n"
|
|
||||||
" vec4 u_ambLight;\n"
|
|
||||||
" int u_numLights;\n"
|
|
||||||
" Light u_lights[MAX_LIGHTS];\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"uniform vec4 u_matColor;\n"
|
|
||||||
"uniform vec4 u_surfaceProps; // amb, spec, diff, extra\n"
|
|
||||||
|
|
||||||
"layout(location = 0) in vec3 in_pos;\n"
|
|
||||||
"layout(location = 1) in vec3 in_normal;\n"
|
|
||||||
"layout(location = 2) in vec4 in_color;\n"
|
|
||||||
"layout(location = 3) in vec2 in_tex0;\n"
|
|
||||||
|
|
||||||
"out vec4 v_color;\n"
|
|
||||||
"out vec2 v_tex0;\n"
|
|
||||||
"out float v_fog;\n"
|
|
||||||
|
|
||||||
"void\n"
|
|
||||||
"main(void)\n"
|
|
||||||
"{\n"
|
|
||||||
" vec3 lightdir = vec3(1.0, 1.0, -1.0);\n"
|
|
||||||
|
|
||||||
" vec4 V = u_world * vec4(in_pos, 1.0);\n"
|
|
||||||
" vec4 cV = u_view * V; \n"
|
|
||||||
" gl_Position = u_proj * cV;\n"
|
|
||||||
" vec3 N = mat3(u_world) * in_normal;\n"
|
|
||||||
|
|
||||||
" v_color = in_color;\n"
|
|
||||||
" for(int i = 0; i < u_numLights; i++){\n"
|
|
||||||
" float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));\n"
|
|
||||||
" v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;\n"
|
|
||||||
" }\n"
|
|
||||||
" v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;\n"
|
|
||||||
" v_color *= u_matColor;\n"
|
|
||||||
|
|
||||||
" v_tex0 = in_tex0;\n"
|
|
||||||
|
|
||||||
" v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
|
|
||||||
"}\n"
|
|
||||||
;
|
|
@ -1,41 +1,4 @@
|
|||||||
#version 330
|
uniform mat4 u_boneMatrices[64];
|
||||||
|
|
||||||
layout(std140) uniform State
|
|
||||||
{
|
|
||||||
int u_alphaTest;
|
|
||||||
float u_alphaRef;
|
|
||||||
|
|
||||||
int u_fogEnable;
|
|
||||||
float u_fogStart;
|
|
||||||
float u_fogEnd;
|
|
||||||
vec4 u_fogColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform Scene
|
|
||||||
{
|
|
||||||
mat4 u_proj;
|
|
||||||
mat4 u_view;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAX_LIGHTS 8
|
|
||||||
struct Light {
|
|
||||||
vec4 position;
|
|
||||||
vec4 direction;
|
|
||||||
vec4 color;
|
|
||||||
float radius;
|
|
||||||
float minusCosAngle;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform Object
|
|
||||||
{
|
|
||||||
mat4 u_world;
|
|
||||||
vec4 u_ambLight;
|
|
||||||
int u_numLights;
|
|
||||||
Light u_lights[MAX_LIGHTS];
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform vec4 u_matColor;
|
|
||||||
uniform vec4 u_surfaceProps; // amb, spec, diff, extra
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 in_pos;
|
layout(location = 0) in vec3 in_pos;
|
||||||
layout(location = 1) in vec3 in_normal;
|
layout(location = 1) in vec3 in_normal;
|
||||||
@ -44,8 +7,6 @@ layout(location = 3) in vec2 in_tex0;
|
|||||||
layout(location = 11) in vec4 in_weights;
|
layout(location = 11) in vec4 in_weights;
|
||||||
layout(location = 12) in vec4 in_indices;
|
layout(location = 12) in vec4 in_indices;
|
||||||
|
|
||||||
uniform mat4 u_boneMatrices[64];
|
|
||||||
|
|
||||||
out vec4 v_color;
|
out vec4 v_color;
|
||||||
out vec2 v_tex0;
|
out vec2 v_tex0;
|
||||||
out float v_fog;
|
out float v_fog;
|
||||||
@ -53,26 +14,44 @@ out float v_fog;
|
|||||||
void
|
void
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
mat4 m = u_boneMatrices[int(in_indices[0])] * in_weights[0];
|
vec3 SkinVertex = vec3(0.0, 0.0, 0.0);
|
||||||
m += u_boneMatrices[int(in_indices[1])] * in_weights[1];
|
vec3 SkinNormal = vec3(0.0, 0.0, 0.0);
|
||||||
m += u_boneMatrices[int(in_indices[2])] * in_weights[2];
|
for(int i = 0; i < 4; i++){
|
||||||
m += u_boneMatrices[int(in_indices[3])] * in_weights[3];
|
SkinVertex += (u_boneMatrices[int(in_indices[i])] * vec4(in_pos, 1.0)).xyz * in_weights[i];
|
||||||
mat4 world = u_world * m;
|
SkinNormal += (mat3(u_boneMatrices[int(in_indices[i])]) * in_normal) * in_weights[i];
|
||||||
|
}
|
||||||
|
|
||||||
vec4 V = world * vec4(in_pos, 1.0);
|
vec4 V = u_world * vec4(SkinVertex, 1.0);
|
||||||
vec4 cV = u_view * V;
|
gl_Position = u_proj * u_view * V;
|
||||||
gl_Position = u_proj * cV;
|
vec3 N = mat3(u_world) * SkinNormal;
|
||||||
vec3 N = mat3(world) * in_normal;
|
|
||||||
|
|
||||||
v_color = in_color;
|
v_color = in_color;
|
||||||
for(int i = 0; i < u_numLights; i++){
|
v_color.rgb += u_ambLight.rgb*surfAmbient;
|
||||||
float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));
|
|
||||||
v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;
|
#ifdef DIRECTIONALS
|
||||||
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
|
if(u_directLights[i].enabled == 0.0)
|
||||||
|
break;
|
||||||
|
v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;
|
||||||
}
|
}
|
||||||
v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;
|
#endif
|
||||||
|
#ifdef POINTLIGHTS
|
||||||
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
|
if(u_pointLights[i].enabled == 0.0)
|
||||||
|
break;
|
||||||
|
v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef SPOTLIGHTS
|
||||||
|
for(int i = 0; i < MAX_LIGHTS; i++){
|
||||||
|
if(u_spotLights[i].enabled == 0.0)
|
||||||
|
break;
|
||||||
|
v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
v_color *= u_matColor;
|
v_color *= u_matColor;
|
||||||
|
|
||||||
v_tex0 = in_tex0;
|
v_tex0 = in_tex0;
|
||||||
|
|
||||||
v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
|
v_fog = DoFog(gl_Position.z);
|
||||||
}
|
}
|
||||||
|
@ -1,42 +1,5 @@
|
|||||||
const char *skin_vert_src =
|
const char *skin_vert_src =
|
||||||
"#version 330\n"
|
"uniform mat4 u_boneMatrices[64];\n"
|
||||||
|
|
||||||
"layout(std140) uniform State\n"
|
|
||||||
"{\n"
|
|
||||||
" int u_alphaTest;\n"
|
|
||||||
" float u_alphaRef;\n"
|
|
||||||
|
|
||||||
" int u_fogEnable;\n"
|
|
||||||
" float u_fogStart;\n"
|
|
||||||
" float u_fogEnd;\n"
|
|
||||||
" vec4 u_fogColor;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform Scene\n"
|
|
||||||
"{\n"
|
|
||||||
" mat4 u_proj;\n"
|
|
||||||
" mat4 u_view;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"#define MAX_LIGHTS 8\n"
|
|
||||||
"struct Light {\n"
|
|
||||||
" vec4 position;\n"
|
|
||||||
" vec4 direction;\n"
|
|
||||||
" vec4 color;\n"
|
|
||||||
" float radius;\n"
|
|
||||||
" float minusCosAngle;\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"layout(std140) uniform Object\n"
|
|
||||||
"{\n"
|
|
||||||
" mat4 u_world;\n"
|
|
||||||
" vec4 u_ambLight;\n"
|
|
||||||
" int u_numLights;\n"
|
|
||||||
" Light u_lights[MAX_LIGHTS];\n"
|
|
||||||
"};\n"
|
|
||||||
|
|
||||||
"uniform vec4 u_matColor;\n"
|
|
||||||
"uniform vec4 u_surfaceProps; // amb, spec, diff, extra\n"
|
|
||||||
|
|
||||||
"layout(location = 0) in vec3 in_pos;\n"
|
"layout(location = 0) in vec3 in_pos;\n"
|
||||||
"layout(location = 1) in vec3 in_normal;\n"
|
"layout(location = 1) in vec3 in_normal;\n"
|
||||||
@ -45,8 +8,6 @@ const char *skin_vert_src =
|
|||||||
"layout(location = 11) in vec4 in_weights;\n"
|
"layout(location = 11) in vec4 in_weights;\n"
|
||||||
"layout(location = 12) in vec4 in_indices;\n"
|
"layout(location = 12) in vec4 in_indices;\n"
|
||||||
|
|
||||||
"uniform mat4 u_boneMatrices[64];\n"
|
|
||||||
|
|
||||||
"out vec4 v_color;\n"
|
"out vec4 v_color;\n"
|
||||||
"out vec2 v_tex0;\n"
|
"out vec2 v_tex0;\n"
|
||||||
"out float v_fog;\n"
|
"out float v_fog;\n"
|
||||||
@ -54,27 +15,45 @@ const char *skin_vert_src =
|
|||||||
"void\n"
|
"void\n"
|
||||||
"main(void)\n"
|
"main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" mat4 m = u_boneMatrices[int(in_indices[0])] * in_weights[0];\n"
|
" vec3 SkinVertex = vec3(0.0, 0.0, 0.0);\n"
|
||||||
" m += u_boneMatrices[int(in_indices[1])] * in_weights[1];\n"
|
" vec3 SkinNormal = vec3(0.0, 0.0, 0.0);\n"
|
||||||
" m += u_boneMatrices[int(in_indices[2])] * in_weights[2];\n"
|
" for(int i = 0; i < 4; i++){\n"
|
||||||
" m += u_boneMatrices[int(in_indices[3])] * in_weights[3];\n"
|
" SkinVertex += (u_boneMatrices[int(in_indices[i])] * vec4(in_pos, 1.0)).xyz * in_weights[i];\n"
|
||||||
" mat4 world = u_world * m;\n"
|
" SkinNormal += (mat3(u_boneMatrices[int(in_indices[i])]) * in_normal) * in_weights[i];\n"
|
||||||
|
" }\n"
|
||||||
|
|
||||||
" vec4 V = world * vec4(in_pos, 1.0);\n"
|
" vec4 V = u_world * vec4(SkinVertex, 1.0);\n"
|
||||||
" vec4 cV = u_view * V; \n"
|
" gl_Position = u_proj * u_view * V;\n"
|
||||||
" gl_Position = u_proj * cV;\n"
|
" vec3 N = mat3(u_world) * SkinNormal;\n"
|
||||||
" vec3 N = mat3(world) * in_normal;\n"
|
|
||||||
|
|
||||||
" v_color = in_color;\n"
|
" v_color = in_color;\n"
|
||||||
" for(int i = 0; i < u_numLights; i++){\n"
|
" v_color.rgb += u_ambLight.rgb*surfAmbient;\n"
|
||||||
" float L = max(0.0, dot(N, -normalize(u_lights[i].direction.xyz)));\n"
|
|
||||||
" v_color.rgb += u_lights[i].color.rgb*L*u_surfaceProps.z;\n"
|
"#ifdef DIRECTIONALS\n"
|
||||||
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
|
" if(u_directLights[i].enabled == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
|
" v_color.rgb += DoDirLight(u_directLights[i], N)*surfDiffuse;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" v_color.rgb += u_ambLight.rgb*u_surfaceProps.x;\n"
|
"#endif\n"
|
||||||
|
"#ifdef POINTLIGHTS\n"
|
||||||
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
|
" if(u_pointLights[i].enabled == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
|
" v_color.rgb += DoPointLight(u_pointLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||||
|
" }\n"
|
||||||
|
"#endif\n"
|
||||||
|
"#ifdef SPOTLIGHTS\n"
|
||||||
|
" for(int i = 0; i < MAX_LIGHTS; i++){\n"
|
||||||
|
" if(u_spotLights[i].enabled == 0.0)\n"
|
||||||
|
" break;\n"
|
||||||
|
" v_color.rgb += DoSpotLight(u_spotLights[i], V.xyz, N)*surfDiffuse;\n"
|
||||||
|
" }\n"
|
||||||
|
"#endif\n"
|
||||||
" v_color *= u_matColor;\n"
|
" v_color *= u_matColor;\n"
|
||||||
|
|
||||||
" v_tex0 = in_tex0;\n"
|
" v_tex0 = in_tex0;\n"
|
||||||
|
|
||||||
" v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);\n"
|
" v_fog = DoFog(gl_Position.z);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
;
|
;
|
||||||
|
@ -21,7 +21,13 @@ namespace rw {
|
|||||||
|
|
||||||
int32 Image::numAllocated;
|
int32 Image::numAllocated;
|
||||||
|
|
||||||
// TODO: full 16 bit support
|
// Image formats are as follows:
|
||||||
|
// 32 bit has 4 bytes: 8888 RGBA
|
||||||
|
// 24 bit has 3 bytes: 888 RGB
|
||||||
|
// 16 bit has 2 bytes: 1555 ARGB stored in platform native order (TODO?)
|
||||||
|
// palettes always have 4 bytes: r, g, b, a
|
||||||
|
// 8 bit has 1 byte: x
|
||||||
|
// 4 bit has 1 byte per two pixels: 0xLR, where L and R are the left and right pixel resp.
|
||||||
|
|
||||||
Image*
|
Image*
|
||||||
Image::create(int32 width, int32 height, int32 depth)
|
Image::create(int32 width, int32 height, int32 depth)
|
||||||
|
Loading…
Reference in New Issue
Block a user