Using Material Expression Cosine with a Period of 0.0 gives unexpected results

Branch: A build of the GitHub 4.2 branch

Build Version: 4.2.0-0+UE4

Repro Steps:

  1. In Visual Studio open MaterialExpression.cpp
  2. Goto line 2880 (assumes 4.2 codebase, also try going to UMaterialExpressionSine::Compile)
  3. See that when Sine is compiled it either passes a multiplication for using Period, but if Period is 0.0f it just passes the Input unmodified.
  4. Goto line 2916 (assumes 4.2 codebase, also try going to UMaterialExpressionCosine::Compile)
  5. See that when Cosine is compiled it always passes a multiplication, but if Period is 0.0f it passes 0 as the index to the second multiplicand. I don’t think this is the intended behaviour.

I made a test material that shows the bug, but when I try to attach it I get an error saying that the file type (.uasset) is invalid.

You are correct. That is broken. As for what period=0 should equal, I’m not sure. I don’t agree with what sin has that defined to be either.

I’ll make some hand wavy reference to Taylor series expansion of sin(pi/(1-x)) and Grandi’s series and say I think both should be defined as zero when period=0.

Really? I thought Period=0 was a way for someone like me to not have the multiplication automatically inserted. i.e. I just want the sine of this value I’m passing without it being changed. Which is what the sine version does.