Cubemap Texture

 

 

글의 요약 설명 부분. 150자를 적어주세요. 글의 요약 설명 부분. 150자를 적어주세요. 글의 요약 설명 부분. 150자를 적어주세요. 글의 요약 설명 부분. 150자를 적어주세요. 글의 요약 설명 부분. 150자를 적어주세요. 글의 요약 설명 부분. 150자입니다

 

목차

     

     


     

     

    Cube Map

     

     


    CubeMap.fx

     

    CubeMap.fx

    더보기
    matrix World;
    matrix View;
    matrix Projection;
    
    TextureCube CubeMap;
    
    struct VertexInput
    {
        float4 Position : Position;
        float2 Uv : Uv;
        float3 Normal : Normal;
    };
    
    struct VertexOutput
    {
        float4 Position : SV_Position;
        float3 oPosition : Position1;
        float2 Uv : Uv;
        float3 Normal : Normal;
    };
    
    VertexOutput VS(VertexInput input)
    {
        VertexOutput output;
    
        output.oPosition = input.Position.xyz;
    
        output.Position = mul(input.Position, World);
        output.Position = mul(output.Position, View);
        output.Position = mul(output.Position, Projection);
        
        output.Normal = mul(input.Normal, (float3x3) World);
    
        output.Uv = input.Uv;
    
        return output;
    }
    
    SamplerState LinearSampler
    {
        Filter = MIN_MAG_MIP_LINEAR;
        AddressU = Wrap;
        AddressV = Wrap;
    };
    
    Texture2D t;
    float4 PS(VertexOutput input) : SV_Target
    {
        return CubeMap.Sample(LinearSampler, input.oPosition);
    
    }
    
    RasterizerState FillMode_Wireframe
    {
        FillMode = Wireframe;
    };
    
    technique11 T0
    {
        pass P0
        {
            SetVertexShader(CompileShader(vs_5_0, VS()));
            SetPixelShader(CompileShader(ps_5_0, PS()));
        }
    
        pass P1
        {
            SetRasterizerState(FillMode_Wireframe);
    
            SetVertexShader(CompileShader(vs_5_0, VS()));
            SetPixelShader(CompileShader(ps_5_0, PS()));
        }
    }

     


     

    Cube Map

     

     

    CubeMap.h

    더보기
    #pragma once
    
    class CubeMap
    {
    public:
    	CubeMap(Shader* shader);
    	~CubeMap();
    
    	void Texture(wstring file);
    
    	void Update();
    	void Render();
    
    	void Pass(UINT val) { pass = val; }
    
    	void Position(float x, float y, float z);
    	void Position(Vector3& vec);
    	void Position(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);
    
    	void Scale(float x, float y, float z);
    	void Scale(Vector3& vec);
    	void Scale(Vector3* vec);
    
    private:
    	Shader* shader;
    	UINT pass = 0;
    
    	//MeshCube* cube; //Cube모양
    	MeshSphere* cube;
    
    	ID3D11ShaderResourceView* srv = NULL;
    	ID3DX11EffectShaderResourceVariable* sSrv;
    };

     

     

    CubeMap.cpp

    더보기
     #include "Framework.h"
    #include "CubeMap.h"
    
    CubeMap::CubeMap(Shader * shader)
    	: shader(shader)
    {
    	//cube = new MeshCube(shader); //Cube모양
    	cube = new MeshSphere(shader, 0.5f);  //Sphere모양
    
    	sSrv = shader->AsSRV("CubeMap");
    }
    
    CubeMap::~CubeMap()
    {
    	SafeDelete(cube);
    
    	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()
    {
    	cube->Update();
    }
    
    void CubeMap::Render()
    {
    	sSrv->SetResource(srv);
    
    	cube->Render();
    }
    
    void CubeMap::Position(float x, float y, float z)
    {
    	cube->Position(x, y, z);
    }
    
    void CubeMap::Position(Vector3 & vec)
    {
    	cube->Position(vec);
    }
    
    void CubeMap::Position(Vector3 * vec)
    {
    	cube->Position(vec);
    }
    
    void CubeMap::Rotation(float x, float y, float z)
    {
    	cube->Rotation(x, y, z);
    }
    
    void CubeMap::Rotation(Vector3 & vec)
    {
    	cube->Rotation(vec);
    }
    
    void CubeMap::Rotation(Vector3 * vec)
    {
    	cube->Rotation(vec);
    }
    
    void CubeMap::RotationDegree(float x, float y, float z)
    {
    	cube->RotationDegree(x, y, z);
    }
    
    void CubeMap::RotationDegree(Vector3 & vec)
    {
    	cube->RotationDegree(vec);
    }
    
    void CubeMap::RotationDegree(Vector3 * vec)
    {
    	cube->RotationDegree(vec);
    }
    
    void CubeMap::Scale(float x, float y, float z)
    {
    	cube->Scale(x, y, z);
    }
    
    void CubeMap::Scale(Vector3 & vec)
    {
    	cube->Scale(vec);
    }
    
    void CubeMap::Scale(Vector3 * vec)
    {
    	cube->Scale(vec);
    }

     


     

    Cube Map Demo

     

     

    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->Position(0, 20, 0);
    	cubeMap->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()
    {
    	cube = new MeshCube(shader);
    	cube->Position(0, 5, 0);
    	cube->Scale(20, 10, 20);
    	cube->DiffuseMap(L"Stones.png");
    
    	grid = new MeshGrid(shader, 6, 6);
    	grid->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]->Position(-30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2]->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]->Position(30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2 + 1]->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]->Position(-30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2]->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]->Position(30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2 + 1]->Scale(5, 5, 5);
    		sphere[i * 2 + 1]->DiffuseMap(L"Wall.png");
    	}
    }

     

     

     


     

    실행화면

     

     


     

     

    Cube Sky

     

    구의 위치 = 카메라 위치를 기준으로 잡는다.

     

    반시계 방향

     

    Rasterizer 시계 방향 -> 반시계 방향으로 변환


     

     

    CubeSky.fx

     

     

    CubeSky.fx

    더보기
    matrix World;
    matrix View;
    matrix Projection;
    
    TextureCube SkyCubeMap;
    
    struct VertexInput
    {
        float4 Position : Position;
        float2 Uv : Uv;
        float3 Normal : Normal;
    };
    
    struct VertexOutput
    {
        float4 Position : SV_Position;
        float3 oPosition : Position1;
        float2 Uv : Uv;
        float3 Normal : Normal;
    };
    
    VertexOutput VS(VertexInput input)
    {
        VertexOutput output;
    
        output.oPosition = input.Position.xyz;
    
        output.Position = mul(input.Position, World);
        output.Position = mul(output.Position, View);
        output.Position = mul(output.Position, Projection);
        
        output.Normal = mul(input.Normal, (float3x3) World);
    
        output.Uv = input.Uv;
    
        return output;
    }
    
    SamplerState LinearSampler
    {
        Filter = MIN_MAG_MIP_LINEAR;
        AddressU = Wrap;
        AddressV = Wrap;
    };
    
    RasterizerState FrontCounterClockWise_True
    {
        FrontCounterClockWise = True;
    };
    
    DepthStencilState DepthEnable_False
    {
        DepthEnable = false;
    };
    
    Texture2D t;
    float4 PS(VertexOutput input) : SV_Target
    {
        return SkyCubeMap.Sample(LinearSampler, input.oPosition);
    
    }
    
    technique11 T0
    {
        pass P0
        {
            SetRasterizerState(FrontCounterClockWise_True);
            SetDepthStencilState(DepthEnable_False, 0);
    
            SetVertexShader(CompileShader(vs_5_0, VS()));
            SetPixelShader(CompileShader(ps_5_0, PS()));
        }
    }

     

    깊이off 하늘을 그리고 그 후 깊이on 물체를 그리고 그 후에 깊이off UI를 그린다. 

     


     

     

    Cube Sky

     

     

    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->Position(position);
    }
    
    void CubeSky::Render()
    {
    	sSrv->SetResource(srv);
    	sphere->Render();
    }

     

     


     

    Cube Sky Demo

     

     

    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->Position(0, 20, 0);
    	cubeMap->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->Position(0, 5, 0);
    	cube->Scale(20, 10, 20);
    	cube->DiffuseMap(L"Stones.png");
    
    	grid = new MeshGrid(shader, 6, 6);
    	grid->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]->Position(-30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2]->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]->Position(30, 6, (float)i * 15.0f - 15.0f);
    		cylinder[i * 2 + 1]->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]->Position(-30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2]->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]->Position(30, 15.5f, (float)i * 15.0f - 15.0f);
    		sphere[i * 2 + 1]->Scale(5, 5, 5);
    		sphere[i * 2 + 1]->DiffuseMap(L"Wall.png");
    	}
    }

     


     

     

     

    실행화면

     

     

     


     

     

     

     

    Tips

     

     


     

     

    HLSL에 줄번호 추가하는 방법

     

    방법1. HLSL 줄 번호

     

     

    방법2. 모든 언어 줄 번호 

     

     


     

     

     

    Texture 편집 + Texture 다운받을 수 있는 사이트 

     

    DxTex.exe 실행

    • C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Utilities\bin\x86
    • 해당 위치의 DxTex.exd 실행

     

     

    Cubemap Texture 다운받을 수 있는 사이트

     

    https://humus.name/

     

    Humus

    "If there's one thing worse than a program that doesn't work when it should, it's a program that does work when it shouldn't." - Bob Archer More pages: 1 2 3 4 5 6 ... 11 ... 21 ... 31 ... 41 ... 48 Another Metaballs2 updateFriday, October 25, 2019 | Perma

    humus.name