Saturday, November 6, 2021

Unity Frame Rates

To reach 60FPS we must update and render each frame in less than 16.67 milliseconds. The time budget for 30FPS is double that, thus 33.33ms per frame.

URP prefers the SRP batcher over GPU instancing, so to make GPU instancing work the SRP batcher has to be disabled. 

We could conclude from this data that for URP GPU Instancing is best, followed by dynamic batching, and then the SRP batcher. But the difference is small, so they seem effectively equivalent for our graph. The only clear conclusion is that either GPU instancing or the SRP batcher should be used.

Tuesday, August 7, 2018

Vector3 Extensions

public static Vector3 xyz (this Vector3 v, float x, float y, float z) {
    v.x = x;    v.y = y;   v.z = z;
    return v;
}
public static Vector3 xy (this Vector3 v, float x, float y) {
    v.x = x;   v.y = y;
    return v;
}
public static Vector3 xz (this Vector3 v, float x, float z) {
    v.x = x;   v.z = z;
    return v;
}

//calling it
Vector3 v = Vector3.zero;
v.xz(5f,10f);


//============================

public static Vector3 ChangeX (this Transform transform, float x) {
    Vector3 position = transform.position;
    position.x = x;
    transform.position = position;
    return position;
}
// Do the same for ChangeY and ChangeZ
// ...

// Old version
Vector3 position = transform.position;
position.x = 10;
transform.position = position;

// New version
transform.ChangeX(10);

Unity3D - Vector3 to Quaternion


static vector3 quaternion
vector3.zero (0, 0, 0) (0.0, 0.0, 0.0, 1.0)
vector3.back (0, 0, -1) (0.0, 0.0, -0.5, 0.9)
vector3.down (0, -1, 0) (0.0, -0.5, 0.0, 0.9)
vector3.forward (0, 0, 1) (0.0, 0.0, 0.5, 0.9)
vector3.left (-1, 0, 0) (-0.5, 0.0, 0.0, 0.9)
vector3.one (1, 1, 1) (0.6, 0.2, 0.2, 0.8)
vector3.right (1, 0, 0) (0.5, 0.0, 0.0, 0.9)
vector3.up (0, 1, 0) (0.0, 0.5, 0.0, 0.9)

Wednesday, February 21, 2018

Inheritance

public interface iBaseClass {
  void BaseClassMethod;
}


public class BaseClass : iBaseClass{
   // equivalent to private
   protected internal float accesibleToDerivedFloat = 0f;

   protected virtual void PrivateBaseClassMethod (){
      accesibleToDerivedFloat = 1f;
   }

   public virtual void BaseClassMethod ( //empty ) {}
}

====================================================

public interface IDerivedClass : IBaseClass{
}

public class DerivedClass : BaseClass, IDerivedClass{
   public override void PublicBaseClassMethod (){
      accesibleToDerivedFloat += 1f;
   }
}

Tuesday, February 13, 2018

Blender Sculpting Shortcuts


  • F = Adjust Brush SIZE
  • Shift + F = Adjust Brush Strength
  • Ctrl = Switch Between Add/Substract

Monday, August 14, 2017

Dependent Texture Reads

Not dependent:
float3 nonDependentTextureRead = tex2D(_MainTexture, input.texcoord).xyz;

Dependent:
float3 DependentTextureRead = tex2D(_MainTexture, input.texcoord.zw).xyz;
float3 DependentTextureRead = tex2D(_MainTexture, input.texcoord.yx).xyz;
float3 DependentTextureRead = tex2D(_MainTexture, input.texcoord*2.0).xyz;

==========================

struct v2f{
 half2 uv : TEXCOORDn; //pass uvs direcly
 half4 packed2uvs : TEXCOORDn; //afraid of dependent texture read, avoid packing 2 uvs into 1 varying
 half4 packed4Scalars : TEXCOORDn; //for general purpose scalar packing
}

tex2D(_Texture,i.uv); //good, fastest
tex2D(_Texture,i.uv.xy); //afraid of dependent texture read, depends on driver?. avoid
tex2D(_Texture,i.uv.zw); //afraid of dependent texture read. avoid