목차

     

     


     

     

    Framework - CubeMap, CubeSky

     

     


    fx

     

    00_Global.fx

    더보기
    cbuffer CB_PerFrame
    {
        matrix View; 
        matrix ViewInverse;//View의 역행렬
        matrix Projection;
        matrix VP;
        
        float4 Culling[4];
        float4 Clipping;
        
        float Time; //게임시간
    };
    
    cbuffer CB_World
    {
        matrix World;
    };
    
    Texture2D DiffuseMap;
    Texture2D SpecularMap;
    Texture2D NormalMap;
    
    TextureCube SkyCubeMap;
    
    
    
    static const float PI = 3.14159265f;
    
    
    
    float4 WorldPosition(float4 position)
    {
        return mul(position, World);
    }
    
    float4 ViewProjection(float4 position)
    {
        return mul(position, VP);
    
        //position = mul(position, View);
        //return mul(position, Projection);
    }
    
    float3 WorldNormal(float3 normal)
    {
        return mul(normal, (float3x3) World);
    }
    
    float3 WorldTangent(float3 tangent)
    {
        return mul(tangent, (float3x3) World);
    }
    
    float3 ViewPosition()
    {
        return ViewInverse._41_42_43;
    }
    
    
    
    struct Vertex
    {
        float4 Position : Position;
    };
    
    struct VertexNormal
    {
        float4 Position : Position;
        float3 Normal : Normal;
    };
    
    struct VertexColor
    {
        float4 Position : Position;
        float4 Color : Color;
    };
    
    struct VertexColorNormal
    {
        float4 Position : Position;
        float4 Color : Color;
        float3 Normal : Normal;
    };
    
    struct VertexTexture
    {
        float4 Position : Position;
        float2 Uv : Uv;
    };
    
    struct VertexTextureNormal
    {
        float4 Position : Position;
        float2 Uv : Uv;
        float3 Normal : Normal;
    };
    
    
    
    
    SamplerState LinearSampler
    {
        Filter = MIN_MAG_MIP_LINEAR;
    
        AddressU = Wrap;
        AddressV = Wrap;
    };
    
    SamplerState PointSampler
    {
        Filter = MIN_MAG_MIP_POINT;
    
        AddressU = Wrap;
        AddressV = Wrap;
    };
    
    RasterizerState FrontCounterClockwise_True
    {
        FrontCounterClockwise = true;
    };
    
    RasterizerState FillMode_WireFrame
    {
        FillMode = WireFrame;
    };
    
    //RasterizerState CullMode_None
    //{
    //    CullMode = None;
    //};
    
    DepthStencilState DepthEnable_False
    {
        DepthEnable = false;
    };
    
    
    
    // Vertex / Pixel
    
    #define P_VP(name, vs, ps) \
    pass name \
    { \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_VP(name, rs, vs, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_BS_VP(name, bs, vs, ps) \
    pass name \
    { \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_DSS_VP(name, dss, vs, ps) \
    pass name \
    { \
        SetDepthStencilState(dss, 1); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_DSS_VP(name, rs, dss, vs, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetDepthStencilState(dss, 1); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_BS_VP(name, rs, bs, vs, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_DSS_BS_VP(name, dss, bs, vs, ps) \
    pass name \
    { \
        SetDepthStencilState(dss, 1); \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    ///////////////////////////////////////////////////////////////////////////////
    // Vertex / Geometry / Pixel
    ///////////////////////////////////////////////////////////////////////////////
    #define P_VGP(name, vs, gs, ps) \
    pass name \
    { \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetGeometryShader(CompileShader(gs_5_0, gs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_VGP(name, rs, vs, gs, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetGeometryShader(CompileShader(gs_5_0, gs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_BS_VGP(name, bs, vs, gs, ps) \
    pass name \
    { \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetGeometryShader(CompileShader(gs_5_0, gs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_DSS_VGP(name, dss, vs, gs, ps) \
    pass name \
    { \
        SetDepthStencilState(dss, 1); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetGeometryShader(CompileShader(gs_5_0, gs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_DSS_VGP(name, rs, dss, vs, gs, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetDepthStencilState(dss, 1); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetGeometryShader(CompileShader(gs_5_0, gs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_BS_VGP(name, rs, bs, vs, gs, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetGeometryShader(CompileShader(gs_5_0, gs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_DSS_BS_VGP(name, dss, bs, vs, gs, ps) \
    pass name \
    { \
        SetDepthStencilState(dss, 1); \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetGeometryShader(CompileShader(gs_5_0, gs())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////
    // Vertex / Tessellation / Pixel
    ///////////////////////////////////////////////////////////////////////////////
    #define P_VTP(name, vs, hs, ds, ps) \
    pass name \
    { \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetHullShader(CompileShader(hs_5_0, hs())); \
        SetDomainShader(CompileShader(ds_5_0, ds())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_VTP(name, rs, vs, hs, ds, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetHullShader(CompileShader(hs_5_0, hs())); \
        SetDomainShader(CompileShader(ds_5_0, ds())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_BS_VTP(name, bs, vs, hs, ds, ps) \
    pass name \
    { \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetHullShader(CompileShader(hs_5_0, hs())); \
        SetDomainShader(CompileShader(ds_5_0, ds())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_DSS_VTP(name, dss, vs, hs, ds, ps) \
    pass name \
    { \
        SetDepthStencilState(dss, 1); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetHullShader(CompileShader(hs_5_0, hs())); \
        SetDomainShader(CompileShader(ds_5_0, ds())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_DSS_VTP(name, rs, dss, vs, hs, ds, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetDepthStencilState(dss, 1); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetHullShader(CompileShader(hs_5_0, hs())); \
        SetDomainShader(CompileShader(ds_5_0, ds())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_BS_VTP(name, rs, bs, vs, hs, ds, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetHullShader(CompileShader(hs_5_0, hs())); \
        SetDomainShader(CompileShader(ds_5_0, ds())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_DSS_BS_VTP(name, dss, bs, vs, hs, ds, ps) \
    pass name \
    { \
        SetDepthStencilState(dss, 1); \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetHullShader(CompileShader(hs_5_0, hs())); \
        SetDomainShader(CompileShader(ds_5_0, ds())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }
    
    #define P_RS_DSS_BS_VTP(name, rs, dss, bs, vs, hs, ds, ps) \
    pass name \
    { \
        SetRasterizerState(rs); \
        SetDepthStencilState(dss, 1); \
        SetBlendState(bs, float4(0, 0, 0, 0), 0xFF); \
        SetVertexShader(CompileShader(vs_5_0, vs())); \
        SetHullShader(CompileShader(hs_5_0, hs())); \
        SetDomainShader(CompileShader(ds_5_0, ds())); \
        SetPixelShader(CompileShader(ps_5_0, ps())); \
    }

     

     

    25_Mesh.fx

    더보기
    #include "00_Global.fx"
    
    float3 Direction;
    
    struct VertexOutput
    {
        float4 Position : SV_Position;
        float2 Uv : Uv;
        float3 Normal : Normal;
    };
    
    VertexOutput VS(VertexTextureNormal input)
    {
        VertexOutput output;
        output.Position = WorldPosition(input.Position);
        output.Position = ViewProjection(output.Position);
        
        output.Normal = WorldNormal(input.Normal);
    
        output.Uv = input.Uv;
    
        return output;
    }
    
    float4 PS(VertexOutput input) : SV_Target
    {
        float3 normal = normalize(input.Normal);
        float3 light = -Direction;
    
        return DiffuseMap.Sample(LinearSampler, input.Uv) * dot(light, normal);
    }
    
    technique11 T0
    {
        P_VP(P0, VS, PS)
        P_RS_VP(P1, FillMode_WireFrame, VS, PS)
        
    }

     

     

    29_CubeMap.fx

    더보기
    #include "00_Global.fx"
    
    TextureCube CubeMap;
    
    struct VertexOutput
    {
        float4 Position : SV_Position;
        float3 oPosition : Position1;
        float3 Normal : Normal;
    };
    
    VertexOutput VS(VertexTextureNormal input)
    {
        VertexOutput output;
    
        output.oPosition = input.Position.xyz;
    
        input.Position.x += cos(Time) * 3.0f;
        output.Position = WorldPosition(input.Position);
        output.Position = ViewProjection(output.Position);
        output.Normal = WorldNormal(input.Normal);
    
        return output;
    }
    
    float4 PS(VertexOutput input) : SV_Target
    {
        float4 color = float4(sin(Time * 3), 1, 1, 1); //구 색 변화
    
        return CubeMap.Sample(LinearSampler, input.oPosition) * color; //*color로 적용
    }
    
    technique11 T0
    {
        P_VP(P0, VS, PS)
        P_RS_VP(P1, FillMode_WireFrame, VS, PS)
    }

     

     

    29_CubeSky.fx

    더보기
    #include "00_Global.fx"
    
    struct VertexOutput
    {
        float4 Position : SV_Position;
        float3 oPosition : Position1;
    };
    
    VertexOutput VS(Vertex input)
    {
        VertexOutput output;
    
        output.oPosition = input.Position.xyz;
    
        output.Position = WorldPosition(input.Position);
        output.Position = ViewProjection(output.Position);
    
        return output;
    }
    
    Texture2D t;
    float4 PS(VertexOutput input) : SV_Target
    {
        return SkyCubeMap.Sample(LinearSampler, input.oPosition);
    
    }
    
    technique11 T0
    {
        P_RS_DSS_VP(P0, FrontCounterClockwise_True, DepthEnable_False, VS, PS)
    }

     


     

    Renderer

     

    Renderer.h

    더보기
    #pragma once
    
    class Renderer
    {
    public:
    	Renderer(Shader* shader);
    	Renderer(wstring shaderFile);
    	virtual ~Renderer();
    
    	Shader* GetShader() { return shader; }
    
    	UINT& Pass() { return pass; }
    	void Pass(UINT val) { pass = val; }
    
    	virtual void Update();
    	virtual void Render();
    
    	Transform* GetTransform() { return transform; }
    
    private:
    	void Initialize();
    
    protected:
    	void Topology(D3D11_PRIMITIVE_TOPOLOGY val) { topology = val; }
    
    protected:
    	Shader* shader;
    
    	Transform* transform;
    	VertexBuffer* vertexBuffer = NULL;
    	IndexBuffer* indexBuffer = NULL;
    
    	UINT vertexCount = 0;
    	UINT indexCount = 0;
    
    private:
    	bool bCreateShader = false;
    
    	D3D11_PRIMITIVE_TOPOLOGY topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
    	UINT pass = 0;
    
    	PerFrame* perFrame;
    };

     

     

    Renderer.cpp

    더보기
    #include "Framework.h"
    #include "Renderer.h"
    
    Renderer::Renderer(Shader * shader)
    	: shader(shader)
    {
    	Initialize();
    }
    
    Renderer::Renderer(wstring shaderFile)
    	: bCreateShader(true)
    {
    	shader = new Shader(shaderFile);
    
    	Initialize();
    }
    
    void Renderer::Initialize()
    {
    	perFrame = new PerFrame(shader);
    	transform = new Transform(shader);
    }
    
    Renderer::~Renderer()
    {
    	SafeDelete(perFrame);
    	SafeDelete(transform);
    
    	SafeDelete(vertexBuffer);
    	SafeDelete(indexBuffer);
    
    	if (bCreateShader == true)
    		SafeDelete(shader);
    }
    
    void Renderer::Update()
    {
    	perFrame->Update();
    	transform->Update();
    }
    
    void Renderer::Render()
    {
    	if (vertexBuffer != NULL)
    	{
    		vertexBuffer->Render();
    
    		if (indexBuffer != NULL)
    			indexBuffer->Render();
    	}
    
    	D3D::GetDC()->IASetPrimitiveTopology(topology);
    
    	perFrame->Render();
    	transform->Render();
    }

     

     

     


     

    Transform

     

    Transform.h

    더보기
    #pragma once
    
    class Transform
    {
    public:
    	Transform();
    	Transform(Shader* shader);
    	~Transform();
    
    	void Set(Transform* transform);
    
    	void SetShader(Shader* shader);
    
    	void Position(float x, float y, float z);
    	void Position(Vector3& vec);
    	void Position(Vector3* vec);
    
    	void Scale(float x, float y, float z);
    	void Scale(Vector3& vec);
    	void Scale(Vector3* vec);
    
    	void Rotation(float x, float y, float z);
    	void Rotation(Vector3& vec);
    	void Rotation(Vector3* vec);
    
    	void RotationDegree(float x, float y, float z);
    	void RotationDegree(Vector3& vec);
    	void RotationDegree(Vector3* vec);
    
    	Vector3 Forward();
    	Vector3 Up();
    	Vector3 Right();
    
    	void World(Matrix& matrix);
    	Matrix& World() { return bufferDesc.World; }
    
    private:
    	void UpdateWorld();
    
    public:
    	void Update();
    	void Render();
    
    private:
    	struct BufferDesc
    	{
    		Matrix World;
    	} bufferDesc;
    
    private:
    	Shader* shader;
    
    	ConstantBuffer* buffer;
    	ID3DX11EffectConstantBuffer* sBuffer;
    
    
    	Vector3 position;
    	Vector3 scale;
    	Vector3 rotation;
    };

     

     

    Transform.cpp

    더보기
    #include "Framework.h"
    #include "Transform.h"
    
    Transform::Transform()
    	: shader(NULL), buffer(NULL)
    	, position(0, 0, 0), scale(1, 1, 1), rotation(0, 0, 0)
    {
    	D3DXMatrixIdentity(&bufferDesc.World);
    }
    
    Transform::Transform(Shader * shader)
    	: position(0, 0, 0), scale(1, 1, 1), rotation(0, 0, 0)
    {
    	SetShader(shader);
    
    	D3DXMatrixIdentity(&bufferDesc.World);
    }
    
    Transform::~Transform()
    {
    	SafeDelete(buffer);
    }
    
    void Transform::Set(Transform * transform)
    {
    	position = transform->position;
    	scale = transform->scale;
    	rotation = transform->rotation;
    
    	UpdateWorld();
    }
    
    void Transform::SetShader(Shader* shader)
    {
    	this->shader = shader;
    
    	buffer = new ConstantBuffer(&bufferDesc, sizeof(BufferDesc));
    	sBuffer = shader->AsConstantBuffer("CB_World");
    }
    
    void Transform::Position(float x, float y, float z)
    {
    	Position(Vector3(x, y, z));
    }
    
    void Transform::Position(Vector3 & vec)
    {
    	position = vec;
    
    	UpdateWorld();
    }
    
    void Transform::Position(Vector3 * vec)
    {
    	*vec = position;
    }
    
    void Transform::Scale(float x, float y, float z)
    {
    	Scale(Vector3(x, y, z));
    }
    
    void Transform::Scale(Vector3 & vec)
    {
    	scale = vec;
    
    	UpdateWorld();
    }
    
    void Transform::Scale(Vector3 * vec)
    {
    	*vec = scale;
    }
    
    void Transform::Rotation(float x, float y, float z)
    {
    	Rotation(Vector3(x, y, z));
    }
    
    void Transform::Rotation(Vector3 & vec)
    {
    	rotation = vec;
    
    	UpdateWorld();
    }
    
    void Transform::Rotation(Vector3 * vec)
    {
    	*vec = rotation;
    }
    
    void Transform::RotationDegree(float x, float y, float z)
    {
    	RotationDegree(Vector3(x, y, z));
    }
    
    void Transform::RotationDegree(Vector3 & vec)
    {
    	Vector3 temp;
    
    	temp.x = Math::ToRadian(vec.x);
    	temp.y = Math::ToRadian(vec.y);
    	temp.z = Math::ToRadian(vec.z);
    
    	Rotation(temp);
    }
    
    void Transform::RotationDegree(Vector3 * vec)
    {
    	Vector3 temp;
    
    	temp.x = Math::ToDegree(rotation.x);
    	temp.y = Math::ToDegree(rotation.y);
    	temp.z = Math::ToDegree(rotation.z);
    
    	*vec = temp;
    }
    
    Vector3 Transform::Forward()
    {	//z방향
    	return Vector3(bufferDesc.World._31, bufferDesc.World._32, bufferDesc.World._33);
    }
    
    Vector3 Transform::Up()
    {	//y방향
    	return Vector3(bufferDesc.World._21, bufferDesc.World._22, bufferDesc.World._23);
    }
    
    Vector3 Transform::Right()
    {	//x방향
    	return Vector3(bufferDesc.World._11, bufferDesc.World._12, bufferDesc.World._13);
    }
    
    void Transform::World(Matrix & matrix)
    {
    	Math::MatrixDecompose(matrix, scale, rotation, position); //엘리오트 컴포싯
    
    	bufferDesc.World = matrix;
    }
    
    void Transform::UpdateWorld()
    {
    	Matrix S, R, T;
    	D3DXMatrixScaling(&S, scale.x, scale.y, scale.z);
    	D3DXMatrixRotationYawPitchRoll(&R, rotation.y, rotation.x, rotation.z);
    	D3DXMatrixTranslation(&T, position.x, position.y, position.z);
    
    	Matrix world = S * R * T;
    	bufferDesc.World = world;
    }
    
    void Transform::Update()
    {
    
    }
    
    void Transform::Render()
    {
    	if (shader == NULL)
    		return;
    
    	buffer->Render();
    	sBuffer->SetConstantBuffer(buffer->Buffer());
    }

     

     

     


     

    Mesh

     

    Mesh.h

    더보기
    #pragma once
    
    class Mesh : public Renderer
    {
    public:
    	typedef VertexTextureNormal MeshVertex;
    
    public:
    	Mesh(Shader* shader);
    	virtual ~Mesh();
    
    	void Update();
    	void Render();
    
    public:
    	void DiffuseMap(wstring file);
    
    protected:
    	virtual void Create() = 0;
    
    protected:
    	MeshVertex* vertices = NULL;
    	UINT* indices = NULL;
    
    private:
    	Texture* diffuseMap = NULL;
    	ID3DX11EffectShaderResourceVariable* sDiffuseMap;
    };

     

     

    Mesh.cpp

    더보기
    #include "Framework.h"
    #include "Mesh.h"
    
    Mesh::Mesh(Shader * shader)
    	: Renderer(shader)
    {
    	sDiffuseMap = shader->AsSRV("DiffuseMap");
    }
    
    Mesh::~Mesh()
    {
    	SafeDeleteArray(vertices);
    	SafeDeleteArray(indices);
    
    	SafeDelete(diffuseMap);
    }
    
    void Mesh::Update()
    {
    	Super::Update();//Super는 부모를 의미하는 키워드
    }
    
    void Mesh::Render()
    {
    	if (vertexBuffer == NULL && indexBuffer == NULL)
    	{
    		Create();
    
    		vertexBuffer = new VertexBuffer(vertices, vertexCount, sizeof(MeshVertex));
    		indexBuffer = new IndexBuffer(indices, indexCount);
    	}
    
    	Super::Render();
    	
    	if(diffuseMap != NULL)
    		sDiffuseMap->SetResource(diffuseMap->SRV());
    
    	shader->DrawIndexed(0, Pass(), indexCount);
    }
    
    void Mesh::DiffuseMap(wstring file)
    {
    	SafeDelete(diffuseMap);
    
    	diffuseMap = new Texture(file);
    }

     


     

     

     

    CubeSky

     

    CubeSky.h

    더보기
    #pragma once
    
    class CubeSky
    {
    public:
    	CubeSky(wstring file);
    	~CubeSky();
    
    	void Update();
    	void Render();
    
    private:
    	Shader* shader;
    	MeshSphere* sphere;
    
    	ID3D11ShaderResourceView* srv;
    	ID3DX11EffectShaderResourceVariable* sSrv;
    };

     

     

    CubeSky.cpp

    더보기
    #include "Framework.h"
    #include "CubeSky.h"
    
    CubeSky::CubeSky(wstring file)
    {
    	shader = new Shader(L"29_CubeSky.fx");
    
    	sphere = new MeshSphere(shader, 0.5f);
    
    	file = L"../../_Textures/" + file;
    	Check(D3DX11CreateShaderResourceViewFromFile
    	(
    		D3D::GetDevice(), file.c_str(), NULL, NULL, &srv, NULL
    	));
    
    	sSrv = shader->AsSRV("SkyCubeMap");
    }
    
    CubeSky::~CubeSky()
    {
    	SafeDelete(shader);
    	SafeDelete(sphere);
    
    	SafeRelease(srv);
    }
    
    void CubeSky::Update()
    {
    	Vector3 position;
    	Context::Get()->GetCamera()->Position(&position);
    
    	sphere->GetTransform()->Position(position);
    }
    
    void CubeSky::Render()
    {
    	sSrv->SetResource(srv);
    	sphere->Render();
    }

     


     

     

     

     

    CubeMap

     

    CubeMap.h

    더보기
    #pragma once
    #include "Systems/IExecute.h"
    
    class CubeSkyDemo : public IExecute
    {
    public:
    	virtual void Initialize() override;
    	virtual void Ready() override {}
    	virtual void Destroy() override;
    	virtual void Update() override;
    	virtual void PreRender() override {}
    	virtual void Render() override;
    	virtual void PostRender() override {}
    	virtual void ResizeScreen() override {}
    
    private:
    	void CreateMesh();
    
    private:
    	Shader* shader;
    
    	Vector3 direction = Vector3(-1, -1, 1);
    	ID3DX11EffectVectorVariable* sDirection;
    
    	CubeSky* sky;
    
    	MeshCube* cube;
    	MeshCylinder* cylinder[10];
    	MeshSphere* sphere[10];
    	MeshGrid* grid;
    
    	Shader* cubeMapShader;
    	CubeMap* cubeMap;
    };

     

     

    CubeMap.cpp

    더보기
    #include "Framework.h"
    #include "CubeMap.h"
    
    CubeMap::CubeMap(Shader * shader)
    	: shader(shader)
    {
    	//mesh = new MeshCube(shader);
    	mesh = new MeshSphere(shader, 0.5f);
    
    	sSrv = shader->AsSRV("CubeMap");
    }
    
    CubeMap::~CubeMap()
    {
    	SafeDelete(mesh);
    
    	SafeRelease(srv);
    }
    
    void CubeMap::Texture(wstring file)
    {
    	SafeRelease(srv);
    
    	file = L"../../_Textures/" + file;
    	Check(D3DX11CreateShaderResourceViewFromFile
    	(
    		D3D::GetDevice(), file.c_str(), NULL, NULL, &srv, NULL
    	));
    }
    
    void CubeMap::Update()
    {
    	mesh->Update();
    }
    
    void CubeMap::Render()
    {
    	sSrv->SetResource(srv);
    
    	mesh->Render();
    }

     


     

     

     

    CubeSkyDemo

     

    CubeSkyDemo.h

    더보기
    #pragma once
    #include "Systems/IExecute.h"
    
    class CubeSkyDemo : public IExecute
    {
    public:
    	virtual void Initialize() override;
    	virtual void Ready() override {}
    	virtual void Destroy() override;
    	virtual void Update() override;
    	virtual void PreRender() override {}
    	virtual void Render() override;
    	virtual void PostRender() override {}
    	virtual void ResizeScreen() override {}
    
    private:
    	void CreateMesh();
    
    private:
    	Shader* shader;
    
    	Vector3 direction = Vector3(-1, -1, 1);
    	ID3DX11EffectVectorVariable* sDirection;
    
    	CubeSky* sky;
    
    	MeshCube* cube;
    	MeshCylinder* cylinder[10];
    	MeshSphere* sphere[10];
    	MeshGrid* grid;
    
    	Shader* cubeMapShader;
    	CubeMap* cubeMap;
    };

     

     

    CubeSkyDemo.cpp

    더보기
    #include "stdafx.h"
    #include "CubeSkyDemo.h"
    
    void CubeSkyDemo::Initialize()
    {
    	Context::Get()->GetCamera()->RotationDegree(20, 0, 0);
    	Context::Get()->GetCamera()->Position(1, 36, -85);
    
    
    	shader = new Shader(L"25_Mesh.fx");
    	sDirection = shader->AsVector("Direction");
    
    	sky = new CubeSky(L"Environment/GrassCube1024.dds");
    	
    	CreateMesh();
    
    	cubeMapShader = new Shader(L"29_CubeMap.fx");
    	cubeMap = new CubeMap(cubeMapShader);
    	//cubeMap->Texture(L"Environment/SunsetCube1024.dds");
    	cubeMap->Texture(L"Environment/Earth.dds");
    	cubeMap->GetTransform()->Position(0, 20, 0);
    	cubeMap->GetTransform()->Scale(10, 10, 10);
    }
    
    void CubeSkyDemo::Destroy()
    {
    	SafeDelete(shader);
    	SafeDelete(sky);
    	
    	SafeDelete(cube);
    	SafeDelete(grid);
    
    	for (int i = 0; i < 10; i++)
    	{
    		SafeDelete(cylinder[i]);
    		SafeDelete(sphere[i]);
    	}
    
    	SafeDelete(cubeMapShader);
    	SafeDelete(cubeMap);
    }
    
    void CubeSkyDemo::Update()
    {
    	sky->Update();
    
    	cube->Update();
    	grid->Update();
    
    	for (int i = 0; i < 10; i++)
    	{
    		cylinder[i]->Update();
    		sphere[i]->Update();
    	}
    
    	cubeMap->Update();
    }
    
    void CubeSkyDemo::Render()
    {
    	ImGui::SliderFloat3("Direction", direction, -1, +1);
    	sDirection->SetFloatVector(direction);
    
    	sky->Render();
    
    	cube->Render();
    	grid->Render();
    
    	for (int i = 0; i < 10; i++)
    	{
    		cylinder[i]->Render();
    		sphere[i]->Render();
    	}
    
    	cubeMap->Render();
    }
    
    void CubeSkyDemo::CreateMesh()
    {
    	cube = new MeshCube(shader);
    	cube->GetTransform()->Position(0, 5, 0);
    	cube->GetTransform()->Scale(20, 10, 20);
    	cube->DiffuseMap(L"Stones.png");
    
    	grid = new MeshGrid(shader, 6, 6);
    	grid->GetTransform()->Scale(12, 1, 12);
    	grid->DiffuseMap(L"Floor.png");
    
    
    	for (UINT i = 0; i < 5; i++)
    	{
    		cylinder[i * 2] = new MeshCylinder(shader, 0.5f, 3.0f, 20, 20);
    		cylinder[i * 2]->GetTransform()->Position(-30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2]->GetTransform()->Scale(5, 5, 5);
    		cylinder[i * 2]->DiffuseMap(L"Bricks.png");
    
    		cylinder[i * 2 + 1] = new MeshCylinder(shader, 0.5f, 3.0f, 20, 20);
    		cylinder[i * 2 + 1]->GetTransform()->Position(30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2 + 1]->GetTransform()->Scale(5, 5, 5);
    		cylinder[i * 2 + 1]->DiffuseMap(L"Bricks.png");
    
    
    		sphere[i * 2] = new MeshSphere(shader, 0.5f, 20, 20);
    		sphere[i * 2]->GetTransform()->Position(-30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2]->GetTransform()->Scale(5, 5, 5);
    		sphere[i * 2]->DiffuseMap(L"Wall.png");
    
    		sphere[i * 2 + 1] = new MeshSphere(shader, 0.5f, 20, 20);
    		sphere[i * 2 + 1]->GetTransform()->Position(30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2 + 1]->GetTransform()->Scale(5, 5, 5);
    		sphere[i * 2 + 1]->DiffuseMap(L"Wall.png");
    	}
    }

     


     

     

    CubeMapDemo

     

    CubeMapDemo.h

    더보기
    #pragma once
    #include "Systems/IExecute.h"
    
    class CubeMapDemo : public IExecute
    {
    public:
    	virtual void Initialize() override;
    	virtual void Ready() override {}
    	virtual void Destroy() override;
    	virtual void Update() override;
    	virtual void PreRender() override {}
    	virtual void Render() override;
    	virtual void PostRender() override {}
    	virtual void ResizeScreen() override {}
    
    private:
    	void CreateMesh();
    
    private:
    	Shader* shader;
    
    	Vector3 direction = Vector3(-1, -1, 1);
    	ID3DX11EffectVectorVariable* sDirection;
    
    	MeshCube* cube;
    	MeshCylinder* cylinder[10];
    	MeshSphere* sphere[10];
    	MeshGrid* grid;
    
    	Shader* cubeMapShader;
    	CubeMap* cubeMap;
    };

     

     

    CubeMapDemo.cpp

    더보기
    #include "stdafx.h"
    #include "CubeMapDemo.h"
    
    void CubeMapDemo::Initialize()
    {
    	Context::Get()->GetCamera()->RotationDegree(20, 0, 0);
    	Context::Get()->GetCamera()->Position(1, 36, -85);
    
    
    	shader = new Shader(L"25_Mesh.fx");
    	sDirection = shader->AsVector("Direction");
    	
    	CreateMesh();
    
    	cubeMapShader = new Shader(L"29_CubeMap.fx");
    	cubeMap = new CubeMap(cubeMapShader);
    	//cubeMap->Texture(L"Environment/SunsetCube1024.dds");
    	cubeMap->Texture(L"Environment/Earth.dds");
    	cubeMap->GetTransform()->Position(0, 20, 0);
    	cubeMap->GetTransform()->Scale(10, 10, 10);
    }
    
    void CubeMapDemo::Destroy()
    {
    	SafeDelete(shader);
    	
    	SafeDelete(cube);
    	SafeDelete(grid);
    
    	for (int i = 0; i < 10; i++)
    	{
    		SafeDelete(cylinder[i]);
    		SafeDelete(sphere[i]);
    	}
    
    	SafeDelete(cubeMapShader);
    	SafeDelete(cubeMap);
    }
    
    void CubeMapDemo::Update()
    {
    	cube->Update();
    	grid->Update();
    
    	for (int i = 0; i < 10; i++)
    	{
    		cylinder[i]->Update();
    		sphere[i]->Update();
    	}
    
    	cubeMap->Update();
    }
    
    void CubeMapDemo::Render()
    {
    	ImGui::SliderFloat3("Direction", direction, -1, +1);
    	sDirection->SetFloatVector(direction);
    
    	static int pass = 0;
    	ImGui::InputInt("Pass", &pass);
    	pass %= 2;
    
    
    	cube->Render();
    	grid->Render();
    
    	for (int i = 0; i < 10; i++)
    	{
    		cylinder[i]->Pass(pass);
    		cylinder[i]->Render();
    
    		sphere[i]->Pass(pass);
    		sphere[i]->Render();
    	}
    
    	cubeMap->Render();
    }
    
    void CubeMapDemo::CreateMesh()
    {	//CubeSkyDemo부분과 동일
    	cube = new MeshCube(shader);
    	cube->GetTransform()->Position(0, 5, 0);
    	cube->GetTransform()->Scale(20, 10, 20);
    	cube->DiffuseMap(L"Stones.png");
    
    	grid = new MeshGrid(shader, 6, 6);
    	grid->GetTransform()->Scale(12, 1, 12);
    	grid->DiffuseMap(L"Floor.png");
    
    
    	for (UINT i = 0; i < 5; i++)
    	{
    		cylinder[i * 2] = new MeshCylinder(shader, 0.5f, 3.0f, 20, 20);
    		cylinder[i * 2]->GetTransform()->Position(-30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2]->GetTransform()->Scale(5, 5, 5);
    		cylinder[i * 2]->DiffuseMap(L"Bricks.png");
    
    		cylinder[i * 2 + 1] = new MeshCylinder(shader, 0.5f, 3.0f, 20, 20);
    		cylinder[i * 2 + 1]->GetTransform()->Position(30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2 + 1]->GetTransform()->Scale(5, 5, 5);
    		cylinder[i * 2 + 1]->DiffuseMap(L"Bricks.png");
    
    
    		sphere[i * 2] = new MeshSphere(shader, 0.5f, 20, 20);
    		sphere[i * 2]->GetTransform()->Position(-30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2]->GetTransform()->Scale(5, 5, 5);
    		sphere[i * 2]->DiffuseMap(L"Wall.png");
    
    		sphere[i * 2 + 1] = new MeshSphere(shader, 0.5f, 20, 20);
    		sphere[i * 2 + 1]->GetTransform()->Position(30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2 + 1]->GetTransform()->Scale(5, 5, 5);
    		sphere[i * 2 + 1]->DiffuseMap(L"Wall.png");
    	}
    }

     


     

     

     

     

     

     

    MeshDemo

     

    MeshDemo.h

    더보기
    #pragma once
    #include "Systems/IExecute.h"
    
    class MeshDemo : public IExecute
    {
    public:
    	virtual void Initialize() override;
    	virtual void Ready() override {}
    	virtual void Destroy() override;
    	virtual void Update() override;
    	virtual void PreRender() override {}
    	virtual void Render() override;
    	virtual void PostRender() override {}
    	virtual void ResizeScreen() override {}
    
    private:
    	void CreateMesh();
    
    private:
    	Shader* shader;
    
    	Vector3 direction = Vector3(-1, -1, 1);
    	ID3DX11EffectVectorVariable* sDirection;
    
    	MeshCube* cube;
    	MeshCylinder* cylinder[10];
    	MeshSphere* sphere[10];
    	MeshGrid* grid;
    };

     

     

    MeshDemo.cpp

    #include "stdafx.h"
    #include "MeshDemo.h"
    
    void MeshDemo::Initialize()
    {
    	Context::Get()->GetCamera()->RotationDegree(20, 0, 0);
    	Context::Get()->GetCamera()->Position(1, 36, -85);
    
    
    	shader = new Shader(L"25_Mesh.fx");
    	sDirection = shader->AsVector("Direction");
    	
    	CreateMesh();
    }
    
    void MeshDemo::Destroy()
    {
    	SafeDelete(shader);
    	
    	SafeDelete(cube);
    	SafeDelete(grid);
    
    	for (int i = 0; i < 10; i++)
    	{
    		SafeDelete(cylinder[i]);
    		SafeDelete(sphere[i]);
    	}
    }
    
    void MeshDemo::Update()
    {
    	cube->Update();
    	grid->Update();
    
    	for (int i = 0; i < 10; i++)
    	{
    		cylinder[i]->Update();
    		sphere[i]->Update();
    	}
    }
    
    void MeshDemo::Render()
    {
    	ImGui::SliderFloat3("Direction", direction, -1, +1);
    	sDirection->SetFloatVector(direction);
    
    	static int pass = 0;
    	ImGui::InputInt("Pass", &pass);
    	pass %= 2;
    
    
    	cube->Render();
    	grid->Render();
    
    	for (int i = 0; i < 10; i++)
    	{
    		cylinder[i]->Pass(pass);
    		cylinder[i]->Render();
    
    		sphere[i]->Pass(pass);
    		sphere[i]->Render();
    	}
    }
    
    void MeshDemo::CreateMesh()
    {
    	cube = new MeshCube(shader);
    	cube->GetTransform()->Position(0, 5, 0);
    	cube->GetTransform()->Scale(20, 10, 20);
    	cube->DiffuseMap(L"Stones.png");
    
    	grid = new MeshGrid(shader, 6, 6);
    	grid->GetTransform()->Scale(12, 1, 12);
    	grid->DiffuseMap(L"Floor.png");
    
    
    	for (UINT i = 0; i < 5; i++)
    	{
    		cylinder[i * 2] = new MeshCylinder(shader, 0.5f, 3.0f, 20, 20);
    		cylinder[i * 2]->GetTransform()->Position(-30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2]->GetTransform()->Scale(5, 5, 5);
    		cylinder[i * 2]->DiffuseMap(L"Bricks.png");
    
    		cylinder[i * 2 + 1] = new MeshCylinder(shader, 0.5f, 3.0f, 20, 20);
    		cylinder[i * 2 + 1]->GetTransform()->Position(30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2 + 1]->GetTransform()->Scale(5, 5, 5);
    		cylinder[i * 2 + 1]->DiffuseMap(L"Bricks.png");
    
    
    		sphere[i * 2] = new MeshSphere(shader, 0.5f, 20, 20);
    		sphere[i * 2]->GetTransform()->Position(-30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2]->GetTransform()->Scale(5, 5, 5);
    		sphere[i * 2]->DiffuseMap(L"Wall.png");
    
    		sphere[i * 2 + 1] = new MeshSphere(shader, 0.5f, 20, 20);
    		sphere[i * 2 + 1]->GetTransform()->Position(30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2 + 1]->GetTransform()->Scale(5, 5, 5);
    		sphere[i * 2 + 1]->DiffuseMap(L"Wall.png");
    	}
    }

     


     

     

     

     

     

    실행화면

     

     

     

    '⭐ DirectX > DirectX11 3D' 카테고리의 다른 글

    [DirectX11] 037 Model Reader  (0) 2023.02.05
    [DirectX11] 034~36 Model Editor  (0) 2023.02.01
    [DirectX11] 032 Renderer  (0) 2023.01.31
    [DirectX11] 031 Framework  (0) 2023.01.30
    [DirectX11] 029~30 Cube Map, Sphere Map  (0) 2023.01.27