mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-17 02:24:07 +02:00
#15 some RPI shader optimizations
This commit is contained in:
@@ -228,7 +228,7 @@
|
|||||||
PFNGLPROGRAMBINARYPROC glProgramBinary;
|
PFNGLPROGRAMBINARYPROC glProgramBinary;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_GAPI_GLES)
|
#if defined(_GAPI_GLES) && !defined(_OS_RPI)
|
||||||
PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT;
|
PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -369,6 +369,11 @@ namespace GAPI {
|
|||||||
}
|
}
|
||||||
sprintf(defines, "%s#define PASS_%s\n", defines, passNames[pass]);
|
sprintf(defines, "%s#define PASS_%s\n", defines, passNames[pass]);
|
||||||
|
|
||||||
|
#ifdef _OS_RPI
|
||||||
|
strcat(defines, "#define OPT_VLIGHTPROJ\n");
|
||||||
|
strcat(defines, "#define OPT_SHADOW_ONETAP\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
char fileName[255];
|
char fileName[255];
|
||||||
// generate shader file path
|
// generate shader file path
|
||||||
if (Core::support.shaderBinary) {
|
if (Core::support.shaderBinary) {
|
||||||
@@ -648,7 +653,7 @@ namespace GAPI {
|
|||||||
bool dynamic;
|
bool dynamic;
|
||||||
|
|
||||||
Mesh(bool dynamic) : iBuffer(NULL), vBuffer(NULL), VAO(NULL), dynamic(dynamic) {
|
Mesh(bool dynamic) : iBuffer(NULL), vBuffer(NULL), VAO(NULL), dynamic(dynamic) {
|
||||||
ID[0] = ID[1] = NULL;
|
ID[0] = ID[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(Index *indices, int iCount, ::Vertex *vertices, int vCount, int aCount) {
|
void init(Index *indices, int iCount, ::Vertex *vertices, int vCount, int aCount) {
|
||||||
@@ -796,7 +801,7 @@ namespace GAPI {
|
|||||||
void *libGL = dlopen("libGLESv2.so", RTLD_LAZY);
|
void *libGL = dlopen("libGLESv2.so", RTLD_LAZY);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_OS_WIN) || (defined(_OS_LINUX) && !defined(_OS_RPI)) || defined(_OS_ANDROID)
|
#if defined(_OS_WIN) || defined(_OS_LINUX) || defined(_OS_ANDROID)
|
||||||
#ifdef _OS_WIN
|
#ifdef _OS_WIN
|
||||||
GetProcOGL(glActiveTexture);
|
GetProcOGL(glActiveTexture);
|
||||||
#endif
|
#endif
|
||||||
@@ -929,8 +934,8 @@ namespace GAPI {
|
|||||||
support.texHalf = support.texHalfLinear || extSupport(ext, "_texture_half_float");
|
support.texHalf = support.texHalfLinear || extSupport(ext, "_texture_half_float");
|
||||||
|
|
||||||
#ifdef PROFILE
|
#ifdef PROFILE
|
||||||
support.profMarker = extSupport(ext, "_KHR_debug");
|
support.profMarker = extSupport(ext, "_KHR_debug");
|
||||||
support.profTiming = extSupport(ext, "_timer_query");
|
support.profTiming = extSupport(ext, "_timer_query");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (support.maxAniso)
|
if (support.maxAniso)
|
||||||
@@ -1198,4 +1203,4 @@ namespace GAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -523,10 +523,11 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inputFree();
|
||||||
|
|
||||||
sndFree();
|
sndFree();
|
||||||
Game::deinit();
|
Game::deinit();
|
||||||
|
|
||||||
inputFree();
|
|
||||||
eglFree(display, surface, context);
|
eglFree(display, surface, context);
|
||||||
wndFree(dmDisplay, dmWindow);
|
wndFree(dmDisplay, dmWindow);
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
#define WATER_FOG_DIST (1.0 / (6.0 * 1024.0))
|
#define WATER_FOG_DIST (1.0 / (6.0 * 1024.0))
|
||||||
#define UNDERWATER_COLOR float3(0.6, 0.9, 0.9)
|
#define UNDERWATER_COLOR float3(0.6, 0.9, 0.9)
|
||||||
#define SHADOW_NORMAL_BIAS 16.0
|
#define SHADOW_NORMAL_BIAS 16.0
|
||||||
#define SHADOW_CONST_BIAS 0.04
|
#define SHADOW_CONST_BIAS 0.05
|
||||||
#define PI 3.141592653589793
|
#define PI 3.141592653589793
|
||||||
|
|
||||||
static const float3 SHADOW_TEXEL = float3(1.0 / 1024.0, 1.0 / 1024.0, 0.0);
|
static const float3 SHADOW_TEXEL = float3(1.0 / 1024.0, 1.0 / 1024.0, 0.0);
|
||||||
@@ -73,4 +73,4 @@ float4 pack(float value) {
|
|||||||
|
|
||||||
float unpack(float4 value) {
|
float unpack(float4 value) {
|
||||||
return dot(value, float4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0));
|
return dot(value, float4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0));
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ R"====(
|
|||||||
#define UNDERWATER_COLOR vec3(0.6, 0.9, 0.9)
|
#define UNDERWATER_COLOR vec3(0.6, 0.9, 0.9)
|
||||||
|
|
||||||
#define SHADOW_NORMAL_BIAS 16.0
|
#define SHADOW_NORMAL_BIAS 16.0
|
||||||
#define SHADOW_CONST_BIAS 0.04
|
#define SHADOW_CONST_BIAS 0.05
|
||||||
|
|
||||||
#if (defined(PASS_AMBIENT) || defined(PASS_COMPOSE)) && !defined(TYPE_FLASH)
|
#if (defined(PASS_AMBIENT) || defined(PASS_COMPOSE)) && !defined(TYPE_FLASH)
|
||||||
varying vec3 vCoord;
|
varying vec3 vCoord;
|
||||||
@@ -25,6 +25,10 @@ varying vec4 vTexCoord; // xy - atlas coords, zw - trapezoidal correction
|
|||||||
#ifdef OPT_SHADOW
|
#ifdef OPT_SHADOW
|
||||||
#define SHADOW_TEXEL vec3(1.0 / 1024.0, 1.0 / 1024.0, 0.0)
|
#define SHADOW_TEXEL vec3(1.0 / 1024.0, 1.0 / 1024.0, 0.0)
|
||||||
uniform mat4 uLightProj;
|
uniform mat4 uLightProj;
|
||||||
|
|
||||||
|
#ifdef OPT_VLIGHTPROJ
|
||||||
|
varying vec4 vLightProj;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uniform mat4 uViewProj;
|
uniform mat4 uViewProj;
|
||||||
@@ -37,7 +41,7 @@ uniform vec4 uMaterial; // x - diffuse, y - ambient, z - specular, w - alpha
|
|||||||
uniform vec4 uFogParams;
|
uniform vec4 uFogParams;
|
||||||
|
|
||||||
#ifndef PASS_SHADOW
|
#ifndef PASS_SHADOW
|
||||||
varying vec4 vViewVec; // xyz - dir * dist, w - coord.y * clipPlaneSign
|
varying vec4 vViewVec; // xyz - dir * dist, w - coord.y * clipPlaneSign
|
||||||
varying vec4 vDiffuse;
|
varying vec4 vDiffuse;
|
||||||
varying vec4 vNormal; // xyz - normal dir, w - fog factor
|
varying vec4 vNormal; // xyz - normal dir, w - fog factor
|
||||||
|
|
||||||
@@ -53,6 +57,14 @@ uniform vec4 uFogParams;
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef OPT_SHADOW
|
||||||
|
vec4 calcLightProj(vec3 coord, vec3 lightVec, vec3 normal) {
|
||||||
|
float factor = clamp(1.0 - dot(normalize(lightVec), normal), 0.0, 1.0);
|
||||||
|
factor *= SHADOW_NORMAL_BIAS;
|
||||||
|
return uLightProj * vec4(coord + normal * factor, 1.0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef VERTEX
|
#ifdef VERTEX
|
||||||
|
|
||||||
#if defined(TYPE_ENTITY) || defined(TYPE_MIRROR)
|
#if defined(TYPE_ENTITY) || defined(TYPE_MIRROR)
|
||||||
@@ -208,6 +220,11 @@ uniform vec4 uFogParams;
|
|||||||
vAmbient = ambient;
|
vAmbient = ambient;
|
||||||
vLight = light;
|
vLight = light;
|
||||||
vLightMap = aLight * light.x;
|
vLightMap = aLight * light.x;
|
||||||
|
|
||||||
|
#ifdef OPT_VLIGHTPROJ
|
||||||
|
vLightProj = calcLightProj(coord, lv0, vNormal.xyz);
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
vLight.xyz = uLightColor[1].xyz * light.y + uLightColor[2].xyz * light.z + uLightColor[3].xyz * light.w;
|
vLight.xyz = uLightColor[1].xyz * light.y + uLightColor[2].xyz * light.z + uLightColor[3].xyz * light.w;
|
||||||
vLight.w = 0.0;
|
vLight.w = 0.0;
|
||||||
@@ -296,16 +313,20 @@ uniform vec4 uFogParams;
|
|||||||
#ifdef SHADOW_SAMPLER
|
#ifdef SHADOW_SAMPLER
|
||||||
float rShadow = SHADOW(p);
|
float rShadow = SHADOW(p);
|
||||||
#else
|
#else
|
||||||
vec4 samples = vec4(SHADOW( p.xy),
|
#ifndef OPT_SHADOW_ONETAP
|
||||||
SHADOW(SHADOW_TEXEL.xz + p.xy),
|
vec4 samples = vec4(SHADOW( p.xy),
|
||||||
SHADOW(SHADOW_TEXEL.zy + p.xy),
|
SHADOW(SHADOW_TEXEL.xz + p.xy),
|
||||||
SHADOW(SHADOW_TEXEL.xy + p.xy));
|
SHADOW(SHADOW_TEXEL.zy + p.xy),
|
||||||
|
SHADOW(SHADOW_TEXEL.xy + p.xy));
|
||||||
|
|
||||||
samples = step(vec4(p.z), samples);
|
samples = step(vec4(p.z), samples);
|
||||||
|
|
||||||
vec2 f = fract(p.xy / SHADOW_TEXEL.xy);
|
vec2 f = fract(p.xy / SHADOW_TEXEL.xy);
|
||||||
samples.xy = mix(samples.xz, samples.yw, f.x);
|
samples.xy = mix(samples.xz, samples.yw, f.x);
|
||||||
float rShadow = mix(samples.x, samples.y, f.y);
|
float rShadow = mix(samples.x, samples.y, f.y);
|
||||||
|
#else
|
||||||
|
float rShadow = step(p.z, SHADOW(p.xy));
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float fade = clamp(dot(lightVec, lightVec), 0.0, 1.0);
|
float fade = clamp(dot(lightVec, lightVec), 0.0, 1.0);
|
||||||
@@ -313,9 +334,10 @@ uniform vec4 uFogParams;
|
|||||||
}
|
}
|
||||||
|
|
||||||
float getShadow(vec3 lightVec, vec3 normal) {
|
float getShadow(vec3 lightVec, vec3 normal) {
|
||||||
float factor = clamp(1.0 - dot(normalize(lightVec), normal), 0.0, 1.0);
|
#ifndef OPT_VLIGHTPROJ
|
||||||
factor *= SHADOW_NORMAL_BIAS;
|
vec4 vLightProj = calcLightProj(vCoord, lightVec, normal);
|
||||||
return getShadow(lightVec, normal, uLightProj * vec4(vCoord + normal * factor, 1.0));
|
#endif
|
||||||
|
return getShadow(lightVec, normal, vLightProj);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -414,7 +436,7 @@ uniform vec4 uFogParams;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TYPE_ROOM
|
#ifdef TYPE_ROOM
|
||||||
light += mix(vAmbient.xyz, vLightMap.xyz, rShadow);
|
light += mix(vAmbient, vLightMap.xyz, rShadow);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TYPE_SPRITE
|
#ifdef TYPE_SPRITE
|
||||||
@@ -451,4 +473,4 @@ uniform vec4 uFogParams;
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
)===="
|
)===="
|
||||||
|
Reference in New Issue
Block a user