Jump to content

  • Log In with Google      Sign In   
  • Create Account

markypooch

Member Since 26 Mar 2013
Offline Last Active Yesterday, 05:45 PM

#5298124 Basic texturing

Posted by markypooch on 26 June 2016 - 11:52 AM

Very much depends on your use scenario. Does the texel being evaluated through your pixel shader only reference a single texture for it's computation? If your making a game that only needs simple texturing, and to have it sampled by a single SamplerState at any given shader execution, sure one Texture2D, and SamplerState should be fine.

 

As MJP stated, you'll change the texture, and sampler bindslots cpu side for different textures, and (if need be) corresponding samplers, and the bindslots will retain there textures, and samplers between draw calls, and shader swaps. 

 

The website you mentioned will eventually step you through more advanced use scenarios where for a given texel you'll evaluate it against several textures, such as, normal maps, shadow maps, and ect.

 

Marcus Hansen




#5297356 what means these error?

Posted by markypooch on 20 June 2016 - 02:12 PM

Hello Cambalinho,

 

it has been awhile since I received a similar error, so I had to do a little bit of research. The general consensus is that the error is given when attempting to access a pointer that has either not been properly initialized, or has been deleted. Essentially trying to de-reference a dangling pointer that may point to an unexpected area in memory. If my explanation proves to be insufficient, i'll attempt to clarify, or through a google search you will be able to procure a wealth of info in regards to this particular error.

 

Might also be helpful to post the source file(s) that is generating the errors.

 

Marcus Hansen




#5296649 How to avoid Singletons/global variables

Posted by markypooch on 15 June 2016 - 08:27 AM

I always love practical examples.
 

 

void SomeFunc() //This function requires no argument. So it appears to be relatively standalone

{

    mySingletonClass* mySingletonClass::getSingletonObject() //Oh, you evil sob

    //does something

}

 

 

If the project is small as others have stated, AND you, and/or one other guy are they only developers touching the code. A singleton could be justified. But take a look at that function. How am I, as a curious passerby in the project know what in god's name the function truly requires for it's functionality? I have come across several times in production code, and more often than not it tends to be a show stopper. 

 

Avoid them, even if your the only one working on a project. For all you know someone may come by in the future, and need to work on it. Besides though singletons can make code look cleaner, it actually shows extremely bad foresight, and the inability to nail down a coherent, and non-opaque object/function design.

 

Marcus Hansen




#5292094 What is this artifact in my shadow map?

Posted by markypooch on 17 May 2016 - 11:19 AM

Two thoughts come to mind.

 

Have you tried playing around with the bias? Tweaking it until the issue is not visible on the geometry?

Also, are you using a nullified Sampler State, or did you specify a clamped sampler?

 

Marcus Hansen




#5290448 XNA Width And Height Problem

Posted by markypooch on 06 May 2016 - 11:32 AM

To further elaborate on nscu121978's answer.

 

"If you request a back-buffer resolution that is not supported by the output device, the XNA Framework automatically selects the highest resolution supported by the output device. For example, if a graphics back buffer with a resolution of 1920×1080 (1080p or 1080i) is created and displayed on a device with 480i resolution, the back buffer automatically is resized to 480i."

 

https://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphicsdevicemanager.preferredbackbufferwidth.aspx

 

This is verbatim from the MSDN website on the use of preferredBackBufferWidth & Height.

Also, it seems there's a general consensus that the ApplyChanges Method should only be called within the update method of your game class, not entirely sure that it matters, but it's worth a shot.

 

Marcus Hansen




#5289067 triangle culling in close proximity to other triangles?

Posted by markypooch on 28 April 2016 - 04:43 AM

Hello,

 

haha, it would probably help if I knew what I was looking at ;)

 

But have you ruled out the possibility of inverted normals on the mesh, with BF culling that would certainly create the issue of triangles not appearing...

 

Marcus Hansen




#5288014 Going multi-threaded | Batches and Jobs

Posted by markypooch on 21 April 2016 - 12:01 PM

Basicly I don't understand what 'Batches' and 'Jobs' are.

 

What are 'Batches' and 'Jobs' when generally speaking about Thread Pooling?

What are the best way to identify a function call as a 'Batch' or either as a 'Job'?

 

Hello Julien,

 

Essentially when he means jobs, he simply is implying work that an engine sub-system has to perform. When he says batch, it's just a conceptualization in the context of the article of a group of individual objects deli-metered based upon some logical segmentation (A BSP Tree perhaps) being submitted to a ThreadPool Queue.

 

How would one go about creating a multi-thread system?

 

To my knowledge, C/C++ by itself has no notion of multi-threading. But, here goes a pretty simple example in C, from MSDN, also I'm pretty sure the threading code here is not portable. But, I think Boost does offer a portable solution...

 

 

// sample_multithread_c_program.c
// compile with: /c
//
//  Bounce - Creates a new thread each time the letter 'a' is typed.
//  Each thread bounces a happy face of a different color around
//  the screen. All threads are terminated when the letter 'Q' is
//  entered.
//

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <process.h>

#define MAX_THREADS  32

// The function getrandom returns a random number between
// min and max, which must be in integer range.
#define getrandom( min, max ) (SHORT)((rand() % (int)(((max) + 1) - \
                               (min))) + (min))

int main( void );                    // Thread 1: main
void KbdFunc( void  );               // Keyboard input, thread dispatch
void BounceProc( void * MyID );      // Threads 2 to n: display
void ClearScreen( void );            // Screen clear
void ShutDown( void );               // Program shutdown
void WriteTitle( int ThreadNum );    // Display title bar information

HANDLE  hConsoleOut;                 // Handle to the console
HANDLE  hRunMutex;                   // "Keep Running" mutex
HANDLE  hScreenMutex;                // "Screen update" mutex
int     ThreadNr;                    // Number of threads started
CONSOLE_SCREEN_BUFFER_INFO csbiInfo; // Console information


int main() // Thread One
{
    // Get display screen information & clear the screen.
    hConsoleOut = GetStdHandle( STD_OUTPUT_HANDLE );
    GetConsoleScreenBufferInfo( hConsoleOut, &csbiInfo );
    ClearScreen();
    WriteTitle( 0 );

    // Create the mutexes and reset thread count.
    hScreenMutex = CreateMutex( NULL, FALSE, NULL );  // Cleared
    hRunMutex = CreateMutex( NULL, TRUE, NULL );      // Set
    ThreadNr = 0;

    // Start waiting for keyboard input to dispatch threads or exit.
    KbdFunc();

    // All threads done. Clean up handles.
    CloseHandle( hScreenMutex );
    CloseHandle( hRunMutex );
    CloseHandle( hConsoleOut );
}

void ShutDown( void ) // Shut down threads
{
    while ( ThreadNr > 0 )
    {
        // Tell thread to die and record its death.
        ReleaseMutex( hRunMutex );
        ThreadNr--;  
    }

    // Clean up display when done
    WaitForSingleObject( hScreenMutex, INFINITE );
    ClearScreen();
}

void KbdFunc( void ) // Dispatch and count threads.
{
    int         KeyInfo;

    do
    {
        KeyInfo = _getch();
        if ( tolower( KeyInfo ) == 'a' &&
             ThreadNr < MAX_THREADS )
        {
            ThreadNr++;
            _beginthread( BounceProc, 0, &ThreadNr );
            WriteTitle( ThreadNr );
        }
    } while( tolower( KeyInfo ) != 'q' );

    ShutDown();
}

void BounceProc( void *pMyID )
{
    char    MyCell, OldCell;
    WORD    MyAttrib, OldAttrib;
    char    BlankCell = 0x20;
    COORD   Coords, Delta;
    COORD   Old = {0,0};
    DWORD   Dummy;
    char    *MyID = (char*)pMyID;

    // Generate update increments and initial
    // display coordinates.
    srand( (unsigned int) *MyID * 3 );

    Coords.X = getrandom( 0, csbiInfo.dwSize.X - 1 );
    Coords.Y = getrandom( 0, csbiInfo.dwSize.Y - 1 );
    Delta.X = getrandom( -3, 3 );
    Delta.Y = getrandom( -3, 3 );

    // Set up "happy face" & generate color
    // attribute from thread number.
    if( *MyID > 16)
        MyCell = 0x01;          // outline face
    else
        MyCell = 0x02;          // solid face
    MyAttrib =  *MyID & 0x0F;   // force black background

    do
    {
        // Wait for display to be available, then lock it.
        WaitForSingleObject( hScreenMutex, INFINITE );

        // If we still occupy the old screen position, blank it out.
        ReadConsoleOutputCharacter( hConsoleOut, &OldCell, 1,
                                    Old, &Dummy );
        ReadConsoleOutputAttribute( hConsoleOut, &OldAttrib, 1,
                                    Old, &Dummy );
        if (( OldCell == MyCell ) && (OldAttrib == MyAttrib))
            WriteConsoleOutputCharacter( hConsoleOut, &BlankCell, 1,
                                         Old, &Dummy );

        // Draw new face, then clear screen lock
        WriteConsoleOutputCharacter( hConsoleOut, &MyCell, 1,
                                     Coords, &Dummy );
        WriteConsoleOutputAttribute( hConsoleOut, &MyAttrib, 1,
                                     Coords, &Dummy );
        ReleaseMutex( hScreenMutex );

        // Increment the coordinates for next placement of the block.
        Old.X = Coords.X;
        Old.Y = Coords.Y;
        Coords.X += Delta.X;
        Coords.Y += Delta.Y;

        // If we are about to go off the screen, reverse direction
        if( Coords.X < 0 || Coords.X >= csbiInfo.dwSize.X )
        {
            Delta.X = -Delta.X;
            Beep( 400, 50 );
        }
        if( Coords.Y < 0 || Coords.Y > csbiInfo.dwSize.Y )
        {
            Delta.Y = -Delta.Y;
            Beep( 600, 50 );
        }
    }
    // Repeat while RunMutex is still taken.
    while ( WaitForSingleObject( hRunMutex, 75L ) == WAIT_TIMEOUT );
}

void WriteTitle( int ThreadNum )
{
    enum {
        sizeOfNThreadMsg = 80
    };
    char    NThreadMsg[sizeOfNThreadMsg];

    sprintf_s( NThreadMsg, sizeOfNThreadMsg,
               "Threads running: %02d.  Press 'A' "
               "to start a thread,'Q' to quit.", ThreadNum );
    SetConsoleTitle( NThreadMsg );
}

void ClearScreen( void )
{
    DWORD    dummy;
    COORD    Home = { 0, 0 };
    FillConsoleOutputCharacter( hConsoleOut, ' ',
                                csbiInfo.dwSize.X * csbiInfo.dwSize.Y,
                                Home, &dummy );
}
 

 

So this is pretty simple. While 'q' has not been pressed, and if 'a' has been pressed, and if ntThread is less than 32; increment ntThread, pass the BounceProc function as an argument to the __beginThread() function.

 

insofar as how to structure this in a typical Game Engine though the article gave some high level insight on it, a deeper explanation on it however would probably be a question best reserved for some other members here, as my only real experience with Multi-Threading was with Java several years ago.

 

Marcus Hansen




#5281543 Match-3 puzzle game algorithms

Posted by markypooch on 16 March 2016 - 02:57 PM

 

I want a 9X9 grid layout for the game and I would like to have some guidance to design the algorithms to fill up the empty cells of the grid, after match making takes place. I also would like some guidance on how to design the level progression and ramp up the difficulty in a match three puzzle game.

 

Well I'm not sure how you have your program structured so far (And if you've chosen to have your board represented by a simple array), but code for populating a 1D, or 2D array (in the following example 2D) is quite simple, and can be expressed in many ways. But one simple way is:

//Psuedo Code
Cell board[9][9];
 
for (i = 0 to board.length())
    for (j = 0 to board.length()) //Assuming your board is 
always column, and row symmetrical
        board[i][j] = new Cell() //where 
your default constructor for cell will just self initialize to be representative 
of an empty cell
        //Or alternatively
        board[i][j] = new 
Cell(Enumerator.SomeRandomColor);

Of course, I would imagine as Frob sated that populating your board at pure random may lead to cases that as soon as your game loads you get a match 3 Or match 4 without player intervention, which is obviously a sign of either a very liberal, and player friendly Matching game, or a poorly designed one. (I once played a version of bejeweled that upon a level loading I would get Match 4s all over the place, haha, let's just say Wisdom Cat was not amused)

 

One simple to code game would be TicTacToe. This would give you an idea on how a very basic matching game is created, and potentially provide you with a base to build into a more complex project which ultimately seems like what you want.

 

Marcus




#5281260 visual problem with texture tiling

Posted by markypooch on 14 March 2016 - 03:35 PM

This is a well know issue. 

One solution would be to flesh out the terrain more, i.e. blend with other textures (A patch of grass that fades into the sand texture?), add supportive meshes (A cactus, a palm tree, a decrepit colonist cart partially devoured by the sand dune, and some ram skulls for good measure ;) ) 

 

Another one that can be used in conjunction with the previous solution is to use Google! no, haha sorry. But seriously, upon searching your issue in google I found something called Multi-UV mixing which appears to be the result of sampling your base texture with a replica texture at a larger resolution in your shader (I may have butchered that). The results based upon a few articles that I glanced over seem to be something worth looking into

 

(I'll include the link in the case I completely butchered the idea behind the technique)

 

http://forum.unity3d.com/threads/improved-terrain-texture-tiling.116509/

 

http://polycount.com/discussion/116254/terrain-tiling-reduction-multi-uv-mixing 

 

Marcus




#5281211 For beginners

Posted by markypooch on 14 March 2016 - 09:28 AM

The only pre-requisite for making games is to have the desire (Programming/Mathematics knowledge is a huge plus). There are plenty of tools out their that will accommodate peoples desires to make games without even a sliver of technical knowledge.

 

As far as APIs, it REALLY depends on the game your trying to make, the target audience, or if your doing it to amuse yourself. You can make a fun game with console graphics. In fact I remember back in middle school before I learned D3D coding an animated ascii game. In order to accomplish sprite animation I'd do things like this:

 

char  frOne[] = {' ',' ',' ',' ','*',' ',' ',' '};

char  frTwo[] = {' ',' ',' ',' ',' ','*',' ',' '}; //The asterisk is just moving to the right.

 

And I would use a simple timer to animate between these char arrays (though my renditions were much more complicated than a star). This produced a result than brought life to my console games.

 

If you want to make 3D games your best bet is either an engine/framework like Unreal/Unity, or DIY and learn Direct3D11, OpenGL 4.0 APIs (Though the latter APIs are known for their inherent difficulty to learn for beginners, and are not always user friendly, and this list is certainly not exhaustive).

 

Python is a great language to start out with (A wealth of information, and tutorials are online), it's simple yet powerful. Ambiguous, and extremely flexible. And right off the bat it forces you to indent your code (Which is something I've laughably seen "Advanced" developers overlook). But that's not in stone. There are other good "beginner" languages as well. I started with C, but there was no real reason behind that at the time. I guess I was under the assumption was that it was the only language out their at the time. haha, ignorance can be bliss. 

 

This page serves to get your IDE environment, and SDK installed.

https://www.python.org/about/gettingstarted/

 

This page will take you through the Basics.

http://pythonprogramminglanguage.com/

 

Just remember games are games. Graphical finesse though important, is not the prime ingredient for making a fun game. A damn good idea implemented well IS however.

 

Marcus




#5280699 D3D9 - Rendering image to texture problem

Posted by markypooch on 11 March 2016 - 08:10 AM

Welcome to the forums!

 

First off your not an idiot. A lot of us are still learning here. Though some may disagree; the simple fact that your programming implies that you are capable of logical deduction, and flow control which would imply that you have a high level thought process organically accelerated by a human brain, haha.

 

That being said the first thing I would check are your renderStates.

 

without making square for it, so the texture will be just the image?

 

That's a great question.Your referring to Vectorized graphics which is the use of polygons to represent images/textures in graphics. But, I feel if you check over your RenderStates, or your underlying texture itself you'll find that complete transparency with a image is completely possible, and that the use of vectorized graphics for this one case is a little overkill imho

 

Marcus




#5238298 What is the easiest way to show effects(ice, fire, thunder, etc...) in direct...

Posted by markypooch on 03 July 2015 - 09:06 PM

It sounds as though you are using a method similar to that of one of the rastertek tutorials for fire. Having implmented it myself it produced an amicable result for a minimal amount of coding/effort.

However, you could try volumetric rendering with spherical billboards. The groundwork for the effect is layed out in ShaderX5, though im sure there is other relevant information to it in other publications.

 

 

Marcus




#5233883 HLSL matrix initialization

Posted by markypooch on 09 June 2015 - 01:42 PM

Might be time for someone with more HLSL knowledge to step in but I think it pertains to how HLSL stores data internally. It stuffs everything into a four-component vector, if anything straddles the 16-byte boundary it is liable to be pushed into a adajcent vector in memory or truncated.

 

Marcus




#5233864 HLSL matrix initialization

Posted by markypooch on 09 June 2015 - 12:47 PM

Hmmm, while I may be false in this assumption it looks like your values are indeed being read column major. I think by default HLSL is column-major. Compare/Contrast the values of your matrice to the debugger values (column wise) and you'll see whats going on. Each 4th component is being truncated (read column wise).  

 

Try using a float4x4 type for your tbn matrix and see if that works

 

Marcus




#5233585 The most efficient way to create a const array in HLSL?

Posted by markypooch on 08 June 2015 - 12:43 PM

 

Put the static keyword in front. In this case, it should only be defined once right?

 

From my understanding it's the same as in c/c++. Its defined once, and maintains static duration during run-time.

 

 

There are const global variables in OpenGL is there such an alternative in D3D?

The equivalent to my knowledge is a ConstantBuffer in D3D (ShaderModel 4.0+). Even if your data is to be declared outside of a constant buffer it still gets tucked into a default constant buffer under the hood.

 

To clarify a ConstantBuffer is a buffer that is optimized for constant variable usage and enables the app developer to specify data that is constant for that pass through the shader. Those are your constant variables in HLSL.

 

As to your original question, I don't know if it's the best way to do it (I can't say one way over the other), I don't think the way your doing it now is very performance prohibitive. At most when the function is called it has to allocate 128 bytes in video memory for that array.

 

Marcus






PARTNERS