공부 중 메모/DirectX

13. GeometryShaderPoint

라이피 (Lypi) 2019. 1. 31. 21:07
반응형

선택한 이미지를 기하쉐이더로 여러개 뿌리고 쉐이더에 넘긴 상수버퍼의 값으로 이미지 크기나 색조등을 조절하는 예제.



저번 포스팅에서 obj.h obj.cpp / sample.h sample.cpp 부분과 쉐이더 코드인 SVertex.txt 부분이 달라졌다.

특히 obj.cpp 파일에 중요한 내용이 추가되었다.


쉐이더 코드는 편집할 때만 hlsl확장자를 붙이고 txt로 놓고 관리하는게 오류에서 훨씬 자유롭다.


쉐이더 코드나 이미지 파일은 경로를 따로 잡아줄 수도 있지만 현재는 프로젝트 내부에 소스 파일과 함께 두는것이 편할 것이다.



obj.h

#pragma once
#include "header.h"
#include "input.h"

enum ShaderName
{
	Vertex = 1,
	Pixel = 2,
	Geometry = 3,
	Hull = 4,
	Domain = 5,
	Computer = 6,
};

//#include "UserTexture.h"
void		                ClearD3D11DeviceContext(ID3D11DeviceContext* pd3dDeviceContext);
						    
HRESULT		                CompileShaderFromFile(const WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut);

ID3D11DeviceChild*          LoadSelectShaderFile(ShaderName Select, const void* pShaderFileData, ID3DBlob** ppBlobOut = nullptr, char* pFuntionName = 0);
						    
ID3D11InputLayout*          CreateInputlayout     (DWORD dwSize,   LPCVOID lpData, D3D11_INPUT_ELEMENT_DESC* layout, UINT numElements);

ID3D11Buffer*               CreateVertexBuffer    (void *vertices, UINT iNumVertex, UINT iSize, bool bDynamic = false);
ID3D11Buffer*               CreateIndexBuffer     (void *indices,  UINT iNumIndex,  UINT iSize, bool bDynamic = false);
ID3D11Buffer*               CreateConstantBuffer  (void *data,     UINT iNumIndex,  UINT iSize, bool bDynamic = false);

ID3D11ShaderResourceView*	CreateShaderResourceView(const TCHAR* strFilePath);
ID3D11DepthStencilView*     CreateDepthStencilView(DWORD dwWidth, DWORD dwHeight);


class Object_DX
{
public:
	ComPtr<ID3D11Buffer>               m_pVertexBuffer;   // 정점 버퍼
	ComPtr<ID3D11Buffer>               m_pIndexBuffer;    // 인덱스 버퍼
	ComPtr<ID3D11Buffer>               m_pConstantBuffer; // 상수 버퍼
	ComPtr<ID3D11VertexShader>         m_pVS;             // 정점 쉐이더
	ComPtr<ID3D11PixelShader>          m_pPS;             // 픽셀 쉐이더
	ComPtr<ID3D11GeometryShader>       m_pGS;             // 기하 쉐이더
	ComPtr<ID3D11InputLayout>          m_pInputLayout;    // 인풋 레이아웃
	ComPtr<ID3D11ShaderResourceView>   m_pTextureSRV;     // 텍스쳐 SRV
	ComPtr<ID3D11BlendState>           m_pAlphaBlend;

	//sampler 변수
	ID3D11SamplerState*         m_pSamplerState;
	UINT                        m_idxFilter;
	D3D11_FILTER                m_dxFilter;
	UINT                        m_iTexAddressMode;
	FLOAT                       m_MinLod;
	
	ComPtr<ID3DBlob>            m_pVSBlob;
	ComPtr<ID3DBlob>            m_pPSBlob;
	ComPtr<ID3DBlob>            m_pGSBlob;

	

public:
	PNCT_VERTEX m_pVertexList[4];

	uWH   m_uImageSize;
	iLTRB m_uImagePart;

	fLTRB m_fPRegion;

	POINT m_ptCenter;
	D3DXVECTOR3 m_v3Center;

public:
	iLTRB m_uSRegion;

	bool m_bExist;

private:
	void transStoP(); //화면 -> 투영
	void transPtoS(); //투영 -> 화면
	void UpdateCP(); //중점 갱신
	void UpdateVertexList(); //정점 리스트 갱신


public:
	HRESULT Create(const TCHAR* pTexFile);
	void ImagePartialSelect(iXYWH imgXYWH, uWH imgSize);
	void SetPosition(iXYWH _xywh);

	void CreateFullImgObj(iXYWH _xywh, const TCHAR* pTexFile);
	void CreatePartImgObj(iXYWH _xywh, iXYWH imgXYWH, uWH imgSize, const TCHAR* pTexFile);

	void ImagePartialChange(iXYWH);

	void ImageFileChange(const TCHAR* pTexFile);

	void MoveX(float fDis);
	void MoveY(float fDis);

	iLTRB getPos();

	void spin(float fAngle);
	void scale(float size);

	void ColorChange(float r, float g, float b, float a);
	void Color();

public:
	virtual bool Init();
	virtual bool Frame();
	virtual bool Render();
	virtual bool Release();

public:
	Object_DX();
	virtual ~Object_DX();

};

obj.cpp

#include "obj.h"

//------------- 오브젝트 관련 전역 함수 세팅 시작 ------//

void ClearD3D11DeviceContext(ID3D11DeviceContext* pd3dDeviceContext)
{
	// Unbind all objects from the immediate context
	if (pd3dDeviceContext == NULL) return;

	ID3D11ShaderResourceView* pSRVs[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
	ID3D11RenderTargetView* pRTVs[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
	ID3D11DepthStencilView* pDSV = NULL;
	ID3D11Buffer* pBuffers[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
	ID3D11SamplerState* pSamplers[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
	UINT StrideOffset[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };

	// Shaders
	pd3dDeviceContext->VSSetShader(NULL, NULL, 0);
	pd3dDeviceContext->HSSetShader(NULL, NULL, 0);
	pd3dDeviceContext->DSSetShader(NULL, NULL, 0);
	pd3dDeviceContext->GSSetShader(NULL, NULL, 0);
	pd3dDeviceContext->PSSetShader(NULL, NULL, 0);

	// IA clear
	pd3dDeviceContext->IASetVertexBuffers(0, 16, pBuffers, StrideOffset, StrideOffset);
	pd3dDeviceContext->IASetIndexBuffer(NULL, DXGI_FORMAT_R32_UINT, 0);
	pd3dDeviceContext->IASetInputLayout(NULL);

	// Constant buffers
	pd3dDeviceContext->VSSetConstantBuffers(0, 14, pBuffers);
	pd3dDeviceContext->HSSetConstantBuffers(0, 14, pBuffers);
	pd3dDeviceContext->DSSetConstantBuffers(0, 14, pBuffers);
	pd3dDeviceContext->GSSetConstantBuffers(0, 14, pBuffers);
	pd3dDeviceContext->PSSetConstantBuffers(0, 14, pBuffers);

	// Resources
	pd3dDeviceContext->VSSetShaderResources(0, 16, pSRVs);
	pd3dDeviceContext->HSSetShaderResources(0, 16, pSRVs);
	pd3dDeviceContext->DSSetShaderResources(0, 16, pSRVs);
	pd3dDeviceContext->GSSetShaderResources(0, 16, pSRVs);
	pd3dDeviceContext->PSSetShaderResources(0, 16, pSRVs);

	// Samplers
	pd3dDeviceContext->VSSetSamplers(0, 16, pSamplers);
	pd3dDeviceContext->HSSetSamplers(0, 16, pSamplers);
	pd3dDeviceContext->DSSetSamplers(0, 16, pSamplers);
	pd3dDeviceContext->GSSetSamplers(0, 16, pSamplers);
	pd3dDeviceContext->PSSetSamplers(0, 16, pSamplers);

	// Render targets
	pd3dDeviceContext->OMSetRenderTargets(8, pRTVs, pDSV);

	// States
	FLOAT blendFactor[4] = { 0,0,0,0 };
	pd3dDeviceContext->OMSetBlendState(NULL, blendFactor, 0xFFFFFFFF);
	pd3dDeviceContext->OMSetDepthStencilState(NULL, 0);
	pd3dDeviceContext->RSSetState(NULL);
}

HRESULT CompileShaderFromFile(const WCHAR* szFileName, LPCSTR szEntryPoint,	LPCSTR szShaderModel, ID3DBlob** ppBlobOut)
{
	HRESULT hr = S_OK;

	DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )	
	dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif

	ID3DBlob* pErrorBlob;
	hr = D3DX11CompileFromFile(szFileName, NULL, NULL, szEntryPoint, szShaderModel,	dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL);
	if (FAILED(hr)) {
		if (pErrorBlob != NULL) {
			OutputDebugStringA((char*)pErrorBlob->GetBufferPointer());
		}

		if (pErrorBlob) {
			pErrorBlob->Release();
		}

		return hr;
	}

	if (pErrorBlob) {
		pErrorBlob->Release();
	}

	return S_OK;
}

ID3D11DeviceChild* LoadSelectShaderFile(ShaderName Select, const void* pShaderFileData, ID3DBlob** ppBlobOut, char* pFuntionName) 
{
	ID3D11DeviceChild* pShader = nullptr;

	HRESULT hr = S_OK;
	ID3DBlob* pBlob = NULL;
	LPCVOID lpData = NULL;
	DWORD dwSize = 0;

	const char* pFName = pFuntionName;
	const char* pSLevel = 0;

	switch (Select) {
		case Vertex :
		{
			if (pFuntionName == 0) {
				pFName = "VS";
			}
			pSLevel = "vs_5_0";
		} break;

		case Pixel :
		{
			if (pFuntionName == 0) {
				pFName = "PS";
			}
			pSLevel = "ps_5_0";
		} break;

		case Geometry:
		{
			if (pFuntionName == 0) {
				pFName = "GS";
			}
			pSLevel = "gs_5_0";
		} break;

		case Hull:
		{
			if (pFuntionName == 0) {
				pFName = "HS";
			}
			pSLevel = "hs_5_0";
		} break;

		case Domain:
		{
			if (pFuntionName == 0) {
				pFName = "DS";
			}
			pSLevel = "ds_5_0";
		} break;

		case Computer:
		{
			if (pFuntionName == 0) {
				pFName = "CS";
			}
			pSLevel = "cs_5_0";
		} break;

	}

	if (*ppBlobOut == nullptr) {
			hr = CompileShaderFromFile((TCHAR*)pShaderFileData, pFName, pSLevel, &pBlob);
			if (FAILED(hr)) {
				return nullptr;
			}
	}
	else {
		pBlob = *ppBlobOut;

		if (pBlob == nullptr) {
			return nullptr;
		}
	}
	dwSize = (DWORD)pBlob->GetBufferSize();
	lpData = pBlob->GetBufferPointer();

	switch (Select) {
		case Vertex:
		{
			ID3D11VertexShader* pVertexShader = nullptr;
			hr = g_pD3dDevice->CreateVertexShader(lpData, dwSize, NULL, &pVertexShader);
			if (FAILED(hr)) {
				pBlob->Release();
				return nullptr;
			}
			pShader = pVertexShader;
		} break;

		case Pixel:
		{
			ID3D11PixelShader* pPixelShader = nullptr;
			hr = g_pD3dDevice->CreatePixelShader(lpData, dwSize, NULL, &pPixelShader);
			if (FAILED(hr)) {
				pBlob->Release();
				return nullptr;
			}
			pShader = pPixelShader;
		} break;

		case Geometry:
		{
			ID3D11GeometryShader* pGeometryShader = nullptr;
			hr = g_pD3dDevice->CreateGeometryShader(lpData, dwSize, NULL, &pGeometryShader);
			if (FAILED(hr)) {
				pBlob->Release();
				return nullptr;
			}
			pShader = pGeometryShader;
		} break;

		case Hull:
		{
			ID3D11HullShader* pHullShader = nullptr;
			hr = g_pD3dDevice->CreateHullShader(lpData, dwSize, NULL, &pHullShader);
			if (FAILED(hr)) {
				pBlob->Release();
				return nullptr;
			}
			pShader = pHullShader;
		} break;

		case Domain:
		{
			ID3D11DomainShader* pDomainShader = nullptr;
			hr = g_pD3dDevice->CreateDomainShader(lpData, dwSize, NULL, &pDomainShader);
			if (FAILED(hr))
			{
				pBlob->Release();
				return nullptr;
			}
			pShader = pDomainShader;
		} break;

		case Computer:
		{
			ID3D11ComputeShader* pComputeShader = nullptr;
			hr = g_pD3dDevice->CreateComputeShader(lpData, dwSize, NULL, &pComputeShader);
			if (FAILED(hr))
			{
				pBlob->Release();
				return nullptr;
			}
			pShader = pComputeShader;
		} break;

	}

	if (ppBlobOut == nullptr) {
		pBlob->Release();
	}
	else {
		*ppBlobOut = pBlob;
	}

	return pShader;
}


ID3D11InputLayout* CreateInputlayout(DWORD dwSize, LPCVOID lpData, D3D11_INPUT_ELEMENT_DESC* layout, UINT numElements)
{
	HRESULT hr = S_OK;
	
	ID3D11InputLayout* pInutLayout = nullptr;
	hr = g_pD3dDevice->CreateInputLayout(layout, numElements, lpData, dwSize, &pInutLayout);
	if (FAILED(hr)) {
		H(hr);
		return nullptr;
	}

	return pInutLayout;
}

ID3D11Buffer* CreateVertexBuffer(void *vertices, UINT iNumVertex, UINT iVertexSize, bool bDynamic)
{
	ID3D11Buffer* pBuffer = nullptr;
	
	HRESULT hr = S_OK;

	D3D11_BUFFER_DESC bd;
	ZeroMemory(&bd, sizeof(bd));
	if (bDynamic) {

		bd.Usage = D3D11_USAGE_DYNAMIC;
		bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	} 
	else {

		bd.Usage = D3D11_USAGE_DEFAULT;
		bd.CPUAccessFlags = 0;
	}
	bd.ByteWidth = iVertexSize * iNumVertex;
	bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;

	D3D11_SUBRESOURCE_DATA InitData;
	ZeroMemory(&InitData, sizeof(InitData));
	InitData.pSysMem = vertices;
	if (vertices != NULL) {

		hr = g_pD3dDevice->CreateBuffer(&bd, &InitData, &pBuffer);
		if (FAILED(hr)) {
			H(hr);
			return nullptr;
		}
	}
	else {

		g_pD3dDevice->CreateBuffer(&bd, NULL, &pBuffer);
		if (FAILED(hr)) {
			H(hr);
			return nullptr;
		}
	}
	return pBuffer;
}

ID3D11Buffer* CreateIndexBuffer(void *indices, UINT iNumIndex, UINT iSize, bool bDynamic)
{
	ID3D11Buffer* pBuffer = nullptr;

	HRESULT hr = S_OK;

	D3D11_BUFFER_DESC bd;
	ZeroMemory(&bd, sizeof(bd));
	if (bDynamic) {

		bd.Usage = D3D11_USAGE_DYNAMIC;
		bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	}
	else {

		bd.Usage = D3D11_USAGE_DEFAULT;
		bd.CPUAccessFlags = 0;
	}
	bd.ByteWidth = iSize * iNumIndex;
	bd.BindFlags = D3D11_BIND_INDEX_BUFFER;

	D3D11_SUBRESOURCE_DATA InitData;
	ZeroMemory(&InitData, sizeof(InitData));
	InitData.pSysMem = indices;
	if (indices != NULL)
	{
		hr = g_pD3dDevice->CreateBuffer(&bd, &InitData, &pBuffer);
		if (FAILED(hr)) {
			H(hr);
			return nullptr;
		}
	}
	else {
		hr = g_pD3dDevice->CreateBuffer(&bd, NULL, &pBuffer);
		if (FAILED(hr)) {
			H(hr);
			return nullptr;
		}
	}

	return pBuffer;
}

ID3D11Buffer* CreateConstantBuffer(void *data, UINT iNumIndex, UINT iSize, bool bDynamic)
{
	ID3D11Buffer* pBuffer = nullptr;

	HRESULT hr = S_OK;

	D3D11_BUFFER_DESC bd;
	ZeroMemory(&bd, sizeof(bd));
	if (bDynamic) {
		bd.Usage = D3D11_USAGE_DYNAMIC;
		bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	}
	else {
		bd.Usage = D3D11_USAGE_DEFAULT;
		bd.CPUAccessFlags = 0;
	}
	bd.ByteWidth = iSize * iNumIndex;
	bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;

	D3D11_SUBRESOURCE_DATA InitData;
	ZeroMemory(&InitData, sizeof(InitData));
	InitData.pSysMem = data;
	if (data != NULL) {
		hr = g_pD3dDevice->CreateBuffer(&bd, &InitData, &pBuffer);
		if (FAILED(hr)) {
			H(hr);
			return nullptr;
		}
	}
	else {
		hr = g_pD3dDevice->CreateBuffer(&bd, NULL, &pBuffer);
		if (FAILED(hr)) {
			H(hr);
			return nullptr;
		}
	}
	return pBuffer;
}

ID3D11ShaderResourceView*	CreateShaderResourceView(const TCHAR* strFilePath)
{
	ID3D11ShaderResourceView* pSRV = nullptr;
	
	HRESULT hr = S_OK;
	
	if (strFilePath == NULL) { 
		return nullptr; 
	}

	hr = D3DX11CreateShaderResourceViewFromFile(g_pD3dDevice, strFilePath, NULL, NULL, &pSRV, NULL);
	if (FAILED(hr)) {
		H(hr);
		return nullptr;
	}

	return pSRV;
}

ID3D11DepthStencilView* CreateDepthStencilView(DWORD dwWidth, DWORD dwHeight)
{
	ID3D11DepthStencilView* pDSV = nullptr;

	HRESULT hr;

	D3D11_TEXTURE2D_DESC DescDepth;
	DescDepth.Width = dwWidth;
	DescDepth.Height = dwHeight;
	DescDepth.MipLevels = 1;
	DescDepth.ArraySize = 1;
	DescDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
	DescDepth.SampleDesc.Count = 1;
	DescDepth.SampleDesc.Quality = 0;
	DescDepth.Usage = D3D11_USAGE_DEFAULT;
	DescDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
	DescDepth.CPUAccessFlags = 0;
	DescDepth.MiscFlags = 0;

	ComPtr<ID3D11Texture2D> pDSTexture = nullptr;
	hr = g_pD3dDevice->CreateTexture2D(&DescDepth, NULL, &pDSTexture);
	if (FAILED(hr)) {
		return nullptr;
	}

	D3D11_DEPTH_STENCIL_VIEW_DESC dsvd;
	ZeroMemory(&dsvd, sizeof(dsvd));
	dsvd.Format = DescDepth.Format;
	dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
	dsvd.Texture2D.MipSlice = 0;

	hr = g_pD3dDevice->CreateDepthStencilView(pDSTexture.Get(), &dsvd, &pDSV);
	if (FAILED(hr)) {
		return nullptr;
	}

	return pDSV;
}


//------------- 오브젝트 관련 전역 함수 세팅 끝 ------//

Object_DX::Object_DX()
{
}

//화면좌표계 -> 투영좌표게
void Object_DX::transStoP()
{
	m_fPRegion.left = (m_uSRegion.left / ((float)g_rtClient.right)) * 2 - 1.0f;
	m_fPRegion.top = -((m_uSRegion.top / ((float)g_rtClient.bottom)) * 2 - 1.0f);
	m_fPRegion.right = (m_uSRegion.right / ((float)g_rtClient.right)) * 2 - 1.0f;
	m_fPRegion.bottom = -((m_uSRegion.bottom / ((float)g_rtClient.bottom)) * 2 - 1.0f);
}

//투영좌표계 -> 화면좌표계
void Object_DX::transPtoS()
{
	m_uSRegion.left = (UINT)((m_fPRegion.left + 1.0f) / 2 * ((float)g_rtClient.right));
	m_uSRegion.top = (UINT)((m_fPRegion.top - 1.0f) / -2 * ((float)g_rtClient.bottom));
	m_uSRegion.right = (UINT)((m_fPRegion.right + 1.0f) / 2 * ((float)g_rtClient.right));
	m_uSRegion.bottom = (UINT)((m_fPRegion.bottom - 1.0f) / -2 * ((float)g_rtClient.bottom));
}

//중점 갱신
void Object_DX::UpdateCP()
{
	m_ptCenter.x = (m_uSRegion.right + m_uSRegion.left) / 2;
	m_ptCenter.y = (m_uSRegion.bottom + m_uSRegion.top) / 2;

	m_v3Center.x = 0.0f;
	m_v3Center.y = 0.0f;
	m_v3Center.z = 0.0f;

	for (int iV = 0; iV < 4; iV++) {
		m_v3Center.x += m_pVertexList[iV].p.x;
		m_v3Center.y += m_pVertexList[iV].p.y;
	}

	m_v3Center.x /= 4;
	m_v3Center.y /= 4;
}

//정점 리스트 갱신
void Object_DX::UpdateVertexList()
{
	m_pVertexList[0].p = D3DXVECTOR3(m_fPRegion.left, m_fPRegion.top, 0.0f);
	m_pVertexList[1].p = D3DXVECTOR3(m_fPRegion.left, m_fPRegion.bottom, 0.0f);
	m_pVertexList[2].p = D3DXVECTOR3(m_fPRegion.right, m_fPRegion.top, 0.0f);
	m_pVertexList[3].p = D3DXVECTOR3(m_fPRegion.right, m_fPRegion.bottom, 0.0f);


	for (int pl = 0; pl < 4; pl++) {
		m_pVertexList[pl].c = D3DXVECTOR4(1, 1, 1, 1);
	}

	//중점 갱신
	UpdateCP();
}



//생성 위치 지정하기
void Object_DX::SetPosition(iXYWH _xywh)
{
	//화면 좌표계 저장
	m_uSRegion = _xywh;

	//투영 좌표계 변환
	transStoP();

	//정점 리스트 저장
	UpdateVertexList();
}

//이미지 자르기
void Object_DX::ImagePartialSelect(iXYWH imgXYWH, uWH imgSize)
{
	m_uImagePart = imgXYWH;
	m_uImageSize = imgSize;

	fLTRB fImageUV;
	//이미지 화면 좌표를 uv좌표로 변환
	fImageUV.left = (float)m_uImagePart.left / m_uImageSize.width;
	fImageUV.top = (float)m_uImagePart.top / m_uImageSize.Height;
	fImageUV.right = (float)m_uImagePart.right / m_uImageSize.width;
	fImageUV.bottom = (float)m_uImagePart.bottom / m_uImageSize.Height;

	m_pVertexList[0].t = D3DXVECTOR2(fImageUV.left, fImageUV.top);
	m_pVertexList[1].t = D3DXVECTOR2(fImageUV.left, fImageUV.bottom);
	m_pVertexList[2].t = D3DXVECTOR2(fImageUV.right, fImageUV.top);
	m_pVertexList[3].t = D3DXVECTOR2(fImageUV.right, fImageUV.bottom);
}

//오브젝트 생성하기
HRESULT Object_DX::Create(const TCHAR* pTexFile)
{
	HRESULT hr;

	// 정점 버퍼 생성
	D3D11_BUFFER_DESC sDesc;
	ZeroMemory(&sDesc, sizeof(D3D11_BUFFER_DESC));
	sDesc.Usage = D3D11_USAGE_DEFAULT;
	sDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	sDesc.ByteWidth = sizeof(PNCT_VERTEX) * 4;

	D3D11_SUBRESOURCE_DATA sInitData;
	ZeroMemory(&sInitData, sizeof(D3D11_SUBRESOURCE_DATA));
	sInitData.pSysMem = m_pVertexList;

	if (FAILED(hr = g_pD3dDevice->CreateBuffer(&sDesc, &sInitData, &m_pVertexBuffer))) {
		return hr;
	}

	//정점 쉐이더 생성
	ID3DBlob*  pErrorBlob;
	ID3DBlob*  pVSBlob;
	

	hr = D3DX11CompileFromFile(L"Svertex.txt", NULL, NULL, "VS", "vs_5_0", NULL, NULL, NULL, &pVSBlob, &pErrorBlob, NULL);
	if (FAILED(hr)) {
		OutputDebugStringA((char*)pErrorBlob->GetBufferPointer());
		return false;
	}

	hr = g_pD3dDevice->CreateVertexShader(pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), NULL, m_pVS.GetAddressOf());
	if (FAILED(hr)) {
		return hr;
	}


	//기하 쉐이더 생성
	ID3DBlob* pGSBlob;
	hr = D3DX11CompileFromFile(L"Svertex.txt", NULL, NULL, "GS", "gs_5_0", NULL, NULL, NULL, &pGSBlob, &pErrorBlob, NULL);
	if (FAILED(hr)) {
		OutputDebugStringA((char*)pErrorBlob->GetBufferPointer());
		return false;
	}

	hr = g_pD3dDevice->CreateGeometryShader(pGSBlob->GetBufferPointer(), pGSBlob->GetBufferSize(), NULL, m_pGS.GetAddressOf());
	if (FAILED(hr)) {
		SAFE_RELEASE(pGSBlob);
		return NULL;
	}

	//레이아웃 생성
	if (pVSBlob == NULL) { return E_FAIL; }

	D3D11_INPUT_ELEMENT_DESC ied[] = {
		{ "POS", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NO", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 40, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	int iNumElement = sizeof(ied) / sizeof(D3D11_INPUT_ELEMENT_DESC);

	hr = g_pD3dDevice->CreateInputLayout(ied, iNumElement, pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), m_pInputLayout.GetAddressOf());
	if (FAILED(hr)) {
		return hr;
	}

	//픽셀 쉐이더 생성
	ID3DBlob*  pPSBlob;
	hr = D3DX11CompileFromFile(L"Svertex.txt", NULL, NULL, "PS", "ps_5_0", NULL, NULL, NULL, &pPSBlob, &pErrorBlob, NULL);
	if (FAILED(hr)) {
		OutputDebugStringA((char*)pErrorBlob->GetBufferPointer());
		return false;
	}

	hr = g_pD3dDevice->CreatePixelShader(pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), NULL, m_pPS.GetAddressOf());
	if (FAILED(hr)) {
		SAFE_RELEASE(pPSBlob);
		return NULL;
	}




	SAFE_RELEASE(pErrorBlob);
	SAFE_RELEASE(pVSBlob);
	SAFE_RELEASE(pPSBlob);
	SAFE_RELEASE(pGSBlob);


	//블렌드 스테이트 생성
	D3D11_BLEND_DESC BlendState;
	ZeroMemory(&BlendState, sizeof(D3D11_BLEND_DESC));

	BlendState.AlphaToCoverageEnable = FALSE;
	BlendState.IndependentBlendEnable = FALSE;

	BlendState.RenderTarget[0].BlendEnable = TRUE;

	BlendState.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;

	BlendState.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
	BlendState.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;

	BlendState.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
	BlendState.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
	BlendState.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;

	BlendState.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

	if (FAILED(hr = g_pD3dDevice->CreateBlendState(&BlendState, m_pAlphaBlend.GetAddressOf())))
	{
		return hr;
	}

	//samplerState 생성
	m_dxFilter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	m_iTexAddressMode = D3D11_TEXTURE_ADDRESS_CLAMP;
	

	D3D11_SAMPLER_DESC samplerDesc;
	samplerDesc.Filter = m_dxFilter;
	samplerDesc.AddressU = (D3D11_TEXTURE_ADDRESS_MODE)m_iTexAddressMode;
	samplerDesc.AddressV = (D3D11_TEXTURE_ADDRESS_MODE)m_iTexAddressMode;
	samplerDesc.AddressW = (D3D11_TEXTURE_ADDRESS_MODE)m_iTexAddressMode;
	samplerDesc.MipLODBias = 0.0f;
	samplerDesc.MaxAnisotropy = 16;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_EQUAL;
	samplerDesc.BorderColor[0] = 0.0f;
	samplerDesc.BorderColor[1] = 0.0f;
	samplerDesc.BorderColor[2] = 0.0f;
	samplerDesc.BorderColor[3] = 0.0f;
	samplerDesc.MinLOD = 0;
	samplerDesc.MaxLOD = 0;

	hr = g_pD3dDevice->CreateSamplerState(&samplerDesc, &m_pSamplerState);
	if (FAILED(hr)) {
		return hr;
	}

	//텍스쳐 로드
	hr = D3DX11CreateShaderResourceViewFromFile(g_pD3dDevice, pTexFile, NULL, NULL, m_pTextureSRV.GetAddressOf(), NULL);
	if (FAILED(hr)) {
		return hr;
	}

	return hr;
}

void Object_DX::ImageFileChange(const TCHAR* pTexFile)
{
	D3DX11CreateShaderResourceViewFromFile(g_pD3dDevice, pTexFile, NULL, NULL, m_pTextureSRV.GetAddressOf(), NULL);
}

//전체 이미지 오브젝트 생성
void Object_DX::CreateFullImgObj(iXYWH _xywh, const TCHAR* pTexFile) 
{
	SetPosition(_xywh);
	ImagePartialSelect({ 0,0,1,1 }, { 1,1 });
	Create(pTexFile);
}

//부분 이미지 오브젝트 생성
void Object_DX::CreatePartImgObj(iXYWH _xywh, iXYWH imgXYWH, uWH imgSize, const TCHAR* pTexFile)
{
	SetPosition(_xywh);
	ImagePartialSelect(imgXYWH, imgSize);
	Create(pTexFile);
}

//이미지 선택 영역 변경
void Object_DX::ImagePartialChange(iXYWH _uXYWH)
{
	ImagePartialSelect(_uXYWH, m_uImageSize);
}

iLTRB Object_DX::getPos()
{
	return m_uSRegion;
}

//x축 이동
void Object_DX::MoveX(float fDis)
{
	for (int iV = 0; iV < 4; iV++) {
		m_pVertexList[iV].p.x += fDis * g_dSPF;
	}

	m_fPRegion.left += fDis * g_dSPF;
	m_fPRegion.right += fDis * g_dSPF;

	transPtoS();

	UpdateCP();
}

//y축 이동
void Object_DX::MoveY(float fDis)
{
	for (int iV = 0; iV < 4; iV++) {
		m_pVertexList[iV].p.y += fDis * g_dSPF;
	}

	m_fPRegion.top += fDis * g_dSPF;
	m_fPRegion.bottom += fDis * g_dSPF;

	transPtoS();

	UpdateCP();
}

//회전
void Object_DX::spin(float fAngle)
{
	float S = sinf(fAngle);
	float C = cosf(fAngle);

	for (int iV = 0; iV < 4; iV++) {

		D3DXVECTOR3 vertex = m_pVertexList[iV].p;

		m_pVertexList[iV].p.x -= m_v3Center.x;
		m_pVertexList[iV].p.y -= m_v3Center.y;

		vertex.x = m_pVertexList[iV].p.x * C + m_pVertexList[iV].p.y * S / 2;
		vertex.y = m_pVertexList[iV].p.x * -S * 2 + m_pVertexList[iV].p.y * C;

		vertex.x += m_v3Center.x;
		vertex.y += m_v3Center.y;

		m_pVertexList[iV].p = vertex;

	}
}

//크기 조절
void Object_DX::scale(float size)
{//값 넣을 때 주의

	for (int iV = 0; iV < 4; iV++) {
		m_pVertexList[iV].p.x -= m_v3Center.x;
		m_pVertexList[iV].p.y -= m_v3Center.y;

		m_pVertexList[iV].p.x *= size;
		m_pVertexList[iV].p.y *= size;

		m_pVertexList[iV].p.x += m_v3Center.x;
		m_pVertexList[iV].p.y += m_v3Center.y;
	}
}

void Object_DX::ColorChange(float r, float g, float b, float a)
{
	for (int pl = 0; pl < 4; pl++) {
		m_pVertexList[pl].c = D3DXVECTOR4(r, g, b, a);
	}
}

void Object_DX::Color() {
	m_pVertexList[0].c = D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f);
	m_pVertexList[1].c = D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f);
	m_pVertexList[2].c = D3DXVECTOR4(0.0f, 0.0f, 1.0f, 1.0f);
	m_pVertexList[3].c = D3DXVECTOR4(1.0f, 0.0f, 1.0f, 1.0f);
}

bool Object_DX::Init()
{

	return true;
}

bool Object_DX::Frame()
{
	g_pD3dContext->UpdateSubresource(m_pVertexBuffer.Get(), 0, NULL, m_pVertexList, 0, 0);
	
	
	return true;
}

bool Object_DX::Render()
{
	UINT pStrides = sizeof(PNCT_VERTEX);
	UINT pOffsets = 0;

	ID3D11SamplerState* SS[1];
	SS[0] = m_pSamplerState;

	g_pD3dContext->IASetVertexBuffers(0, 1, m_pVertexBuffer.GetAddressOf(), &pStrides, &pOffsets);
	g_pD3dContext->IASetInputLayout(m_pInputLayout.Get());
	g_pD3dContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
	g_pD3dContext->VSSetConstantBuffers(0, 1, m_pConstantBuffer.GetAddressOf());
	g_pD3dContext->VSSetShader(m_pVS.Get(), NULL, NULL);
	g_pD3dContext->PSSetShader(m_pPS.Get(), NULL, NULL);
	g_pD3dContext->GSSetShader(m_pGS.Get(), NULL, NULL);
	g_pD3dContext->PSSetShaderResources(0, 1, m_pTextureSRV.GetAddressOf());
	g_pD3dContext->PSSetSamplers(0, 1, SS);
	g_pD3dContext->OMSetBlendState(m_pAlphaBlend.Get(), 0, -1);

	g_pD3dContext->Draw(4, 0);

	return true;
}

bool Object_DX::Release()
{

	return true;
}


Object_DX::~Object_DX()
{

}


smaple.h

#pragma once
#include "obj.h"
#include "timer.h"

struct VSCB
{
	float r, g, b, a;
	float x0, y0, z0, w0;
	float x1, y1, z1, w1;
	float x2, y2, z2, w2;
	float x3, y3, z3, w3;
	float time, y, z, w;
};

#define MAX_VERTEX 100


class sample
{
	timerC_DX m_Timer;

	Object_DX m_obj;
	VSCB      m_cbData;
	
public:
	bool Init();
	bool Frame();
	bool Render();
	bool Release();

public:
	sample();
	~sample();
};

sample.cpp

#include "sample.h"
#include <time.h>

sample::sample()
{

}

bool sample::Init()
{
	//m_obj.Create(L"Desert.jpg");

	m_Timer.Init();

	m_obj.m_pVS.Attach((ID3D11VertexShader*)LoadSelectShaderFile(Vertex, L"Svertex.txt", m_obj.m_pVSBlob.GetAddressOf()));
	m_obj.m_pPS.Attach((ID3D11PixelShader*)LoadSelectShaderFile(Pixel, L"Svertex.txt", m_obj.m_pPSBlob.GetAddressOf()));
	m_obj.m_pGS.Attach((ID3D11GeometryShader*)LoadSelectShaderFile(Geometry, L"Svertex.txt", m_obj.m_pGSBlob.GetAddressOf()));

	D3D11_INPUT_ELEMENT_DESC layout[] =
	{
		{ "POS", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NO", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 40, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	UINT numElements = sizeof(layout) / sizeof(layout[0]);
	m_obj.m_pInputLayout.Attach(CreateInputlayout(m_obj.m_pVSBlob.Get()->GetBufferSize(), m_obj.m_pVSBlob.Get()->GetBufferPointer(), layout, numElements));

	srand(time(NULL));
	
	PNCT_VERTEX vertices[MAX_VERTEX];
	for (int iVer = 0; iVer < MAX_VERTEX; iVer++) {
		vertices[iVer].p.x = randstep(-0.5f, 0.5f);
		vertices[iVer].p.y = randstep(-0.5f, 0.5f);
		vertices[iVer].p.z = 0.0f;

		vertices[iVer].n.x = 0.0f;
		vertices[iVer].n.y = 0.0f;
		vertices[iVer].n.z = 0.0f;

		vertices[iVer].c.x = randstep(0.0f, 1.0f);
		vertices[iVer].c.y = randstep(0.0f, 1.0f);
		vertices[iVer].c.z = randstep(0.0f, 1.0f);
		vertices[iVer].c.w = 1.0f;

		vertices[iVer].t.x = 0.0f;
		vertices[iVer].t.y = 0.0f;

	}

	int numVertices = sizeof(vertices) / sizeof(vertices[0]);
	m_obj.m_pVertexBuffer.Attach(CreateVertexBuffer(vertices, numVertices, sizeof(PNCT_VERTEX)));

	DWORD indices[] = { 0,1,2, 0,2,3, };
	int iNumIndex = sizeof(indices) / sizeof(indices[0]);
	m_obj.m_pIndexBuffer.Attach(CreateIndexBuffer(indices, iNumIndex, sizeof(DWORD)));

	m_cbData.x0 = randstep(0.0f, 1.0f);
	m_cbData.y0 = randstep(0.0f, 1.0f);
	m_cbData.z0 = randstep(0.0f, 1.0f);
	m_cbData.z0 = 1.0f;

	m_cbData.x1 = randstep(0.0f, 1.0f);
	m_cbData.y1 = randstep(0.0f, 1.0f);
	m_cbData.z1 = randstep(0.0f, 1.0f);
	m_cbData.z1 = 1.0f;

	m_cbData.x2 = randstep(0.0f, 1.0f);
	m_cbData.y2 = randstep(0.0f, 1.0f);
	m_cbData.z2 = randstep(0.0f, 1.0f);
	m_cbData.z2 = 1.0f;

	m_cbData.x3 = randstep(0.0f, 1.0f);
	m_cbData.y3 = randstep(0.0f, 1.0f);
	m_cbData.z3 = randstep(0.0f, 1.0f);
	m_cbData.z3 = 1.0f;

	m_cbData.time = 1.0f;

	//samplerState 생성

	D3D11_SAMPLER_DESC samplerDesc;
	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
	samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
	samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
	samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
	samplerDesc.MipLODBias = 0.0f;
	samplerDesc.MaxAnisotropy = 16;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_EQUAL;
	samplerDesc.BorderColor[0] = 0.0f;
	samplerDesc.BorderColor[1] = 0.0f;
	samplerDesc.BorderColor[2] = 0.0f;
	samplerDesc.BorderColor[3] = 0.0f;
	samplerDesc.MinLOD = 0;
	samplerDesc.MaxLOD = 0;

	g_pD3dDevice->CreateSamplerState(&samplerDesc, &m_obj.m_pSamplerState);
	
	m_obj.m_pConstantBuffer.Attach(CreateConstantBuffer(&m_cbData, 1, sizeof(VSCB)));

	m_obj.m_pTextureSRV.Attach(CreateShaderResourceView(L"Desert.jpg"));

	return true;
}

bool sample::Frame()
{
	m_Timer.Frame();

	static float ftime = 0.0f;
	static int iIndex = 0;
	ftime += g_dSPF;

	if (ftime > 1.0f)
	{
		m_cbData.x0 = randstep(0.0f, 1.0f);
		m_cbData.y0 = randstep(0.0f, 1.0f);
		m_cbData.z0 = randstep(0.0f, 1.0f);
		m_cbData.z0 = 1.0f;

		m_cbData.x1 = randstep(0.5f, 1.0f);
		m_cbData.y1 = randstep(0.5f, 1.0f);
		m_cbData.z1 = randstep(0.5f, 1.0f);
		m_cbData.z1 = 1.0f;

		m_cbData.x2 = randstep(0.0f, 0.5f);
		m_cbData.y2 = randstep(0.0f, 0.5f);
		m_cbData.z2 = randstep(0.0f, 0.5f);
		m_cbData.z2 = 1.0f;

		m_cbData.x3 = randstep(0.0f, 1.0f);
		m_cbData.y3 = randstep(0.0f, 1.0f);
		m_cbData.z3 = randstep(0.0f, 1.0f);
		m_cbData.z3 = 1.0f;
		ftime = 0.0f;
	}
	m_cbData.time = cosf(m_Timer.getGameTime())*0.5f + 0.5f;
	m_cbData.time *= 0.5f;

	return true;
}

bool sample::Render()
{
	m_Timer.Render();

	g_pD3dContext->UpdateSubresource(m_obj.m_pConstantBuffer.Get(), 0, NULL, &m_cbData, 0, 0);

	g_pD3dContext->IASetInputLayout(m_obj.m_pInputLayout.Get());

	UINT pStrides = sizeof(PNCT_VERTEX);
	UINT pOffsets = 0;

	g_pD3dContext->IASetVertexBuffers(0, 1, m_obj.m_pVertexBuffer.GetAddressOf(), &pStrides, &pOffsets);
	
	g_pD3dContext->VSSetConstantBuffers(0, 1, m_obj.m_pConstantBuffer.GetAddressOf());
	g_pD3dContext->VSSetShader(m_obj.m_pVS.Get(), NULL, NULL);
	g_pD3dContext->PSSetShader(m_obj.m_pPS.Get(), NULL, NULL);
	g_pD3dContext->GSSetShader(m_obj.m_pGS.Get(), NULL, NULL);
	g_pD3dContext->PSSetShaderResources(0, 1, m_obj.m_pTextureSRV.GetAddressOf());

	ID3D11SamplerState* SS[1];
	SS[0] = m_obj.m_pSamplerState;
	g_pD3dContext->PSSetSamplers(0, 1, SS);
	g_pD3dContext->OMSetBlendState(m_obj.m_pAlphaBlend.Get(), 0, -1);

	// 프리미티브는 정점파티클을 사용하기 때문에 고정되야 한다.
	g_pD3dContext->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_POINTLIST);
	g_pD3dContext->GSSetConstantBuffers(0, 1, m_obj.m_pConstantBuffer.GetAddressOf());

	// 1초 시간 간격으로 파티클의 개수(1 ~ MAX_VERTEX)를 조절한다.
	static float time = 0.0f;
	static int iIndex = 0;

	time += g_dSPF;
	if (time > 1.0f / MAX_VERTEX) {
		iIndex++;

		if (iIndex >= MAX_VERTEX) {
			iIndex = 1;
		}

		time -= 1.0f / MAX_VERTEX;
	}

	g_pD3dContext->Draw(MAX_VERTEX, 0);

	return true;
}

bool sample::Release()
{
	m_Timer.Release();

	m_obj.Release();

	return true;
}

sample::~sample()
{

}


Svertex.txt

//struct VS_INPUT
//{
//	float3 p : POS;
//	float3 n : NO;
//	float4 c : COLOR;
//	float2 t : TEXCOORD;
//};
//struct VS_OUTPUT
//{
//	float4 p : SV_POSITION;	 // 시멘틱(의미구조)
//	float3 n : NO0;
//	float4 c : COLOR0;
//	float2 t : TEXCOORD0;
//};
//
//struct G_OUT
//{
//	float4 p : SV_POSITION;
//	float4 c : COLOR0;
//	float2 t : TEXCOORD0;
//};
//
//VS_OUTPUT VS(VS_INPUT vIn)
//{
//	VS_OUTPUT vOut = (VS_OUTPUT)0;
//	vOut.p = float4(vIn.p.x, vIn.p.y, vIn.p.z, 1.0f);
//	vOut.n = vIn.n;
//	vOut.c = vIn.c;
//	vOut.t = vIn.t;
//	return vOut;
//}


cbuffer cb0
{
//상수버퍼이며 쉐이더 내에서 변수처럼 사용할 수 있다.
	float4 Color : packoffset(c0);
	float4 vColor[4]: packoffset(c1);
	float time : packoffset(c5.x);
};
struct V_in
{
	float4 p : POS;
	float3 n : NO;
	float4 c : COLOR;
	float2 t : TEXCOORD;
};

struct V_OUT
{
	float4 p : SV_POSITION;	 // 시멘틱(의미구조)
	float3 n : NO0;
	float4 c : COLOR0;
	float2 t : TEXCOORD0;
};

//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
// float4  정점을 반환해야 한다.
V_OUT VS(V_in vIn)
{
	V_OUT vOut; 
	vOut.p = vIn.p;
	vOut.n = vIn.n;
	vOut.c = vIn.c;
	vOut.t = vIn.t;
	return vOut;
}

struct G_OUT
{
	float4 p : SV_POSITION;
	float3 n : NO0;
	float4 c : COLOR0;
	float2 t : TEXCOORD0;
};
[maxvertexcount(4)]
void GS(in point V_OUT vIn[1], inout TriangleStream<G_OUT> vOut)
{
	// Strip으로 구성한다.
	const float3 g_positions[4] =
	{
		float3(-1.0,  1.0, 0.0),
		float3(1.0,  1.0, 0.0),
		float3(-1.0, -1.0, 0.0),
		float3(1.0, -1.0, 0.0),
	};
	float4 g_color[4] =
	{
		float4(1.0f, 1.0f, 1.0f, 1.0f),
		float4(1.0f, 1.0f, 1.0f, 1.0f),
		float4(1.0f, 1.0f, 1.0f, 1.0f),
		float4(1.0f, 1.0f, 1.0f, 1.0f),
	};
	const float2 g_texcoords[4] =
	{
		float2(0.0, 0.0),
		float2(1.0, 0.0),
		float2(0.0, 1.0),
		float2(1.0, 1.0),
	};

	G_OUT vVertex;
	for (int i = 0; i < 4; i++)
	{
		vVertex.p = float4(vIn[0].p.xyz + g_positions[i].xyz * time, 1.0f);
		vVertex.n = vIn[0].n;
		if(time <= 0.3f) {
			vVertex.c = vColor[i] * (time*5);
		} else {
			vVertex.c = g_color[i];
		}
		vVertex.t = g_texcoords[i];
		vOut.Append(vVertex);
	}
	vOut.RestartStrip();
}

// 텍스처 저장 레지스터(0번)
Texture2D g_txDiffuse : register(t0);
// 샘플러 저장 레지스터(0번)
SamplerState samLinear : register(s0);
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS(G_OUT vIn) : SV_Target
{
	float4 texColor = g_txDiffuse.Sample(samLinear, vIn.t);
	float4 FinalColor = texColor * vIn.c;
	return FinalColor;
}


반응형