add uv offset/scale support
This commit is contained in:
parent
224766bcaf
commit
32f0916f97
4 changed files with 35 additions and 0 deletions
2
Game.cpp
2
Game.cpp
|
@ -246,6 +246,8 @@ void Game::Update(float deltaTime, float totalTime)
|
|||
{
|
||||
entities[i]->GetTransform()->SetRotation(sin(totalTime / 720) * 360, 0, 0);
|
||||
entities[i]->GetMaterial()->SetRoughness(sin(totalTime) * 0.5f + 0.49f);
|
||||
entities[i]->GetMaterial()->SetUVOffset(DirectX::XMFLOAT2(cos(totalTime * 4) * 0.5f + 0.49f, cos(totalTime * 4) * 0.5f + 0.49f));
|
||||
entities[i]->GetMaterial()->SetUVScale(DirectX::XMFLOAT2(sin(totalTime) * 0.5f + 0.49f, sin(totalTime) * 0.5f + 0.49f));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
24
Material.cpp
24
Material.cpp
|
@ -10,6 +10,8 @@ Material::Material(
|
|||
roughness = _roughness;
|
||||
vertexShader = _vertexShader;
|
||||
pixelShader = _pixelShader;
|
||||
uvOffset = DirectX::XMFLOAT2(0, 0);
|
||||
uvScale = DirectX::XMFLOAT2(1, 1);
|
||||
}
|
||||
|
||||
Material::~Material()
|
||||
|
@ -27,6 +29,8 @@ void Material::Activate(Transform* _transform, std::shared_ptr<Camera> _camera,
|
|||
|
||||
pixelShader->SetFloat3("cameraPosition", _camera->GetTransform()->GetPosition());
|
||||
pixelShader->SetFloat("roughness", GetRoughness());
|
||||
pixelShader->SetFloat2("scale", GetUVScale());
|
||||
pixelShader->SetFloat2("offset", GetUVOffset());
|
||||
pixelShader->SetFloat3("tint", GetTint());
|
||||
pixelShader->SetFloat3("ambient", _ambient);
|
||||
pixelShader->SetData("lights", &_lights[0], sizeof(Light) * (int)_lights.size());
|
||||
|
@ -48,6 +52,16 @@ DirectX::XMFLOAT3 Material::GetTint()
|
|||
return tint;
|
||||
}
|
||||
|
||||
DirectX::XMFLOAT2 Material::GetUVScale()
|
||||
{
|
||||
return uvScale;
|
||||
}
|
||||
|
||||
DirectX::XMFLOAT2 Material::GetUVOffset()
|
||||
{
|
||||
return uvOffset;
|
||||
}
|
||||
|
||||
float Material::GetRoughness()
|
||||
{
|
||||
return roughness;
|
||||
|
@ -68,6 +82,16 @@ void Material::SetTint(DirectX::XMFLOAT3 _tint)
|
|||
tint = _tint;
|
||||
}
|
||||
|
||||
void Material::SetUVScale(DirectX::XMFLOAT2 _scale)
|
||||
{
|
||||
uvScale = _scale;
|
||||
}
|
||||
|
||||
void Material::SetUVOffset(DirectX::XMFLOAT2 _offset)
|
||||
{
|
||||
uvOffset = _offset;
|
||||
}
|
||||
|
||||
void Material::SetRoughness(float _roughness)
|
||||
{
|
||||
if (_roughness > 1)
|
||||
|
|
|
@ -24,11 +24,15 @@ public:
|
|||
std::vector<Light> _lights);
|
||||
|
||||
DirectX::XMFLOAT3 GetTint();
|
||||
DirectX::XMFLOAT2 GetUVScale();
|
||||
DirectX::XMFLOAT2 GetUVOffset();
|
||||
float GetRoughness();
|
||||
std::shared_ptr<SimpleVertexShader> GetVertexShader();
|
||||
std::shared_ptr<SimplePixelShader> GetPixelShader();
|
||||
|
||||
void SetTint(DirectX::XMFLOAT3 _tint);
|
||||
void SetUVScale(DirectX::XMFLOAT2 _scale);
|
||||
void SetUVOffset(DirectX::XMFLOAT2 _offset);
|
||||
void SetRoughness(float _roughness);
|
||||
void SetVertexShader(std::shared_ptr<SimpleVertexShader> _vertexShader);
|
||||
void SetPixelShader(std::shared_ptr<SimplePixelShader> _pixelShader);
|
||||
|
@ -39,6 +43,8 @@ public:
|
|||
private:
|
||||
DirectX::XMFLOAT3 tint;
|
||||
float roughness;
|
||||
DirectX::XMFLOAT2 uvScale;
|
||||
DirectX::XMFLOAT2 uvOffset;
|
||||
std::shared_ptr<SimpleVertexShader> vertexShader;
|
||||
std::shared_ptr<SimplePixelShader> pixelShader;
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ cbuffer ExternalData : register(b0)
|
|||
{
|
||||
float3 cameraPosition;
|
||||
float roughness;
|
||||
float2 offset;
|
||||
float2 scale;
|
||||
float3 ambient;
|
||||
float3 tint;
|
||||
Light lights[LIGHT_COUNT];
|
||||
|
@ -54,6 +56,7 @@ float4 main(VertexToPixel input) : SV_TARGET
|
|||
{
|
||||
// ensure input normals are normalized
|
||||
input.normal = normalize(input.normal);
|
||||
input.uv = input.uv * scale + offset;
|
||||
|
||||
// view only needs calculated once, so pre-calculate here and pass it to lights
|
||||
float3 view = getView(cameraPosition, input.worldPosition);
|
||||
|
|
Reference in a new issue