diff --git a/Game.cpp b/Game.cpp index 38af35d..59baf18 100644 --- a/Game.cpp +++ b/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)); } } diff --git a/Material.cpp b/Material.cpp index 2ccbf54..587c5ba 100644 --- a/Material.cpp +++ b/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, 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) diff --git a/Material.h b/Material.h index b5b4bf9..6f23a1a 100644 --- a/Material.h +++ b/Material.h @@ -24,11 +24,15 @@ public: std::vector _lights); DirectX::XMFLOAT3 GetTint(); + DirectX::XMFLOAT2 GetUVScale(); + DirectX::XMFLOAT2 GetUVOffset(); float GetRoughness(); std::shared_ptr GetVertexShader(); std::shared_ptr 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 _vertexShader); void SetPixelShader(std::shared_ptr _pixelShader); @@ -39,6 +43,8 @@ public: private: DirectX::XMFLOAT3 tint; float roughness; + DirectX::XMFLOAT2 uvScale; + DirectX::XMFLOAT2 uvOffset; std::shared_ptr vertexShader; std::shared_ptr pixelShader; diff --git a/SimplePixelShader.hlsl b/SimplePixelShader.hlsl index f85ff27..9493ca6 100644 --- a/SimplePixelShader.hlsl +++ b/SimplePixelShader.hlsl @@ -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);