Permalink
Browse files

Renamed dFdx/y to DeriveTowardsX/Y.

Updated examples.
Renamed noise<i> to Noise<i>
Supported discard in HLSL
  • Loading branch information...
1 parent e67b68c commit 0fcbade34360429f7e456c8cb312836e3af69573 @WolfgangSt WolfgangSt committed Oct 20, 2011
@@ -27,8 +27,8 @@ public vec4 WangAt(vec2 tex)
var offset = texture(WangMap, Fraction(address)).xw;
var tc = offset + subPos;
var tileScaledTex = tex * new vec2(32.0f / 1.0f);
-
- return textureGrad(WangTiles, tc, dFdx(tileScaledTex), dFdy(tileScaledTex));
+
+ return textureGrad(WangTiles, tc, DeriveTowardsX(tileScaledTex), DeriveTowardsY(tileScaledTex));
}
public override void Begin()
@@ -26,7 +26,7 @@ public vec4 WangAt(vec2 tex)
var tc = offset + subPos;
var tileScaledTex = tex * new vec2(32.0f / 1.0f);
- return textureGrad(WangTiles, tc, dFdx(tileScaledTex), dFdy(tileScaledTex));
+ return textureGrad(WangTiles, tc, DeriveTowardsX(tileScaledTex), DeriveTowardsY(tileScaledTex));
}
public override void Begin()
@@ -95,8 +95,8 @@ public void ClipmapFragmentMain()
var light = Normalize(new vec3(0.0f, 1.0f, 0.6f));
var n = Normalize(Normal);
-
- var n2 = Normalize(Cross(dFdx(_finalPos.xyz),dFdy(_finalPos.xyz)));
+
+ var n2 = Normalize(Cross(DeriveTowardsX(_finalPos.xyz), DeriveTowardsY(_finalPos.xyz)));
n2.xy = -n2.xy;
var light2 = new mat3(NormalMatrix) * (light);
@@ -25,8 +25,8 @@ public vec4 WangAt(vec2 tex)
var offset = texture(WangMap, Fraction(address)).xw;
var tc = offset + subPos;
var tileScaledTex = tex * new vec2(32.0f / 1.0f);
-
- return textureGrad(WangTiles, tc, dFdx(tileScaledTex), dFdy(tileScaledTex));
+
+ return textureGrad(WangTiles, tc, DeriveTowardsX(tileScaledTex), DeriveTowardsY(tileScaledTex));
}
public override void Begin()
@@ -8,54 +8,54 @@ public abstract partial class ShaderDefinition
// implementation may approximate the true derivatives by using a fast but not entirely accurate derivative
// computation. Derivatives are undefined within non-uniform control flow.
- #region genType dFdx(genType p)
+ #region genType DeriveTowardsX(genType p)
/// <summary>Returns the derivative in x using local differencing for the input argument p.</summary>
- protected internal static float dFdx(float p) { throw _invalidAccess; }
+ protected internal static float DeriveTowardsX(float p) { throw _invalidAccess; }
/// <summary>Returns the derivative in x using local differencing for the input argument p.</summary>
- protected internal static vec2 dFdx(vec2 p) { throw _invalidAccess; }
+ protected internal static vec2 DeriveTowardsX(vec2 p) { throw _invalidAccess; }
/// <summary>Returns the derivative in x using local differencing for the input argument p.</summary>
- protected internal static vec3 dFdx(vec3 p) { throw _invalidAccess; }
+ protected internal static vec3 DeriveTowardsX(vec3 p) { throw _invalidAccess; }
/// <summary>Returns the derivative in x using local differencing for the input argument p.</summary>
- protected internal static vec4 dFdx(vec4 p) { throw _invalidAccess; }
+ protected internal static vec4 DeriveTowardsX(vec4 p) { throw _invalidAccess; }
#endregion
- #region genType dFdy(genType p)
+ #region genType DeriveTowardsY(genType p)
/// <summary>Returns the derivative in y using local differencing for the input argument p.</summary>
- protected internal static float dFdy(float p) { throw _invalidAccess; }
+ protected internal static float DeriveTowardsY(float p) { throw _invalidAccess; }
/// <summary>Returns the derivative in y using local differencing for the input argument p.</summary>
- protected internal static vec2 dFdy(vec2 p) { throw _invalidAccess; }
+ protected internal static vec2 DeriveTowardsY(vec2 p) { throw _invalidAccess; }
/// <summary>Returns the derivative in y using local differencing for the input argument p.</summary>
- protected internal static vec3 dFdy(vec3 p) { throw _invalidAccess; }
+ protected internal static vec3 DeriveTowardsY(vec3 p) { throw _invalidAccess; }
/// <summary>Returns the derivative in y using local differencing for the input argument p.</summary>
- protected internal static vec4 dFdy(vec4 p) { throw _invalidAccess; }
+ protected internal static vec4 DeriveTowardsY(vec4 p) { throw _invalidAccess; }
#endregion
#region genType fwidth(genType p)
/// <summary>Returns the sum of the absolute derivative in x and y using local
- /// differencing for the input argument p, i.e., Abs (dFdx (p)) + Abs (dFdy (p));</summary>
+ /// differencing for the input argument p, i.e., Abs(DeriveTowardsX(p)) + Abs(DeriveTowardsY(p));</summary>
protected static float fwidth(float p) { throw _invalidAccess; }
/// <summary>Returns the sum of the absolute derivative in x and y using local
- /// differencing for the input argument p, i.e., Abs (dFdx (p)) + Abs (dFdy (p));</summary>
+ /// differencing for the input argument p, i.e., Abs(DeriveTowardsX(p)) + Abs(DeriveTowardsY(p));</summary>
protected static vec2 fwidth(vec2 p) { throw _invalidAccess; }
/// <summary>Returns the sum of the absolute derivative in x and y using local
- /// differencing for the input argument p, i.e., Abs (dFdx (p)) + Abs (dFdy (p));</summary>
+ /// differencing for the input argument p, i.e., Abs(DeriveTowardsX(p)) + Abs(DeriveTowardsY(p));</summary>
protected static vec3 fwidth(vec3 p) { throw _invalidAccess; }
/// <summary>Returns the sum of the absolute derivative in x and y using local
- /// differencing for the input argument p, i.e., Abs (dFdx (p)) + Abs (dFdy (p));</summary>
+ /// differencing for the input argument p, i.e., Abs(DeriveTowardsX(p)) + Abs(DeriveTowardsY(p));</summary>
protected static vec4 fwidth(vec4 p) { throw _invalidAccess; }
#endregion
@@ -8,67 +8,67 @@ public abstract partial class ShaderDefinition
// can be used to increase visual complexity. Values returned by the following noise functions give the
// appearance of randomness, but are not truly random.
- #region float noise1(genType x)
+ #region float Noise1(genType x)
/// <summary>Returns a 1D noise value based on the input value x.</summary>
- protected static float noise1(float x) { throw _invalidAccess; }
+ protected internal static float Noise1(float x) { throw _invalidAccess; }
/// <summary>Returns a 1D noise value based on the input value x.</summary>
- protected static float noise1(vec2 x) { throw _invalidAccess; }
+ protected internal static float Noise1(vec2 x) { throw _invalidAccess; }
/// <summary>Returns a 1D noise value based on the input value x.</summary>
- protected static float noise1(vec3 x) { throw _invalidAccess; }
+ protected internal static float Noise1(vec3 x) { throw _invalidAccess; }
/// <summary>Returns a 1D noise value based on the input value x.</summary>
- protected static float noise1(vec4 x) { throw _invalidAccess; }
+ protected internal static float Noise1(vec4 x) { throw _invalidAccess; }
#endregion
- #region vec2 noise2(genType x)
+ #region vec2 Noise2(genType x)
/// <summary>Returns a 2D noise value based on the input value x.</summary>
- protected static vec2 noise2(float x) { throw _invalidAccess; }
+ protected internal static vec2 Noise2(float x) { throw _invalidAccess; }
/// <summary>Returns a 2D noise value based on the input value x.</summary>
- protected static vec2 noise2(vec2 x) { throw _invalidAccess; }
+ protected internal static vec2 Noise2(vec2 x) { throw _invalidAccess; }
/// <summary>Returns a 2D noise value based on the input value x.</summary>
- protected static vec2 noise2(vec3 x) { throw _invalidAccess; }
+ protected internal static vec2 Noise2(vec3 x) { throw _invalidAccess; }
/// <summary>Returns a 2D noise value based on the input value x.</summary>
- protected static vec2 noise2(vec4 x) { throw _invalidAccess; }
+ protected internal static vec2 Noise2(vec4 x) { throw _invalidAccess; }
#endregion
- #region vec3 noise3(genType x)
+ #region vec3 Noise3(genType x)
/// <summary>Returns a 3D noise value based on the input value x.</summary>
- protected static vec3 noise3(float x) { throw _invalidAccess; }
+ protected internal static vec3 Noise3(float x) { throw _invalidAccess; }
/// <summary>Returns a 3D noise value based on the input value x.</summary>
- protected static vec3 noise3(vec2 x) { throw _invalidAccess; }
+ protected internal static vec3 Noise3(vec2 x) { throw _invalidAccess; }
/// <summary>Returns a 3D noise value based on the input value x.</summary>
- protected static vec3 noise3(vec3 x) { throw _invalidAccess; }
+ protected internal static vec3 Noise3(vec3 x) { throw _invalidAccess; }
/// <summary>Returns a 3D noise value based on the input value x.</summary>
- protected static vec3 noise3(vec4 x) { throw _invalidAccess; }
+ protected internal static vec3 Noise3(vec4 x) { throw _invalidAccess; }
#endregion
- #region vec4 noise4(genType x)
+ #region vec4 Noise4(genType x)
/// <summary>Returns a 4D noise value based on the input value x.</summary>
- protected static vec4 noise4(float x) { throw _invalidAccess; }
+ protected internal static vec4 Noise4(float x) { throw _invalidAccess; }
/// <summary>Returns a 4D noise value based on the input value x.</summary>
- protected static vec4 noise4(vec2 x) { throw _invalidAccess; }
+ protected internal static vec4 Noise4(vec2 x) { throw _invalidAccess; }
/// <summary>Returns a 4D noise value based on the input value x.</summary>
- protected static vec4 noise4(vec3 x) { throw _invalidAccess; }
+ protected internal static vec4 Noise4(vec3 x) { throw _invalidAccess; }
/// <summary>Returns a 4D noise value based on the input value x.</summary>
- protected static vec4 noise4(vec4 x) { throw _invalidAccess; }
+ protected internal static vec4 Noise4(vec4 x) { throw _invalidAccess; }
#endregion
}
@@ -518,6 +518,44 @@ public GlslVisitor()
{ () => ShaderDefinition.FusedMultiplyAdd(dvec4, dvec4, dvec4), Rename("fma") },
#endregion
+
+ #region Derivative
+
+ { () => ShaderDefinition.DeriveTowardsX(_float), Rename("dFdx") },
+ { () => ShaderDefinition.DeriveTowardsX(vec2), Rename("dFdx") },
+ { () => ShaderDefinition.DeriveTowardsX(vec3), Rename("dFdx") },
+ { () => ShaderDefinition.DeriveTowardsX(vec4), Rename("dFdx") },
+
+ { () => ShaderDefinition.DeriveTowardsY(_float), Rename("dFdy") },
+ { () => ShaderDefinition.DeriveTowardsY(vec2), Rename("dFdy") },
+ { () => ShaderDefinition.DeriveTowardsY(vec3), Rename("dFdy") },
+ { () => ShaderDefinition.DeriveTowardsY(vec4), Rename("dFdy") },
+
+ #endregion
+
+ #region Noise
+
+ { () => ShaderDefinition.Noise1(_float), ToLower },
+ { () => ShaderDefinition.Noise1(vec2), ToLower },
+ { () => ShaderDefinition.Noise1(vec3), ToLower },
+ { () => ShaderDefinition.Noise1(vec4), ToLower },
+
+ { () => ShaderDefinition.Noise2(_float), ToLower },
+ { () => ShaderDefinition.Noise2(vec2), ToLower },
+ { () => ShaderDefinition.Noise2(vec3), ToLower },
+ { () => ShaderDefinition.Noise2(vec4), ToLower },
+
+ { () => ShaderDefinition.Noise3(_float), ToLower },
+ { () => ShaderDefinition.Noise3(vec2), ToLower },
+ { () => ShaderDefinition.Noise3(vec3), ToLower },
+ { () => ShaderDefinition.Noise3(vec4), ToLower },
+
+ { () => ShaderDefinition.Noise4(_float), ToLower },
+ { () => ShaderDefinition.Noise4(vec2), ToLower },
+ { () => ShaderDefinition.Noise4(vec3), ToLower },
+ { () => ShaderDefinition.Noise4(vec4), ToLower },
+
+ #endregion
};
}
@@ -22,6 +22,8 @@ public HlslVisitor()
{
Handlers = new Dictionary<Expression<Action>, Func<MethodDefinition, InvocationExpression, StringBuilder>>(new HandlerComparer())
{
+ { () => ShaderDefinition.Discard(), KeywordDiscard },
+
#region Trigonometry
{ () => ShaderDefinition.Radians(_float), ToLower },
@@ -405,21 +407,36 @@ public HlslVisitor()
#endregion
+ #region Derivative
+
+ { () => ShaderDefinition.DeriveTowardsX(_float), Rename("ddx") },
+ { () => ShaderDefinition.DeriveTowardsX(vec2), Rename("ddx") },
+ { () => ShaderDefinition.DeriveTowardsX(vec3), Rename("ddx") },
+ { () => ShaderDefinition.DeriveTowardsX(vec4), Rename("ddx") },
+
+ { () => ShaderDefinition.DeriveTowardsY(_float), Rename("ddy") },
+ { () => ShaderDefinition.DeriveTowardsY(vec2), Rename("ddy") },
+ { () => ShaderDefinition.DeriveTowardsY(vec3), Rename("ddy") },
+ { () => ShaderDefinition.DeriveTowardsY(vec4), Rename("ddy") },
+
+ #endregion
+
+ #region Noise
+
+ { () => ShaderDefinition.Noise1(_float), Rename("noise") },
+ { () => ShaderDefinition.Noise1(vec2), Rename("noise") },
+ { () => ShaderDefinition.Noise1(vec3), Rename("noise") },
+ { () => ShaderDefinition.Noise1(vec4), Rename("noise") },
+
+ // Noise2 3 and 4 needs emulation
+
+ #endregion
+
{ () => ShaderDefinition.texture(sampler2D, vec2), Rename("tex2D") },
// we need to wrap this into tex2DBias(sampler, new vec4(vec2, 0.0, float)
//{ () => ShaderDefinition.texture(sampler2D, vec2, _float), Redirect<Workarounds.Texture>("tex2Dbias") },
- { () => ShaderDefinition.dFdx(_float), Rename("ddx") },
- { () => ShaderDefinition.dFdx(vec2), Rename("ddx") },
- { () => ShaderDefinition.dFdx(vec3), Rename("ddx") },
- { () => ShaderDefinition.dFdx(vec4), Rename("ddx") },
-
- { () => ShaderDefinition.dFdy(_float), Rename("ddy") },
- { () => ShaderDefinition.dFdy(vec2), Rename("ddy") },
- { () => ShaderDefinition.dFdy(vec3), Rename("ddy") },
- { () => ShaderDefinition.dFdy(vec4), Rename("ddy") },
-
{ () => ShaderDefinition.textureGrad(sampler2D, vec2, vec2, vec2), Rename("tex2Dgrad") },
{ () => ShaderDefinition.textureLod(sampler2D, vec2, _float), TextureLod }
@@ -462,5 +479,10 @@ private StringBuilder Refract(MethodDefinition m, InvocationExpression i)
return result.Append("refract(").Append(ArgsToString(args)).Append(")");
}
+
+ private StringBuilder KeywordDiscard(MethodDefinition unused1, InvocationExpression unused2)
+ {
+ return new StringBuilder("discard");
+ }
}
}

0 comments on commit 0fcbade

Please sign in to comment.