Skip to content

Commit

Permalink
used a proper normal matrix to transform normals
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmind committed Apr 1, 2017
1 parent 8f4a4f2 commit d6008ca
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/blender-addon/leaf/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def export_texture(tex):

def export_image(img):
options = {
"cuda": True,
"cuda": False,
"linear": img.colorspace_settings.name == "Linear",
"normal_map": img.leaf.is_normal_map
}
Expand Down
5 changes: 2 additions & 3 deletions src/engine/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ struct SceneState
struct InstanceData
{
glm::mat4 modelMatrix;
glm::mat3 normalMatrix;
float _padding[3];
glm::mat3x4 normalMatrix; // use 3x4 to match cbuffer packing rules
};
#pragma pack(pop)

Expand Down Expand Up @@ -434,7 +433,7 @@ void Renderer::render(const Scene *scene, int width, int height, bool overrideCa
CHECK_HRESULT(res);
InstanceData *instanceData = (InstanceData *)mappedResource.pData;
instanceData->modelMatrix = job.transform;
instanceData->normalMatrix = glm::mat3(glm::inverseTranspose(job.transform));
instanceData->normalMatrix = glm::mat3x4(glm::inverseTranspose(glm::mat3(job.transform)));
Device::context->Unmap(this->cbInstance, 0);

Device::context->DrawIndexed(currentMesh->getIndexCount(), 0, 0);
Expand Down
1 change: 1 addition & 0 deletions src/engine/shaders/instance.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cbuffer InstanceData : register(b2)
{
float4x4 modelMatrix;
float3x3 normalMatrix;
};
4 changes: 2 additions & 2 deletions src/engine/shaders/standard.vs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ STANDARD_PS_INPUT main(VS_INPUT input)
output.position.z = (output.position.z + output.position.w) * 0.5;

output.worldPosition = worldPosition.xyz;
output.normal = mul((float3x3)modelMatrix, input.normal);
output.tangent = float4(mul((float3x3)modelMatrix, input.tangent.xyz), input.tangent.w);
output.normal = mul(normalMatrix, input.normal);
output.tangent = float4(mul(normalMatrix, input.tangent.xyz), input.tangent.w);
output.uv = float2(input.uv.x, 1.0 - input.uv.y);

return output;
Expand Down

0 comments on commit d6008ca

Please sign in to comment.