Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


maya18222

Member Since 30 May 2008
Offline Last Active Apr 23 2013 05:34 PM

#4982162 WPF : How is this code working?

Posted by maya18222 on 20 September 2012 - 02:38 PM

Taken from one of the MSDN examples : http://msdn.microsoft.com/en-us/library/aa970558.aspx

I don't understand how the information in the lower three textboxes of the ContentControl stays synced up with the current selection in the list box. The binding for the ContentControl is bound to an ObservableCollection, which doesnt have any "CurrentItem" functionality. So what is the "IsSynchronizedWithCurrentItem" doing to make this all work?


#4980428 How to view Depth/colour targets in vs2012 Graphics Debugger

Posted by maya18222 on 15 September 2012 - 11:16 AM

I was kinda hoping you could select the depth or colour target object as the current object, and then be able to see the each draw call being rendered onto the buffer as you click over drawcall commands. However, if I do this, I dont see anything, just the clear colour for the colour target, and the checkboard pattern for the depth target.

Anyone got this to work?


#4896118 no books on c++ model loading ?

Posted by maya18222 on 21 December 2011 - 03:50 AM

Here is a rather old one http://www.amazon.com/Focus-Models-Premier-Press-Development/dp/1592000339

But my advice is just to use existing formats like FBX, as they can be exported from lots and lots of tools and are easy to extract from. Once you get to the point of efficiency you can then write a simple converter that will convert all your fbx data into something more efficient for you particular engine. OR even go as writing your own script for your favourite 3d program.


#4872160 What is used for visibility determination these days?

Posted by maya18222 on 13 October 2011 - 04:29 AM

Hodgeman - Why would the artefacts be so bad for a one frame delay? Most objects wouldn't move that much in a single frame, and those that do could maybe be removed from the occlusion system.


#4867753 Threadpool design

Posted by maya18222 on 30 September 2011 - 04:17 PM

First off, Im not trying to reinvent the wheel, I'm just doing this as an exercise.

Below is my ThreadPool class and first of all I was looking for some feedback on it. Secondly, you'll notice that queued tasks can only be dispatched to available threads in 2 places, when they are queued and then in the wait call. How would I go about implementing it so that tasks get dispatched as soon as a thread is free? Im thinking I'll need to have the ThreadPool operating on a thread of its own.

Thread Pool Code

#pragma once

#include <windows.h>
#include <vector>

template< int N >
class ThreadPool
{
public:
	ThreadPool()
	{
		for( int i = 0; i < N; ++i )
		{
			m_Threads[i] = CreateThread( 0, 0, Loop, &m_ThreadStates[i], 0, 0 );
		}
	}

	~ThreadPool()
	{
		for( int i = 0; i < N; ++i )
		{
			TerminateThread( m_Threads[i], 0 );
			CloseHandle( m_Threads[i] );
		}
	}

	void Queue( LPTHREAD_START_ROUTINE func, void* pParams )
	{
		Task t = { func, pParams };
		m_Tasks.push_back(t);

		for( int i = 0; i < N; ++i )
		{
			if( !m_ThreadStates[i].Working )
			{
				const Task& t = m_Tasks.back();
				m_ThreadStates[i].SetTask( t );
				m_Tasks.pop_back();
				return;
			}
		}
	}

	void WaitForAll()
	{
		while(true)
		{
			bool WorkStillinProcess = false;
			for( int i = 0; i < N; ++i )
			{
				if( m_ThreadStates[i].Working )
				{
					WorkStillinProcess = true;
				}
				else if( !m_Tasks.empty() )
				{
					const Task& t = m_Tasks.back();
					m_ThreadStates[i].SetTask( t );
					m_Tasks.pop_back();
					WorkStillinProcess = true;
				}
			}

			Sleep(0);

			if( !WorkStillinProcess )
				return;
		}
		return;	
	}

private:

	static DWORD WINAPI Loop( void* pParams )
	{
		ThreadState* pts = (ThreadState*)pParams;
		while(true)
		{
			if( pts->HasTask() )
			{
				pts->DoTask();
				pts->SetAvaliable();
			}

			Sleep(0);
		}
	}

	struct Task
	{
		LPTHREAD_START_ROUTINE Workfunc;
		void* pWorkParams;
	};

	struct ThreadState
	{
		ThreadState() : Working(0), Workfunc(0), pWorkParams(0) {}
		
		bool HasTask()
		{
			return Workfunc != 0;
		}

		void SetTask( const Task& t )
		{
			Working = 1;
			Workfunc = t.Workfunc;
			pWorkParams = t.pWorkParams;
		}

		void DoTask()
		{
			Workfunc( pWorkParams );
		}

		void SetAvaliable()
		{	
			Working = 0;
			Workfunc = 0;
			pWorkParams = 0;
		}

		int Working;
		LPTHREAD_START_ROUTINE Workfunc;
		void* pWorkParams;
	};

	ThreadState m_ThreadStates[N];
	HANDLE m_Threads[N];
	std::vector<Task> m_Tasks;
};

Usage

#include <iostream>
using namespace std;

#include "ThreadPool.h"

const unsigned int COUNT = 100000000;
const unsigned int THREADS = 4;

struct WorkParams
{
	float begin;
	float end;
	unsigned int count;	
	float result;
	float pad[16];
};

DWORD WINAPI ComputeAreaUnderCurve( void* pParams )
{
	WorkParams* plParams = (WorkParams*)pParams;
	double Area = 0.0f;
	double dx = ( plParams->end - plParams->begin ) / plParams->count;
	for( unsigned int i = 0; i < plParams->count; ++i )
	{
		double x = plParams->begin + (i * dx);
		Area += dx * x * x;
	}
	plParams->result = (float)Area;
	return 0;
}

int main()
{
	ThreadPool<THREADS> threadpool;

	while(true)
	{
		WorkParams wp[THREADS];
		float Result = 0.0f;

		for( int i = 0; i < THREADS; ++i )
		{
			wp[i].begin = i * (1.0f / THREADS);
			wp[i].end = (i+1) * (1.0f / THREADS);
			wp[i].count = (COUNT / THREADS);
			threadpool.Queue( ComputeAreaUnderCurve, &wp[i] );
		}

		threadpool.WaitForAll();

		for( int i = 0; i < THREADS; ++i )
		{
			Result += wp[i].result;
		}

		cout << "Result   : " << Result  << "\n";
	}

	cin.get();
}






#4841003 Ray tracing fur/hair

Posted by maya18222 on 27 July 2011 - 02:35 AM

How is fur/hair generally rendered with a raytracer? Looking at Mentalray, they just create a number of base hairs that the real hairs interpolate between. But how would you do the ray-intersection tests?

I thought about just splitting each strand into a number of segments, and then expanding each segment to form a cylinder and then doing a ray-cylinder test. This is obviously going to be very slow when you have millions of strands with multiple segments. So would you then just use an acceleration technique such as a kdtree? where each hair is stored as maybe an AABB?


#4758589 How do the latest games handle particle systems?

Posted by maya18222 on 13 January 2011 - 06:29 PM

Im talking about particle effects that are created with editors offerering all sorts of options though, many, many configurations. Im wondering if they just peform the update on the CPU where all the options can be rocesssed and send it down to a shader that draws it, or if they have some sort of configurable shader that does the whole lot.

Take the unreal editor for example, in their effect editor, you can stack up different processes for the emiter to perform.


PARTNERS