Jump to content

  • Log In with Google      Sign In   
  • Create Account

Muzzy A

Member Since 25 May 2007
Offline Last Active Jun 04 2015 11:15 AM

Topics I've Started

Shader always returns white

26 November 2014 - 03:06 PM

Hi, I'm trying to do some simple D3D9 rendering.


Problem is, with the shader below, the output on screen is always white even though I'm clearly telling it to return blue

float4x4 gWorld : WORLD;
float4x4 viewProj : VIEWPROJECTION;
 // Vertex Shader
float4 vs( float3 pos : POSITION ) : POSITION
    float4 output;
    output = mul( float4( pos.xyz,1 ), gWorld );
    output = mul( float4( output.xyz,1 ),viewProj );
    return output;
// Pixel Shader
float4 ps( float4 pos : POSITION ) : COLOR
    // Returning blue, but getting white?
    return float4( 0,0,1,1 );

this problem doesn't occur if I simply add another semantic to the vertex shader input, then it returns whatever color I want.


The object is drawn correctly ( cube in this case ) just the wrong color unless I pass the vertex shader more than just the position.


I'll post c++ code if it's needed.  




I actually found it it will only apply the color the way it should ONLY if I pass the color through vertices.  Continuing to debug...




It seems that the pixel shader isn't even getting called.  Any color I return from the vertex shader will be the color used assuming that I have the COLOR semantic on it, and if no color is returned the color is white.

// This is how I load the shader, not sure where to go from here.  But I'll google some more
D3D9* d3d = CEngine::getD3D9();
D3DXCreateEffectFromFileA( d3d->getDevice(),"Assets/Shaders/SimpleShader.fx",0,0,0,0,&shader,0 );

C++ Function Pointer Casting

10 September 2014 - 03:14 PM


    I'm trying to set up a function pointer so that ANY function can be passed to it as long as it's the same signature.



// Define a simple function pointer
typedef void (*FuncPointer)();
void someFunc()
int main()
    FuncPointer func = someFunc;
// This works no prob
// Now here is what I want to do
class A
    void foo();

// Define a simple function pointer
typedef void (*FuncPointer)();

int main()
    // This is what I want to work
    FuncPointer func = A::foo;
    // I want it to work without having to define a function pointer like this
   typedef void (A::*FunctionPointer)()

DirectX 11 Drawing multiple instances of the same object

03 April 2014 - 08:54 PM

I'm trying to set up Direct X 11 and I have a cube that I'm trying to render multiple times in different places.  The problem is only the last one being drawn gets rendered.



Here is how I set my constant buffers

struct objData
    Matrix4x4 world;
    Matrix4x4 viewProj;

// I do this for every object
void CRenderer::setPerObjectData( const Matrix4x4& world,const Matrix4x4& viewProj )
    D3D11* d3d = g_Engine->getD3D();
    objData d = { world,viewProj };
    d3d->getDeviceContext()->Map(_pObjectData, 0, D3D11_MAP_WRITE_DISCARD, 0, &edit);

    memcpy(edit.pData, &d, sizeof( objData ) );

    d3d->getDeviceContext()->Unmap(_pObjectData, 0);
    // '_pObjectData' is the same buffer for all the objects being rendered
    d3d->getDeviceContext()->VSSetConstantBuffers(0, 1, &_pObjectData);

A question about where to store the Camera!

29 March 2014 - 01:09 PM

Hi, I'm building my own little renderer and there's a couple things that I get undecided about.


Where exactly do most of you store things like the Camera and Projection matrix?

I've seen and tried several different ways of doing so, but I'm not satisfied by any of them.

  • Save it in the renderer, pass them as parameters to the render functions - Probably the best way, but I don't want Parameters!
  • Make a singleton for the camera ( HORRIBLE! ) to access it anytime.
  • Make a static variable in the render objects that holds a reference to the camera and projection matrix.


I'm just a little curious at how others would do this minor little thing.

SIMD Function - Illegal instruction?

12 January 2014 - 09:35 PM

I made a particle emitter that will use SIMD

But it crashes on the first load in SIMD - Illegal Instruction

// Particle struct

struct Particle
__declspec(align(32)) float x[MAX_PARTICLES];
__declspec(align(32)) float y[MAX_PARTICLES];
__declspec(align(32)) float z[MAX_PARTICLES];
__declspec(align(32)) float dirX[MAX_PARTICLES];
__declspec(align(32)) float dirY[MAX_PARTICLES];
__declspec(align(32)) float dirZ[MAX_PARTICLES];
__declspec(align(32)) float m_Rate[MAX_PARTICLES];
__declspec(align(32)) int m_RandQuality[MAX_PARTICLES];
__declspec(align(32)) float m_RemainingLifetime[MAX_PARTICLES];
// The list of particles
Particle m_Particle;

for( int i=0;i<MAX_PARTICLES; i += 4 )
// use SIMD
Particle* pPart = &m_Particle;
__m128 x = _mm256_load_ps(pPart->dirX + i);   // Breaks on this line and says "Illegal Instruction" and I have no clue why
__m128 y = _mm256_load_ps(pPart->dirY + i);

// ..
// ..
// ..

Any suggesetions?