Awwww yiss

Coco | Heroic Unstoppable!
 
more |
XBL: Monsieur Cocco
PSN:
Steam: Mr Coco
ID: Cocos
IP: Logged

2,576 posts
 


Got dat fine ass Gouraud shading implemented.  Working on Phong.  Thought I'd share.  Anyone ever toy around with DirectX before?  This shit is confusing as fuck, and it's as if DX9 has no documentation.

Code: [Select]
#pragma once
#include "d3dApp.h"
//=============================================================================
class BaseMaterial
{
protected:
    ID3DXEffect*        mEffect;               // the shader associate effect file

D3DXHANDLE mTech;

    //——-- Material Parameters ——-
    D3DXMATRIX          mWorldMat;
    D3DXMATRIX          mViewProjectionMat;

//——— Colors ———--
D3DXCOLOR mAmbientColor;
D3DXCOLOR mDiffuseColor;
D3DXCOLOR mSpecularColor;

float     m_Shininess;            // specualr power

//——— Lights ———--

D3DXCOLOR mAmbientLightColor;
D3DXCOLOR mDiffuseLightColor;
D3DXCOLOR mSpecularLightColor;

D3DXCOLOR mAttenuation;

    //———- Shader Handles ———-
    // Generic shader handles
    D3DXHANDLE          mWorldMatHandle;   
D3DXHANDLE          mViewProjectionMatHandle;
D3DXHANDLE mWorldInvTransHandle;

    D3DXHANDLE          mLightPosWHandle;       // Position (spot/point) / Direction (directional)
    D3DXHANDLE          mViewerPosWHandle;

    // Material specific shader handles
D3DXHANDLE mAmbientColHandle;
    D3DXHANDLE          mDIffuseColHandle;   
    D3DXHANDLE          mSpecularColHandle;

D3DXHANDLE mAmbientLightHandle;
D3DXHANDLE          mDIffuseLightHandle;
D3DXHANDLE          mSpecularLightHandle;

D3DXHANDLE mAttenuationHandle;
    D3DXHANDLE          mShininessHandle;   

// Light specific shader handles
D3DXHANDLE mLightDirHandle;


public:
    BaseMaterial(void);
BaseMaterial(D3DXCOLOR ambient, D3DXCOLOR diffuse, D3DXCOLOR specular);
    virtual ~BaseMaterial(void);

    void ConnectToEffect( ID3DXEffect* effect );
void Render(D3DXMATRIX& worldMat, D3DXMATRIX& view, D3DXMATRIX& projection, D3DXVECTOR3 lightDirection, ID3DXMesh* mesh);
};
Code: [Select]
#include "BaseMaterial.cpp"
#include "3DClasses\Vertex.h"
//=============================================================================
BaseMaterial::BaseMaterial(void)
{
    mEffect = NULL;
ConnectToEffect(mEffect);
}

BaseMaterial::BaseMaterial(D3DXCOLOR ambient, D3DXCOLOR diffuse, D3DXCOLOR specular)
:mAmbientColor(ambient),
mDiffuseColor(diffuse),
mSpecularColor(specular)
{
ConnectToEffect(mEffect);
mAmbientLightColor = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
mDiffuseLightColor = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
mSpecularLightColor = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);


m_Shininess = 3.2f;
}

//—————————————————————————--
// Relase shader, blah...
BaseMaterial::~BaseMaterial(void)
{
ReleaseCOM(mEffect);
}

//—————————————————————————--
// Connects mEffect to shader file, and associates parameters
void BaseMaterial::ConnectToEffect( ID3DXEffect* effect )
{
ID3DXBuffer* errors = 0;
HR(D3DXCreateEffectFromFile(gd3dDevice, "ambientdiffusespec.fx", 0, 0, D3DXSHADER_DEBUG, 0, &mEffect, &errors));

if (errors)
MessageBox(0, (char*)errors->GetBufferPointer(), 0, 0);



mAmbientColHandle = mEffect->GetParameterByName(0, "gAmbientMtrl");
mDIffuseColHandle = mEffect->GetParameterByName(0, "gDiffuseMtrl");
mSpecularColHandle = mEffect->GetParameterByName(0, "gSpecularMtrl");

mAmbientLightHandle = mEffect->GetParameterByName(0, "gAmbientLight");
mDIffuseLightHandle = mEffect->GetParameterByName(0, "gDiffuseLight");
mSpecularLightHandle = mEffect->GetParameterByName(0, "gSpecularLight");

mShininessHandle = mEffect->GetParameterByName(0, "gSpecularPower");
//mAttenuationHandle = mEffect->GetParameterByName(0, "gAttenuation012");

}

void BaseMaterial::Render(D3DXMATRIX& worldMat, D3DXMATRIX& view, D3DXMATRIX& projection, D3DXVECTOR3 lightDirection, ID3DXMesh* mesh)
{
mTech = mEffect->GetTechniqueByName("AmbientDiffuseSpecTech");
HR(mEffect->SetTechnique(mTech));

mWorldMatHandle = mEffect->GetParameterByName(0, "gWorld");
mViewProjectionMatHandle = mEffect->GetParameterByName(0, "gWVP");
mWorldInvTransHandle = mEffect->GetParameterByName(0, "gWorldInverseTranspose");


mLightDirHandle = mEffect->GetParameterByName(0, "gLightVecW");
//lightDirection = D3DXVECTOR3(0, 0, -1);

mViewerPosWHandle = mEffect->GetParameterByName(0, "gEyePosW");

D3DXMATRIX W, WIT;
D3DXMatrixIdentity(&W);
D3DXMatrixInverse(&WIT, 0, &W);
D3DXMatrixTranspose(&WIT, &WIT);

//Begin passes
UINT numPasses = 0;
HR(mEffect->Begin(&numPasses, 0));
for (UINT i = 0; i < numPasses; ++i)
{
HR(mEffect->BeginPass(i));
gd3dDevice->SetVertexDeclaration(VertexPN::Decl);

//Matricies
HR(mEffect->SetMatrix(mWorldMatHandle, &worldMat));
HR(mEffect->SetMatrix(mViewProjectionMatHandle, &(worldMat * view * projection)));
HR(mEffect->SetMatrix(mWorldInvTransHandle, &WIT));

// Light
HR(mEffect->SetValue(mLightDirHandle, &lightDirection, sizeof(D3DXVECTOR3)));

//Ambient + Diffuse + Specular
HR(mEffect->SetValue(mAmbientColHandle, &mAmbientColor, sizeof(D3DXCOLOR)));
HR(mEffect->SetValue(mDIffuseColHandle, &mDiffuseColor, sizeof(D3DXCOLOR)));
HR(mEffect->SetValue(mSpecularColHandle, &mSpecularColor, sizeof(D3DXCOLOR)));

HR(mEffect->SetValue(mAmbientLightHandle, &mAmbientLightColor, sizeof(D3DXCOLOR)));
HR(mEffect->SetValue(mDIffuseLightHandle, &mDiffuseLightColor, sizeof(D3DXCOLOR)));
HR(mEffect->SetValue(mSpecularLightHandle, &mSpecularLightColor, sizeof(D3DXCOLOR)));

//HR(mEffect->SetValue(mAttenuationHandle, &mAttenuation, sizeof(D3DXCOLOR)));
HR(mEffect->SetFloat(mShininessHandle, m_Shininess));

HR(mEffect->CommitChanges());

//Mesh
HR(gd3dDevice->SetTransform(D3DTS_WORLD, &worldMat));
HR(gd3dDevice->SetTransform(D3DTS_VIEW, &view));
HR(gd3dDevice->SetTransform(D3DTS_PROJECTION, &projection));
mesh->DrawSubset(0);


HR(mEffect->EndPass());
}

mEffect->End();

}




Ingy | Mythic Inconceivable!
 
more |
XBL:
PSN:
Steam:
ID: Ingloriouswho98
IP: Logged

14,559 posts
 
Implying half the people here understands that shit


 
Hahahaha very funny Zonda
| p o l l o
 
more |
XBL: banjo my honey
PSN:
Steam: BanjoKazooie
ID: ねこ
IP: Logged

18,562 posts
RIP ENDIE
This user has been blacklisted from posting on the forums. Until the blacklist is lifted, all posts made by this user have been hidden and require a Sep7agon® SecondClass Premium Membership to view.


Coco | Heroic Unstoppable!
 
more |
XBL: Monsieur Cocco
PSN:
Steam: Mr Coco
ID: Cocos
IP: Logged

2,576 posts
 
Implying half the people here understands that shit

Basically all that code, minus the shader file, which I didn't include, is responsible for making any 3D object you ever see on a screen not look like this:



Aka, giving it color, visible depth, making it sensitive to light, changing how it would reflect light based on what angle you're looking at it, etc... (aka aka ambient + diffuse + specular lighting)
I think that's pretty crazy.


Ingy | Mythic Inconceivable!
 
more |
XBL:
PSN:
Steam:
ID: Ingloriouswho98
IP: Logged

14,559 posts
 
Implying half the people here understands that shit

Basically all that code, minus the shader file, which I didn't include, is responsible for making any 3D object you ever see on a screen not look like this:



Aka, giving it color, visible depth, making it sensitive to light, changing how it would reflect light based on what angle you're looking at it, etc... (aka aka ambient + diffuse + specular lighting)
I think that's pretty crazy.

I figured as much but I still can't decipher it


Coco | Heroic Unstoppable!
 
more |
XBL: Monsieur Cocco
PSN:
Steam: Mr Coco
ID: Cocos
IP: Logged

2,576 posts
 
Implying half the people here understands that shit

Basically all that code, minus the shader file, which I didn't include, is responsible for making any 3D object you ever see on a screen not look like this:



Aka, giving it color, visible depth, making it sensitive to light, changing how it would reflect light based on what angle you're looking at it, etc... (aka aka ambient + diffuse + specular lighting)
I think that's pretty crazy.

I figured as much but I still can't decipher it

I've spent several hours this week trying to decipher DirectX's gibberish, and I only posted this because I'm way too excited that it's coming together, somewhat.


Coco | Heroic Unstoppable!
 
more |
XBL: Monsieur Cocco
PSN:
Steam: Mr Coco
ID: Cocos
IP: Logged

2,576 posts
 


Phong shading, yo.


Tyger | Elite Four Inconceivable!
 
more |
XBL: TP_OneThree
PSN: Tyger_Power
Steam:
ID: Tyger
IP: Logged

10,584 posts
 
Good job you made a teapot do you want a sticker


 
Elegiac
| Knight of the Limits
 
more |
XBL:
PSN:
Steam:
ID: Elegiac
IP: Logged

23,675 posts
:)


Coco | Heroic Unstoppable!
 
more |
XBL: Monsieur Cocco
PSN:
Steam: Mr Coco
ID: Cocos
IP: Logged

2,576 posts
 
Good job you made a teapot do you want a sticker
Yes.


Girl of Mystery | Mythic Unfrigginbelievable!
 
more |
XBL:
PSN:
Steam:
ID: TheBritishLemon
IP: Logged

23,349 posts
A flower which blooms on the battlefield
Good job you made a teapot do you want a sticker
A teapot that's in slow motion


 
cxfhvxgkcf-56:7
| Marty Inconceivable!
 
more |
XBL:
PSN:
Steam:
ID: SoporificSlash
IP: Logged

15,656 posts
 
This user has been blacklisted from posting on the forums. Until the blacklist is lifted, all posts made by this user have been hidden and require a Sep7agon® SecondClass Premium Membership to view.


Coco | Heroic Unstoppable!
 
more |
XBL: Monsieur Cocco
PSN:
Steam: Mr Coco
ID: Cocos
IP: Logged

2,576 posts
 
IM IN LOVE WITH THE COCO
IF U SNITCHIN I GO LOCO