Jump to content

  • Log In with Google      Sign In   
  • Create Account

mrheisenberg

Member Since 13 Aug 2012
Offline Last Active Jan 13 2014 09:20 AM

#5119249 Can't properly produce a ViewProjection matrix

Posted by mrheisenberg on 25 December 2013 - 08:51 PM

I have a camera class that uses the DirectXMath API:

__declspec(align(16)) class Camera
{
public:
XMVECTOR Translation;
XMMATRIX Rotation;
XMVECTOR Scale;
XMMATRIX Transform;


XMFLOAT3 RotAngles;


XMMATRIX ProjectionMatrix;


float Width;
float Height;


float NearZ;
float FarZ;
float AspectRatio;
float FieldOfView;


Camera()
{
Translation = XMVectorZero();
Rotation = XMMatrixIdentity();
Scale = XMVectorSplatOne();


Transform = XMMatrixIdentity();


Width = 800;
Height = 600;


NearZ = 0.1f;
FarZ = 100.0f;
AspectRatio = 800 / 600;
FieldOfView = (XM_PIDIV4);


ProjectionMatrix = XMMatrixPerspectiveFovLH(FieldOfView, AspectRatio, NearZ, FarZ);
}


void Update()
{
Rotation = XMMatrixRotationRollPitchYaw(RotAngles.x, RotAngles.y, RotAngles.z);
XMMATRIX scaleM = XMMatrixScalingFromVector(Scale);
XMMATRIX translationM = XMMatrixTranslationFromVector(Translation);


Transform = scaleM * Rotation * translationM;
}


XMMATRIX GetViewMatrix()
{
XMVECTOR Eye;
XMVECTOR At;
XMVECTOR Up;


Eye = Translation;
At = Translation + Transform.r[2];
Up = Transform.r[1];


return(XMMatrixLookAtLH(Eye, At, Up));
}


XMMATRIX GetViewProjectionMatrix()
{
return(XMMatrixTranspose(GetViewMatrix() * ProjectionMatrix));
}
};

When I store the result of GetViewProjectionMatrix() in a XMFLOAT4X4 and update it to the constant buffer, the geometry gets torn apart or doesn't show up at all when I move/rotate the camera with the keyboard.I have isolated the camera to be issue with the deforming/disappearing geometry, but I have no idea what the problem is.I mean the projection matrix can't be wrong, it's just 1 function call, so it's most likely the view matrix.Could someone tell me where the issue is?I tried different combinations of multiplication orders/transposing both/transposing only one/anything.It never works properly.

 




#5047603 Strange DirectX error(debugger is unreliable in this case)

Posted by mrheisenberg on 28 March 2013 - 05:37 AM

ok I expanded it and same thing happens, it crashes on Release(), but when I remove the line afterwards that sets it to 0/NULL the other error appears.There's

<Unknown function>

Unknown
at the top of the call stack, so I guess there's something wrong in the COM?I don't think I initialized it wrong tho, just used 
EnumOutputs, I check the HRESULT and it's ok

edit: I tried to use IDXGIOutput1 too instead of IDXGIOutput, but I EnumOutputs() doesn't take IDXGIOutput1 as an argument, it wants an IDXGIOutput, or is IDXGIOutput1 a special case and used in a different way?

I check breakpoint by breakpoint the pointer addresses, all of the IDXGI objects seem to be getting created with valid addresses(they're not 
0x00000000 or anything similar)

Ok I fixed it, DXGIOutput outputInterface = DXGIOutput(output); should have been DXGIOutput* outputInterface = new DXGIOutput(output); otherwise it gets destroyed in the end of the frame and then I do adapterOutputs.Add(&outputInterface); I was adding a pointer to an already destroyed object (facepalm).




#5047461 Strange DirectX error(debugger is unreliable in this case)

Posted by mrheisenberg on 27 March 2013 - 08:26 PM

Yes, I use the updated ones everywhere, however I don't understand this:
 

/ Create a factory to enumerate all of the hardware in the system.

    IDXGIFactory1* pFactory = 0;
    hr = CreateDXGIFactory1( __uuidof(IDXGIFactory), (void**)(&pFactory) );

Shouldn't it be IDXGIFactory1? I'm using IDXGIFactory1, maybe that's the issue?
It also worries me that the SafeRelease macro causes a crash, even if I use 0 instead of nullptr, could be a hint at the problem.

 


on a side note - I just now notice GameDev has colors for DirectX in the code tags lol




#5024155 xnacollision structure general transform function versions

Posted by mrheisenberg on 21 January 2013 - 09:00 PM

What you need is in DirectXCollision.h and DirectXCollision.inl,but there are a few functions that have changed from xnamath to DirectXMath(if I remember correctly,some xnamath functions that weren't templated are now templated in DirectXMath) Attached File  Desktop.rar   95.97KB   34 downloads
Also you can still DL the Windows 8 kit on Win7:
http://msdn.microsoft.com/en-us/windows/hardware/hh852363.aspx




#5021715 How are shader mods made?

Posted by mrheisenberg on 15 January 2013 - 01:53 AM

How do the modders,who introduce new shader effects,know what input layout they must be expecting in the vertex shader and what constant buffers are being set,etc..are they reverse engineering the shader files?
For example:Freelancer

The game originally used a forward renderer and it didn't have bloom,how did they alter the renderer if they don't have access to the source?




#5021241 Understanding XMVECTOR parameter passing to own functions

Posted by mrheisenberg on 13 January 2013 - 06:50 PM

Maybe I'm doing it wrong?

Profiler.hpp

#pragma once

#ifndef _PROFILER_HPP_
#define _PROFILER_HPP_

#pragma comment (lib,"Winmm.lib")

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>

class Profiler
{
public:
	static Profiler* Instance();
	static void Destroy();

	void operator()();
	UINT64 GetDTime()
	{
		return(DTime);
	}

private:
	Profiler();
	~Profiler();

	static Profiler *instance;
	UINT64 lastGameTime;
	UINT64 DTime;
};

#endif 

Benchmarks.hpp

#pragma once

#ifndef _TEST_FUNCTIONS_HPP_
#define _TEST_FUNCTIONS_HPP_

#include <Windows.h>
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <vector>
#include <fstream>
#include <ostream>
#include <istream>
#include <DirectXMath.h>
using namespace DirectX;

namespace Benchmark
{
	XMFLOAT4X4 UnoptA(XMFLOAT4X4 inputMat, XMFLOAT4 inputVec);
	XMFLOAT4X4 UnoptB(XMFLOAT4X4 inputMat);

	XMMATRIX OptA(CXMMATRIX inputMat, FXMVECTOR inputVec);
	XMMATRIX OptB(CXMMATRIX inputMat);

	void BenchUnopt(XMFLOAT4X4 inputMat, XMFLOAT4 inputVec, UINT count, std::vector<XMFLOAT4X4> &buffer);
	void BenchOpt(XMFLOAT4X4 inputMat, XMFLOAT4 inputVec, UINT count, std::vector<XMFLOAT4X4> &buffer);
}

#endif

Profiler.cpp

#include "Profiler.hpp"

Profiler *Profiler::instance = nullptr;

Profiler *Profiler::Instance()
{
	if(instance)
	{
		return(instance);
	}
	return(instance = new Profiler);
}

void Profiler::Destroy()
{
	if(instance)
	{
		delete instance;
	}
}

Profiler::Profiler(): DTime(0)
{
	lastGameTime = (UINT64)timeGetTime();
}

Profiler::~Profiler()
{

}

void Profiler::operator()()
{
	UINT64 ticks = (UINT64)timeGetTime();

	DTime = ticks - lastGameTime;

	lastGameTime = ticks;
}

BenchmarksOpt.cpp

#include "Benchmarks.hpp"

namespace Benchmark
{
	XMMATRIX OptA(CXMMATRIX inputMat, FXMVECTOR inputVec)
	{
		return(OptB(XMMatrixMultiply(inputMat, XMMatrixRotationQuaternion(inputVec))));
	}

	XMMATRIX OptB(CXMMATRIX inputMat)
	{
		XMVECTOR determinant;
		return(XMMatrixInverse(&determinant, inputMat));
	}

	void BenchOpt(XMFLOAT4X4 inputMat, XMFLOAT4 inputVec, UINT count, std::vector<XMFLOAT4X4> &buffer)
	{
		XMMATRIX matrixInput = XMLoadFloat4x4(&inputMat);
		XMVECTOR vectorInput = XMLoadFloat4(&inputVec);

		for(UINT i = 0; i < count; i++)
		{
			XMFLOAT4X4 bufferMat;
			XMStoreFloat4x4(&bufferMat, OptA(matrixInput, vectorInput));
			buffer.push_back(bufferMat);
		}
	}
}

BenchmarksUnopt.cpp

#include "Benchmarks.hpp"

namespace Benchmark
{
	XMFLOAT4X4 UnoptA(XMFLOAT4X4 inputMat, XMFLOAT4 inputVec)
	{
		XMMATRIX matrixInput = XMLoadFloat4x4(&inputMat);
		XMVECTOR vectorInput = XMLoadFloat4(&inputVec);
		
		matrixInput = XMMatrixMultiply(matrixInput, XMMatrixRotationQuaternion(vectorInput));

		XMFLOAT4X4 outputMat;
		XMStoreFloat4x4(&outputMat, matrixInput);

		return(UnoptB(outputMat));
	}

	XMFLOAT4X4 UnoptB(XMFLOAT4X4 inputMat)
	{
		XMMATRIX matrixInput = XMLoadFloat4x4(&inputMat);
		XMVECTOR determinant;
		matrixInput = XMMatrixInverse(&determinant, matrixInput);
		XMFLOAT4X4 outputMat;
		XMStoreFloat4x4(&outputMat, matrixInput);
		
		return(outputMat);
	}

	void BenchUnopt(XMFLOAT4X4 inputMat, XMFLOAT4 inputVec, UINT count, std::vector<XMFLOAT4X4> &buffer)
	{
		for(UINT i = 0; i < count; i++)
		{
			buffer.push_back(UnoptA(inputMat, inputVec));
		}
	}
}

main.cpp

#include "Benchmarks.hpp"
#include "Profiler.hpp"

using namespace std;
using namespace Benchmark;

int main()
{
	Profiler &ProfilerRef = *Profiler::Instance();
	UINT count;
	cout<<"Select iteration amount:";
	cin>>count;
	cout<<endl<<"Test will now begin"<<endl<<endl;

	std::vector<XMFLOAT4X4> bufferUnopt;
	std::vector<XMFLOAT4X4> bufferOpt;
	bufferUnopt.reserve(count);
	bufferOpt.reserve(count);

	XMFLOAT4 testVector = XMFLOAT4(1.0f, 3.0f, 2.0f, 4.0f);
	XMFLOAT4X4 testMatrix = XMFLOAT4X4(3.0f,3.0f,3.0f,3.0f,
									   3.0f,3.0f,3.0f,3.0f,
									   3.0f,3.0f,3.0f,3.0f,
									   3.0f,3.0f,3.0f,3.0f);

	ProfilerRef();
	BenchUnopt(testMatrix, testVector, count, bufferUnopt);
	ProfilerRef();
	cout<<"Unoptimized Benchmkar: "<<ProfilerRef.GetDTime()<<endl;

	ProfilerRef();
	BenchOpt(testMatrix, testVector, count, bufferOpt);
	ProfilerRef();
	cout<<"Optimized Benchmkar: "<<ProfilerRef.GetDTime()<<endl;

	ofstream myfile;
	myfile.open ("example.txt");
	for(UINT i = 0; i < bufferOpt.size(); i++)
	{
		myfile<<bufferOpt[i]._11;
	}
	for(UINT i = 0; i < bufferUnopt.size(); i++)
	{
		myfile<<bufferUnopt[i]._11;
	}
	myfile.close();

	return 0;
}

I split the Benchmarks# into 2 .cpp files,so I can get 2 seperate ASM/Machine code lists,the Unopt version always gets over 20 times more output,but the speed difference is almosst 0




#5021239 Understanding XMVECTOR parameter passing to own functions

Posted by mrheisenberg on 13 January 2013 - 06:44 PM

I actualy tried to benchmark some DirectXMath code,one part was doing "unoptimized" functions,by taking XMFLOAT4X4 and XMFLOAT4 as arguments,then loading them into XMVECTOR/XMMATRIX,then doing operations,then storing again,passing again to another function that loads again and then stores again and outputs to the progra.The other test functions were doing the same operations,but with only loading/unloading when it has to output,otherwise taking CXMMATRIX and FXMVECTOR as arguments and being as fast as possible.Even with millions of calls,the "optimized" version was only slightly faster than the "unoptimized" one.




#5020966 Question about MJP's SampleFramework11(the Msg/Dlg-Function types)

Posted by mrheisenberg on 12 January 2013 - 11:00 PM

Hi,I added some functionality from the Window class in SampleFramework11 from the MSAAFilter sample from here: http://mynameismjp.wordpress.com/ ,I didn't alter much from the original code,other than the style,but when I build I get a Error 13 error C2064: term does not evaluate to a function taking 4 arguments c:\program files (x86)\microsoft visual studio 11.0\vc\include\xrefwrap 431 error,I think it's related to the:

typedef std::tr1::function<LRESULT (HWND, UINT, WPARAM, LPARAM)> MsgFunction;
typedef std::tr1::function<INT_PTR (HWND, UINT, WPARAM, LPARAM)> DlgFunction;

but I didn't find absolutely anything that could help me about this kind of error in Google,if someone has had such a problem with the tr1::function,please share




#5019612 Is Clustered Forward Shading worth implementing?

Posted by mrheisenberg on 09 January 2013 - 02:34 PM

how much vRAM do your GBuffers usually take up?GPU-Z tells me with 8xMSAA that mine takes around 350mb just for a position,color,normal,specular buffer.




#5019568 Is Clustered Forward Shading worth implementing?

Posted by mrheisenberg on 09 January 2013 - 12:57 PM

the Z-prepass worries me,does that mean I have to do the tessellation twice as well?(tessellation already hits my FPS big time)




#5019439 Is Clustered Forward Shading worth implementing?

Posted by mrheisenberg on 09 January 2013 - 07:27 AM

http://www.cse.chalmers.se/~olaolss/get_file.php?filename=clustered_forward_demo.zip here's the demo,if you don't trust the direct link you can get it here http://www.cse.chalmers.se/~olaolss/main_frame.php?contents=publication&id=tiled_clustered_forward_talk




#5019374 Is Clustered Forward Shading worth implementing?

Posted by mrheisenberg on 08 January 2013 - 11:56 PM

I'm referring to this: http://www.cse.chalmers.se/~uffe/clustered_shading_preprint.pdf there is also a video avaliable  the performance of this technique seems to scale perfectly for huge amounts of lights,but on lower amounts performs a little worse than the less advanced tiled culling method.The thing is - has there ever been a case where you will need 30 thousand lights in a scene?Plus,won't it get bottlenecked by generating shadow maps for all the lights(in the youtube video the lights just pass trough the bridge and under it).Unfortunately I couldn't test it's performance,because for some reason the provided demo won't start up(even tho I support OpenGL 3 and higher) and I've never done GLSL,so it might take time to get it to work.




#4975755 RawInput causes the window to lag severely.

Posted by mrheisenberg on 02 September 2012 - 09:47 AM

This is pretty much my input handler:

Input* gInput = 0;
Input::Input()
{
   raw = 0;
}
Input::~Input()
{
}
void Input::Release()
{

}
void Input::Initialize()
{
Rid[0].usUsagePage = 1;
Rid[0].usUsage = 6;
Rid[0].dwFlags = 0;
Rid[0].hwndTarget=NULL;
Rid[1].usUsagePage = 1;
Rid[1].usUsage = 2;
Rid[1].dwFlags = 0;
Rid[1].hwndTarget=NULL;
RegisterRawInputDevices(Rid, 2, sizeof(Rid[0]));
}
void Input::Update()
{
if (raw->header.dwType== RIM_TYPEMOUSE)
{
  lastMouseX = raw->data.mouse.lLastX;
  lastMouseY = raw->data.mouse.lLastY;
  mouseFlags = raw->data.mouse.usFlags;
  mouseButtonFlags = raw->data.mouse.usButtonFlags;
  leftButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_LEFT_BUTTON_DOWN;
  rightButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_RIGHT_BUTTON_DOWN;
  middleButtonDown = raw->data.mouse.ulButtons & RI_MOUSE_MIDDLE_BUTTON_DOWN;
  if(raw->data.mouse.ulButtons & RI_MOUSE_WHEEL)
  {
   wheelZ = raw->data.mouse.usButtonData;
  }
}
if (raw->header.dwType== RIM_TYPEKEYBOARD)
{
  keyCode=raw->data.keyboard.VKey;
  bool keyPressed=raw->data.keyboard.Flags & RI_KEY_BREAK;
}
}


class Input
{
#pragma region REGION:INPUT_METHODS
public:
Input();
~Input();

void Release();
void Initialize();
void Update();
#pragma endregion
#pragma region REGION:INPUT_MEMBERS
public:
RAWINPUTDEVICE Rid[2];
RAWINPUT *raw;
long lastMouseX;
long lastMouseY;
USHORT mouseFlags;
USHORT mouseButtonFlags;
USHORT wheelZ;
bool leftButtonDown;
bool rightButtonDown;
bool middleButtonDown;
USHORT keyCode;
#pragma endregion
};
extern Input* gInput;


#endif

When I initialize it in the main function like this:
gInput = new Input();
gInput->Initialize();

The window starts lagging and all 4 cores of my CPU show increased load,as much as 20% - 40% !!
I tried to read input with Enter and LeftMouseButton,but it doesn't respond:

while(!done)
    {
	    if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	    {
		    TranslateMessage(&msg);
		    DispatchMessage(&msg);
	    }
	    if(msg.message == WM_QUIT)
	    {
		    done = true;
	    }
 
  if(msg.message == WM_INPUT)
  {
  UINT bufferSize;
  GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, NULL, &bufferSize, sizeof (RAWINPUTHEADER));
  BYTE *buffer=new BYTE[bufferSize];
  GetRawInputData((HRAWINPUT)msg.lParam, RID_INPUT, (LPVOID)buffer, &bufferSize, sizeof (RAWINPUTHEADER));
  SafeDelete(gInput->raw);
  gInput->raw = (RAWINPUT*)buffer;
  gInput->Update();
  if(gInput->keyCode = VK_RETURN)
  {
   done = true;
  }
  if(gInput->leftButtonDown)
  {
   done = true;
  }
  }
	    else
	    {
   gGraphics->Render();
	    }
}
What am I doing wrong?Did I initialize with the wrong flags?I also tried it like this:

Rid[0].usUsagePage = 0x01;
Rid[0].usUsage = 0x02;
Rid[0].dwFlags = RIDEV_NOLEGACY;  
Rid[0].hwndTarget = 0;


Rid[1].usUsagePage = 0x01;
Rid[1].usUsage = 0x06;
Rid[1].dwFlags = RIDEV_NOLEGACY; 
Rid[1].hwndTarget = 0;



Same thing happens..


#4973474 Visual Studio 2012 ruined everything

Posted by mrheisenberg on 26 August 2012 - 08:04 AM

I worked for around a year on a DirectX Framework in C++ in Visual Studio 2010.Then I made the horrible mistake of getting the new one - after I installed it the DirectX SDK samples started having all sorts of problems,I couldn't even compile audio libraries that I could with 2010,I heard others had the same problems after installing it with the new .NET 4.5.It also replaced some of the C++ core libraries I think,because after I spent 5 hours uninstalling this abomination(along with the other 30 things that installed along with it,my project started missing about 120 headers('excpt.h','crtdbg.h','string.h',pretty much everything).I uninstalled both 2010 and 2012,uninstalled all the .NET versions and the SDK and everything,then reinstalled 2010,.NET 4 and the SDK.The missing 120 headers problem still persists...what can I do to fix this?


PARTNERS