فهرست منبع

Adding fullscreen support on X11. Optimizing IS a bit

Panagiotis Christopoulos Charitos 12 سال پیش
والد
کامیت
78167fa46f
6فایلهای تغییر یافته به همراه57 افزوده شده و 33 حذف شده
  1. 1 1
      include/anki/Config.h.cmake
  2. 2 1
      include/anki/core/NativeWindow.h
  3. 16 20
      shaders/IsLp.glsl
  4. 28 3
      src/core/NativeWindowGlxX11.cpp
  5. 2 2
      src/renderer/Is.cpp
  6. 8 6
      testapp/Main.cpp

+ 1 - 1
include/anki/Config.h.cmake

@@ -133,7 +133,7 @@ inline int stoi(const string& str)
 #define ANKI_RENDERER_MAX_SPOT_LIGHTS 8
 #define ANKI_RENDERER_MAX_SPOT_TEX_LIGHTS 8
 
-#define ANKI_RENDERER_MAX_POINT_LIGHTS_PER_TILE 24
+#define ANKI_RENDERER_MAX_POINT_LIGHTS_PER_TILE 48
 #define ANKI_RENDERER_MAX_SPOT_LIGHTS_PER_TILE 4
 #define ANKI_RENDERER_MAX_SPOT_TEX_LIGHTS_PER_TILE 4
 

+ 2 - 1
include/anki/core/NativeWindow.h

@@ -18,6 +18,7 @@ struct NativeWindowInitializer
 	U32 stencilBits = 8;
 	U32 samplesCount = 0;
 	static const Bool doubleBuffer = true;
+	Bool fullscreenDesktopRez = false;
 
 	U32 minorVersion = 0;
 	U32 majorVersion = 0;
@@ -25,7 +26,7 @@ struct NativeWindowInitializer
 
 	U32 width = 640;
 	U32 height = 768;
-	std::string title = "Untitled";
+	std::string title = "Untitled window";
 };
 
 /// Native window with GL context

+ 16 - 20
shaders/IsLp.glsl

@@ -124,27 +124,25 @@ vec3 getFragPosVSpace()
 float calcAttenuationFactor(
 	in vec3 fragPosVspace, 
 	in Light light,
-	out vec3 rayDir)
+	out vec3 frag2LightVec)
 {
 	// get the vector from the frag to the light
-	vec3 frag2LightVec = light.posRadius.xyz - fragPosVspace;
+	frag2LightVec = light.posRadius.xyz - fragPosVspace;
 
-	// Instead of using normalize(frag2LightVec) we brake the operation 
-	// because we want fragLightDist for the calc of the attenuation
-	float fragLightDistSquared = dot(frag2LightVec, frag2LightVec);
-	float fragLightDist = sqrt(fragLightDistSquared);
-	rayDir = frag2LightVec / fragLightDist;
+	float fragLightDist = length(frag2LightVec);
+	frag2LightVec = normalize(frag2LightVec);
 
-	float att = max((1.0 + ATTENUATION_BOOST) 
-		- fragLightDist / light.posRadius.w, 0.0);
+	float att = max(  
+		(fragLightDist * light.posRadius.w) + (1.0 + ATTENUATION_BOOST), 
+		0.0);
 
 	return att;
 }
 
 //==============================================================================
-float calcLambertTerm(in vec3 normal, in vec3 rayDir)
+float calcLambertTerm(in vec3 normal, in vec3 frag2LightVec)
 {
-	return max(0.0, dot(normal, rayDir));
+	return max(0.0, dot(normal, frag2LightVec));
 }
 
 //==============================================================================
@@ -152,9 +150,6 @@ float calcLambertTerm(in vec3 normal, in vec3 rayDir)
 vec3 calcPhong(in vec3 fragPosVspace, in vec3 diffuse, 
 	in vec2 specularAll, in vec3 normal, in Light light, in vec3 rayDir)
 {
-	// Diffuse
-	vec3 difCol = diffuse * light.diffuseColorShadowmapId.rgb;
-
 	// Specular
 	vec3 eyeVec = normalize(fragPosVspace);
 	vec3 h = normalize(rayDir - eyeVec);
@@ -162,14 +157,15 @@ vec3 calcPhong(in vec3 fragPosVspace, in vec3 diffuse,
 	vec3 specCol = 
 		light.specularColorTexId.rgb * (specIntensity * specularAll.r);
 	
-	// end
-	return difCol + specCol;
+	// Do a mad optimization
+	// diffCol = diffuse * light.diffuseColorShadowmapId.rgb
+	return (diffuse * light.diffuseColorShadowmapId.rgb) + specCol;
 }
 
 //==============================================================================
-float calcSpotFactor(in SpotLight light, in vec3 fragPosVspace)
+float calcSpotFactor(in SpotLight light, in vec3 frag2LightVec)
 {
-	vec3 l = normalize(fragPosVspace - light.lightBase.posRadius.xyz);
+	vec3 l = -frag2LightVec;
 
 	float costheta = dot(l, light.lightDir.xyz);
 	float spotFactor = smoothstep(
@@ -271,7 +267,7 @@ void main()
 
 		float lambert = calcLambertTerm(normal, ray);
 
-		float spot = calcSpotFactor(light, fragPosVspace);
+		float spot = calcSpotFactor(light, ray);
 
 		vec3 col = calcPhong(fragPosVspace, diffuseAndSpec.rgb, 
 			specularAll, normal, light.lightBase, ray);
@@ -298,7 +294,7 @@ void main()
 		float lambert = calcLambertTerm(normal, ray);
 
 		float spot = 
-			calcSpotFactor(light.spotLightBase, fragPosVspace);
+			calcSpotFactor(light.spotLightBase, ray);
 
 		float midFactor = att * lambert * spot;
 

+ 28 - 3
src/core/NativeWindowGlxX11.cpp

@@ -1,5 +1,6 @@
 #include "anki/core/NativeWindowGlxX11.h"
 #include "anki/util/Exception.h"
+#include <cstring>
 
 namespace anki {
 
@@ -100,7 +101,7 @@ void NativeWindowImpl::createNativeWindow(NativeWindowInitializer& init)
 	/* creating colormap */
 	swa.colormap = xColormap = XCreateColormap(xDisplay, root, 
 		vi->visual, AllocNone);
-	swa.background_pixmap = None ;
+	swa.background_pixmap = None;
 	swa.border_pixel      = 0;
 	swa.event_mask        = StructureNotifyMask;
  
@@ -111,15 +112,39 @@ void NativeWindowImpl::createNativeWindow(NativeWindowInitializer& init)
 		CWBorderPixel | CWColormap | CWEventMask, 
 		&swa);
 
-	XFree(vi);
-
 	if(!xWindow)
 	{
+		XFree(vi);
 		throw ANKI_EXCEPTION("XCreateWindow() failed");
 	}
 
 	XStoreName(xDisplay, xWindow, init.title.c_str());
 	XMapWindow(xDisplay, xWindow);
+
+	// Toggle fullscreen
+	if(init.fullscreenDesktopRez)
+	{
+		XEvent xev;
+		memset(&xev, 0, sizeof(xev));
+
+		Atom wmState = XInternAtom(xDisplay, "_NET_WM_STATE", False);
+	    Atom fullscreen = 
+			XInternAtom(xDisplay, "_NET_WM_STATE_FULLSCREEN", False);
+
+		xev.type = ClientMessage;
+		xev.xclient.window = xWindow;
+		xev.xclient.message_type = wmState;
+		xev.xclient.format = 32;
+		xev.xclient.data.l[0] = 1;
+		xev.xclient.data.l[1] = fullscreen;
+		xev.xclient.data.l[2] = 0;
+
+		XSendEvent(xDisplay, RootWindow(xDisplay, vi->screen), 0,
+			SubstructureNotifyMask | SubstructureRedirectMask, &xev);
+	}
+
+	// Cleanup
+	XFree(vi);
 }
 
 //==============================================================================

+ 2 - 2
src/renderer/Is.cpp

@@ -228,7 +228,7 @@ struct WriteLightsJob: ThreadJob
 		Vec3 pos = light.getWorldTransform().getOrigin().getTransformed(
 			cam->getViewMatrix());
 
-		slight.posRadius = Vec4(pos, light.getRadius());
+		slight.posRadius = Vec4(pos, -1.0 / light.getRadius());
 		slight.diffuseColorShadowmapId = light.getDiffuseColor();
 		slight.specularColorTexId = light.getSpecularColor();
 
@@ -290,7 +290,7 @@ struct WriteLightsJob: ThreadJob
 		// Pos & dist
 		Vec3 pos = light.getWorldTransform().getOrigin().getTransformed(
 				cam->getViewMatrix());
-		baseslight->posRadius = Vec4(pos, light.getDistance());
+		baseslight->posRadius = Vec4(pos, -1.0 / light.getDistance());
 
 		// Diff color and shadowmap ID now
 		baseslight->diffuseColorShadowmapId = 

+ 8 - 6
testapp/Main.cpp

@@ -488,8 +488,9 @@ void mainLoop()
 	MainRendererSingleton::get().takeScreenshot("screenshot.tga");
 #endif
 
-	ANKI_LOGI("Exiting main loop (" << mainLoopTimer.getElapsedTime()
-		<< " sec)");
+	HighRezTimer::Scalar timePassed = mainLoopTimer.getElapsedTime();
+	ANKI_LOGI("Exiting main loop (" << timePassed
+		<< " sec) FPS: " << 1000.0 / timePassed);
 	MainRendererSingleton::get().printProfileInfo();
 	SceneGraphSingleton::get().printProfileInfo();
 }
@@ -512,12 +513,13 @@ void initSubsystems(int argc, char* argv[])
 
 	// Window
 	NativeWindowInitializer nwinit;
-	nwinit.width = 1280;
-	nwinit.height = 800;
+	nwinit.width = 1920;
+	nwinit.height = 1080;
 	nwinit.majorVersion = glmajor;
 	nwinit.minorVersion = glminor;
 	nwinit.depthBits = 0;
 	nwinit.stencilBits = 0;
+	nwinit.fullscreenDesktopRez = true;
 	win = new NativeWindow;	
 	win->create(nwinit);
 
@@ -544,8 +546,8 @@ void initSubsystems(int argc, char* argv[])
 	initializer.pps.hdr.exposure = 8.0;
 	initializer.pps.ssao.blurringIterationsNum = 4;
 	initializer.pps.ssao.enabled = true;
-	initializer.pps.ssao.mainPassRenderingQuality = 0.3;
-	initializer.pps.ssao.blurringRenderingQuality = 0.5;
+	initializer.pps.ssao.mainPassRenderingQuality = 0.5;
+	initializer.pps.ssao.blurringRenderingQuality = 0.7;
 	initializer.pps.enabled = true;
 	initializer.pps.bl.enabled = true;
 	initializer.pps.bl.blurringIterationsNum = 2;