Browse Source

Omin light opts

Panagiotis Christopoulos Charitos 10 năm trước cách đây
mục cha
commit
d70c5245cf

+ 3 - 0
include/anki/scene/Light.h

@@ -51,6 +51,9 @@ protected:
 class PointLight: public Light
 {
 public:
+	/// The near plane on the shadow map frustums.
+	static constexpr F32 FRUSTUM_NEAR_PLANE = 0.1;
+
 	PointLight(SceneGraph* scene);
 	~PointLight();
 

+ 9 - 7
shaders/IsLp.frag.glsl

@@ -222,15 +222,17 @@ float computeShadowFactorOmni(in vec3 frag2Light, in float layer,
 	float dist = -max(dirabs.x, max(dirabs.y, dirabs.z));
 	dir = normalize(dir);
 
-	const float f = 1.0 / tan(PI / 2.0 * 0.5);
-	const float near = 0.1;
+	const float near = OMNI_LIGHT_FRUSTUM_NEAR_PLANE;
 	const float far = radius;
-	float g = near - far;
 
-	float z = (far + near) / g * dist + (2.0 * far * near) / g;
-	float w = -dist;
-	z /= w;
-	z = z * 0.5 + 0.5;
+	// Original code:
+	// float g = near - far;
+	// float z = (far + near) / g * dist + (2.0 * far * near) / g;
+	// float w = -dist;
+	// z /= w;
+	// z = z * 0.5 + 0.5;
+	// Optimized:
+	float z = (far * (dist + near)) / (dist * (far - near));
 
 	float shadowFactor = texture(u_omniMapArr, vec4(dir, layer), z).r;
 	return shadowFactor;

+ 1 - 0
src/gr/gl/GlState.cpp

@@ -130,6 +130,7 @@ void GlState::init()
 
 	// Set some GL state
 	glEnable(GL_PROGRAM_POINT_SIZE);
+	glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
 
 	// Other
 	memset(&m_vertexBindingStrides[0], 0, sizeof(m_vertexBindingStrides));

+ 4 - 2
src/renderer/Is.cpp

@@ -202,7 +202,8 @@ Error Is::initInternal(const ConfigSet& config)
 		"#define MAX_LIGHT_INDICES %u\n"
 		"#define GROUND_LIGHT %u\n"
 		"#define TILES_BLOCK_BINDING %u\n"
-		"#define POISSON %u\n",
+		"#define POISSON %u\n"
+		"#define OMNI_LIGHT_FRUSTUM_NEAR_PLANE %f\n",
 		m_r->getTilesCount().x(),
 		m_r->getTilesCount().y(),
 		(m_r->getTilesCount().x() * m_r->getTilesCount().y()),
@@ -214,7 +215,8 @@ Error Is::initInternal(const ConfigSet& config)
 		m_maxLightIds,
 		m_groundLightEnabled,
 		TILES_BLOCK_BINDING,
-		m_sm.getPoissonEnabled());
+		m_sm.getPoissonEnabled(),
+		PointLight::FRUSTUM_NEAR_PLANE);
 
 	// point light
 	ANKI_CHECK(getResourceManager().loadResourceToCache(m_lightVert,

+ 1 - 1
src/scene/Light.cpp

@@ -239,7 +239,7 @@ Error PointLight::frameUpdate(F32 prevUpdateTime, F32 crntTime)
 
 		const F32 ang = toRad(90.0);
 		const F32 dist = m_sphereW.getRadius();
-		const F32 zNear = 0.1;
+		const F32 zNear = FRUSTUM_NEAR_PLANE;
 
 		Mat3 rot;
 		const F32 PI = getPi<F32>();

+ 1 - 1
testapp/Main.cpp

@@ -262,7 +262,7 @@ Error init()
 	{
 		ScriptResourcePtr script;
 
-		ANKI_CHECK(resources.loadResource("maps/techdemo/scene.lua", script));
+		ANKI_CHECK(resources.loadResource("maps/hell/scene.lua", script));
 		if(err) return err;
 
 		err = app->getScriptManager().evalString(script->getSource());