Permalink
Browse files

deprecated mod() builin in favor for % operator.

Implemented % operator logic
  • Loading branch information...
1 parent ef1f282 commit bb0b70c5214741713894a386ee2ce887133610f5 @WolfgangSt WolfgangSt committed Sep 1, 2011
@@ -386,75 +386,6 @@ public abstract partial class ShaderDefinition
#endregion
- #region genType mod(genType x, float y)
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected internal static float mod(float x, float y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected internal static vec2 mod(vec2 x, float y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected internal static vec3 mod(vec3 x, float y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected internal static vec4 mod(vec4 x, float y) { throw _invalidAccess; }
-
- #endregion
-
- #region genType mod(genType x, genType y)
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected internal static vec2 mod(vec2 x, vec2 y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected internal static vec3 mod(vec3 x, vec3 y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected internal static vec4 mod(vec4 x, vec4 y) { throw _invalidAccess; }
-
- #endregion
-
- #region genDType mod(genDType x, double y)
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected static double mod(double x, double y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected static dvec2 mod(dvec2 x, double y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected static dvec3 mod(dvec3 x, double y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- [Obsolete("Use the % operator")]
- protected static dvec4 mod(dvec4 x, double y) { throw _invalidAccess; }
-
- #endregion
-
- #region genDType mod(genDType x, genDType y)
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- protected static dvec2 mod(dvec2 x, dvec2 y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- protected static dvec3 mod(dvec3 x, dvec3 y) { throw _invalidAccess; }
-
- /// <summary>Modulus. Returns x – y * Floor (x/y).</summary>
- protected static dvec4 mod(dvec4 x, dvec4 y) { throw _invalidAccess; }
-
- #endregion
-
#region genType modf (genType x, out genType i)
/// <summary>Returns the fractional part of x and sets i to the integer part
@@ -268,6 +268,16 @@ public override StringBuilder VisitCastExpression(CastExpression castExpression,
public override StringBuilder VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, int data)
{
+ if (binaryOperatorExpression.Operator == BinaryOperatorType.Modulus)
+ {
+ // TODO: check if lhs is a gen(D)Type and only apply the rule in that case
+ // replace with mod(lhs, rhs) statement
+ var r = new StringBuilder("mod(");
+ r.Append(binaryOperatorExpression.Left.AcceptVisitor(this, data));
+ r.Append(", ").Append(binaryOperatorExpression.Right.AcceptVisitor(this, data)).Append(")");
+ return r;
+ }
+
var result = new StringBuilder("(");
result.Append(binaryOperatorExpression.Left.AcceptVisitor(this, data));
@@ -410,14 +410,6 @@ public HlslVisitor()
// we need to wrap this into tex2DBias(sampler, new vec4(vec2, 0.0, float)
//{ () => ShaderDefinition.texture(sampler2D, vec2, _float), Redirect<Workarounds.Texture>("tex2Dbias") },
- { () => ShaderDefinition.mod(vec2, _float), (m, i) => ModFloat<ShaderDefinition.vec2>(m, i) },
- { () => ShaderDefinition.mod(vec3, _float), (m, i) => ModFloat<ShaderDefinition.vec2>(m, i) },
- { () => ShaderDefinition.mod(vec4, _float), (m, i) => ModFloat<ShaderDefinition.vec2>(m, i) },
- { () => ShaderDefinition.mod(_float, _float), Rename("fmod") },
- { () => ShaderDefinition.mod(vec2, vec2), Rename("fmod") },
- { () => ShaderDefinition.mod(vec3, vec3), Rename("fmod") },
- { () => ShaderDefinition.mod(vec4, vec4), Rename("fmod") },
-
{ () => ShaderDefinition.dFdx(_float), Rename("ddx") },
{ () => ShaderDefinition.dFdx(vec2), Rename("ddx") },
{ () => ShaderDefinition.dFdx(vec3), Rename("ddx") },
@@ -442,23 +434,6 @@ private Expression WidenType<T>(Expression source)
return n;
}
- private StringBuilder ModFloat<T>(MethodDefinition m, InvocationExpression i)
- {
- // mod() will have 2 args we need to widen the rhs to a T1 however
-
- Debug.Assert(i.Arguments.Count == 2);
- var result = new StringBuilder();
-
- var lhs = i.Arguments.Take(1);
- var rhs = i.Arguments.Skip(1).Take(1);
- var widen = rhs.Select(WidenType<T>);
- var args = lhs.Concat(widen).ToList();
-
- result.Append("fmod(").Append(ArgsToString(args)).Append(")");
-
- return result;
- }
-
private StringBuilder TextureLod(MethodDefinition m, InvocationExpression i)
{
Debug.Assert(i.Arguments.Count == 3);
@@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using ICSharpCode.Decompiler;
+using ICSharpCode.Decompiler.Ast;
using ICSharpCode.Decompiler.Ast.Transforms;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Resolver;
@@ -313,6 +314,22 @@ public override StringBuilder VisitBinaryOperatorExpression(BinaryOperatorExpres
}
}
+ if (binaryOperatorExpression.Operator == BinaryOperatorType.Modulus)
+ {
+ // TODO: check if lhs is a gen(D)Type and only apply the rule in that case
+ // replace with mod(lhs, rhs) statement
+ var r = new StringBuilder("fmod(");
+ r.Append(binaryOperatorExpression.Left.AcceptVisitor(this, data)).Append(", ");
+
+
+ // we need to widen in case rhs is a scalar and rhs is a vec type!
+ r.Append(binaryOperatorExpression.Right.AcceptVisitor(this, data));
+
+ r.Append(")");
+ return r;
+ }
+
+
result.Append("(");
result.Append(binaryOperatorExpression.Left.AcceptVisitor(this, data));

0 comments on commit bb0b70c

Please sign in to comment.