Преглед изворни кода

Adding the assets for the simple scene. It's too basic at the moment but I'll improve it

Panagiotis Christopoulos Charitos пре 9 година
родитељ
комит
4b1d5fd270

+ 9 - 5
include/anki/gr/Common.h

@@ -70,17 +70,21 @@ using GrAllocator = HeapAllocator<T>;
 /// Clear values for textures or attachments.
 class ClearValue
 {
+private:
+	class Ds
+	{
+	public:
+		F32 m_depth;
+		I32 m_stencil;
+	};
+
 public:
 	union
 	{
 		Array<F32, 4> m_colorf = {{0.0, 0.0, 0.0, 0.0}};
 		Array<I32, 4> m_colori;
 		Array<U32, 4> m_coloru;
-		struct
-		{
-			F32 m_depth;
-			I32 m_stencil;
-		} m_depthStencil;
+		Ds m_depthStencil;
 	};
 };
 

BIN
samples/assets/column.ankimesh


+ 9 - 0
samples/assets/columnroom-material.ankimdl

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<model>
+	<modelPatches>
+		<modelPatch>
+			<mesh>samples/assets/column.ankimesh</mesh>
+			<material>samples/assets/room-material.ankimtl</material>
+		</modelPatch>
+	</modelPatches>
+</model>

+ 89 - 0
samples/assets/room-material.ankimtl

@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<material>
+	<programs>
+		<program>
+			<type>vert</type>
+			<includes>
+				<include>shaders/MsCommonVert.glsl</include>
+			</includes>
+
+			<inputs>
+				<input><type>mat4</type><name>anki_mvp</name></input>
+				<input><type>mat3</type><name>anki_n</name><inShadow>0</inShadow></input>
+				 
+			</inputs>
+
+			<operations>
+				<operation>
+					<id>0</id>
+					<returnType>void</returnType>
+					<function>writePositionAndUv</function>
+					<arguments><argument>anki_mvp</argument></arguments>
+				</operation>
+				<operation>
+					<id>1</id>
+					<returnType>void</returnType>
+					<function>writeNormalAndTangent</function>
+					<arguments><argument>anki_n</argument></arguments>
+				</operation>
+				 
+			</operations>
+		</program>
+		<program>
+			<type>frag</type>
+
+			<includes>
+				<include>shaders/MsCommonFrag.glsl</include>
+			</includes>
+
+			<inputs>
+				<input><type>vec3</type><name>uSpecularColor</name><value>0.500000 0.500000 0.500000</value></input>
+				<input><type>float</type><name>uSpecularPower</name><value>0.097847</value></input>
+				<input><type>vec3</type><name>uDiffuseColor</name><value>0.799988 0.635542 0.640324</value></input>
+				 
+				<input><type>float</type><name>subsurface</name><const>1</const><value>0.0</value></input>
+				<input><type>float</type><name>emission</name><value>0.000000</value><const>1</const></input>
+				<input><type>float</type><name>metallic</name><value>0.000000</value><const>1</const></input>
+				 
+			</inputs>
+
+			<operations>
+				<operation>
+					<id>0</id>
+					<returnType>vec3</returnType>
+					<function>getNormal</function>
+				</operation>
+				<operation>
+					<id>1</id>
+					<returnType>vec4</returnType>
+					<function>getTangent</function>
+				</operation>
+				<operation>
+					<id>2</id>
+					<returnType>vec2</returnType>
+					<function>getTextureCoord</function>
+				</operation>
+				 
+				
+				 
+				
+				
+				
+				
+				<operation>
+					<id>100</id>
+					<returnType>void</returnType>
+					<function>writeRts</function>
+					<arguments>
+						<argument>uDiffuseColor</argument>
+						<argument>out0</argument>
+						<argument>uSpecularColor</argument>
+						<argument>uSpecularPower</argument>
+						<argument>subsurface</argument>
+						<argument>emission</argument>
+						<argument>metallic</argument>
+					</arguments>
+				</operation>
+			</operations>
+		</program>
+	</programs>	</material>

BIN
samples/assets/room.ankimesh


+ 9 - 0
samples/assets/roomroom-material.ankimdl

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<model>
+	<modelPatches>
+		<modelPatch>
+			<mesh>samples/assets/room.ankimesh</mesh>
+			<material>samples/assets/room-material.ankimtl</material>
+		</modelPatch>
+	</modelPatches>
+</model>

+ 58 - 0
samples/assets/scene.lua

@@ -0,0 +1,58 @@
+local scene = getSceneGraph()
+local events = getEventManager()
+local rot
+local node
+local inst
+local lcomp
+
+node = scene:newSector("sector0", "samples/assets/sector.ankimesh")
+trf = Transform.new()
+trf:setOrigin(Vec4.new(0, 0, 0, 0))
+rot = Mat3x4.new()
+rot:setAll(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0)
+trf:setRotation(rot)
+trf:setScale(1.16458)
+node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)
+
+node = scene:newModelNode("roomroom-materialnone0", "samples/assets/roomroom-material.ankimdl")
+trf = Transform.new()
+trf:setOrigin(Vec4.new(0, 0, 0, 0))
+rot = Mat3x4.new()
+rot:setAll(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0)
+trf:setRotation(rot)
+trf:setScale(1)
+node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)
+
+node = scene:newModelNode("columnroom-materialnone1", "samples/assets/columnroom-material.ankimdl")
+trf = Transform.new()
+trf:setOrigin(Vec4.new(5.35225, 5.06618, 5.43441, 0))
+rot = Mat3x4.new()
+rot:setAll(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0)
+trf:setRotation(rot)
+trf:setScale(1)
+node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)
+
+node = scene:newPointLight("Point")
+lcomp = node:getSceneNodeBase():getLightComponent()
+lcomp:setDiffuseColor(Vec4.new(2, 2, 2, 1))
+lcomp:setSpecularColor(Vec4.new(2, 2, 2, 1))
+lcomp:setRadius(12.77)
+trf = Transform.new()
+trf:setOrigin(Vec4.new(0.0680842, -0.0302386, 9.57987, 0))
+rot = Mat3x4.new()
+rot:setAll(1, 0, 0, 0, 0, 4.63287e-05, 1, 0, 0, -1, 4.63287e-05, 0)
+trf:setRotation(rot)
+trf:setScale(1)
+node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)
+lcomp:setShadowEnabled(1)
+
+node = scene:newPerspectiveCamera("Camera")
+scene:setActiveCamera(node:getSceneNodeBase())
+node:setAll(1.5708, 1.0 / getMainRenderer():getAspectRatio() * 1.5708, 0.1, 100)
+trf = Transform.new()
+trf:setOrigin(Vec4.new(5.65394, -5.98675, 3.80237, 0))
+rot = Mat3x4.new()
+rot:setAll(1, 0, 0, 0, 0, 1, -4.63724e-05, 0, 0, 4.63724e-05, 1, 0)
+trf:setRotation(rot)
+trf:setScale(1)
+node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)

BIN
samples/assets/sector.ankimesh


BIN
samples/assets/simple_scene.blend


+ 126 - 5
samples/simple_scene/Main.cpp

@@ -6,8 +6,6 @@ using namespace anki;
 class MyApp : public App
 {
 public:
-	PerspectiveCamera* m_cam = nullptr;
-
 	Error init();
 	Error userMainLoop(Bool& quit) override;
 };
@@ -17,7 +15,25 @@ MyApp* app;
 //==============================================================================
 Error MyApp::init()
 {
-	// TODO
+	// Init the super class
+	Config config;
+	config.set("fullscreenDesktopResolution", true);
+	ANKI_CHECK(App::init(config, allocAligned, nullptr));
+
+	// Load the scene.lua
+	ScriptResourcePtr script;
+	ANKI_CHECK(
+		getResourceManager().loadResource("samples/assets/scene.lua", script));
+	ANKI_CHECK(getScriptManager().evalString(script->getSource()));
+
+	// Input
+	getInput().lockCursor(true);
+	getInput().hideCursor(true);
+	getInput().moveCursor(Vec2(0.0));
+
+	// Some renderer stuff
+	getMainRenderer().getOffscreenRenderer().getVolumetric().setFog(
+		Vec3(1.0, 0.9, 0.9), 0.7);
 
 	return ErrorCode::NONE;
 }
@@ -25,7 +41,93 @@ Error MyApp::init()
 //==============================================================================
 Error MyApp::userMainLoop(Bool& quit)
 {
-	// TODO
+	const F32 MOVE_DISTANCE = 0.1;
+	const F32 ROTATE_ANGLE = toRad(2.5);
+	const F32 MOUSE_SENSITIVITY = 9.0;
+	quit = false;
+
+	SceneGraph& scene = getSceneGraph();
+	Input& in = getInput();
+
+	if(in.getKey(KeyCode::ESCAPE))
+	{
+		quit = true;
+		return ErrorCode::NONE;
+	}
+
+	// move the camera
+	static MoveComponent* mover =
+		&scene.getActiveCamera().getComponent<MoveComponent>();
+
+	if(in.getKey(KeyCode::UP))
+	{
+		mover->rotateLocalX(ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::DOWN))
+	{
+		mover->rotateLocalX(-ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::LEFT))
+	{
+		mover->rotateLocalY(ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::RIGHT))
+	{
+		mover->rotateLocalY(-ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::A))
+	{
+		mover->moveLocalX(-MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::D))
+	{
+		mover->moveLocalX(MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::Z))
+	{
+		mover->moveLocalY(MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::SPACE))
+	{
+		mover->moveLocalY(-MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::W))
+	{
+		mover->moveLocalZ(-MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::S))
+	{
+		mover->moveLocalZ(MOVE_DISTANCE);
+	}
+
+	if(in.getKey(KeyCode::Q))
+	{
+		mover->rotateLocalZ(ROTATE_ANGLE);
+	}
+
+	if(in.getKey(KeyCode::E))
+	{
+		mover->rotateLocalZ(-ROTATE_ANGLE);
+	}
+
+	if(in.getMousePosition() != Vec2(0.0))
+	{
+		F32 angY = -ROTATE_ANGLE * in.getMousePosition().x() * MOUSE_SENSITIVITY
+			* getMainRenderer().getAspectRatio();
+
+		mover->rotateLocalY(angY);
+		mover->rotateLocalX(
+			ROTATE_ANGLE * in.getMousePosition().y() * MOUSE_SENSITIVITY);
+	}
 
 	return ErrorCode::NONE;
 }
@@ -33,7 +135,26 @@ Error MyApp::userMainLoop(Bool& quit)
 //==============================================================================
 int main(int argc, char* argv[])
 {
-	// TODO
+	Error err = ErrorCode::NONE;
+
+	app = new MyApp;
+	err = app->init();
+	if(!err)
+	{
+		err = app->mainLoop();
+	}
+
+	if(err)
+	{
+		ANKI_LOGE("Error reported. To run %s you have to navigate to the "
+				  "/path/to/anki/samples. And then execute it",
+			argv[0]);
+	}
+	else
+	{
+		delete app;
+		ANKI_LOGI("Bye!!");
+	}
 
 	return 0;
 }

+ 2 - 2
src/core/Config.cpp

@@ -58,8 +58,8 @@ Config::Config()
 	newOption("tm.enabled", true);
 
 	// Globals
-	newOption("width", 0);
-	newOption("height", 0);
+	newOption("width", 1280);
+	newOption("height", 768);
 	newOption("renderingQuality", 1.0); // Applies only to MainRenderer
 	newOption("lodDistance", 10.0); // Distance that used to calculate the LOD
 	newOption("samples", 1);

+ 7 - 3
src/gr/gl/ResourceGroupImpl.cpp

@@ -102,8 +102,11 @@ void ResourceGroupImpl::init(const ResourceGroupInitInfo& init)
 	// Init shader buffers
 	initBuffers(
 		init.m_uniformBuffers, m_ubos, m_ubosCount, resourcesCount, transCount);
-	initBuffers(
-		init.m_storageBuffers, m_ssbos, m_ssbosCount, resourcesCount, transCount);
+	initBuffers(init.m_storageBuffers,
+		m_ssbos,
+		m_ssbosCount,
+		resourcesCount,
+		transCount);
 	initBuffers(init.m_atomicBuffers,
 		m_atomics,
 		m_atomicsCount,
@@ -156,7 +159,8 @@ void ResourceGroupImpl::init(const ResourceGroupInitInfo& init)
 		++resourcesCount;
 	}
 
-	ANKI_ASSERT((resourcesCount > 0 || transCount > 0) && "Resource group empty");
+	ANKI_ASSERT(
+		(resourcesCount > 0 || transCount > 0) && "Resource group empty");
 
 	// Hold references
 	initResourceReferences(init, resourcesCount);