Unity_objecttoworld

  
GridFloorShader.shader
  1. Unity_objecttoworld Position
  2. Unity_objecttoworld Instancing
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader'Custom/GridShader' {
Properties{
_GridThickness('Grid Thickness', Float) = 0.1
_GridSpacing('Grid Spacing', Float) = 0.1
_GridColour('Grid Colour', Color) = (0.5, 1.0, 1.0, 1.0)
_BaseColour('Base Colour', Color) = (0.0, 0.0, 0.0, 0.0)
}
SubShader{
Tags{ 'Queue' = 'Transparent' }
Pass{
ZWriteOff
BlendSrcAlphaOneMinusSrcAlpha
CGPROGRAM
// Define the vertex and fragment shader functions
#pragma vertex vert
#pragma fragment frag
// Access Shaderlab properties
uniformfloat _GridThickness;
uniformfloat _GridSpacing;
uniformfloat4 _GridColour;
uniformfloat4 _BaseColour;
// Input into the vertex shader
struct vertexInput {
float4 vertex : POSITION;
};
// Output from vertex shader into fragment shader
struct vertexOutput {
float4 pos : SV_POSITION;
float4 worldPos : TEXCOORD0;
};
// VERTEX SHADER
vertexOutput vert(vertexInput input) {
vertexOutput output;
output.pos = UnityObjectToClipPos(input.vertex);
// Calculate the world position coordinates to pass to the fragment shader
output.worldPos = mul(unity_ObjectToWorld, input.vertex);
output.worldPos.x -= _GridThickness/2;
output.worldPos.z -= _GridThickness/2;
return output;
}
// FRAGMENT SHADER
float4frag(vertexOutput input) : COLOR{
if (frac(input.worldPos.x / _GridSpacing) < _GridThickness frac(input.worldPos.z / _GridSpacing) < _GridThickness) {
return _GridColour;
}
else {
return _BaseColour;
}
}
ENDCG
}
}
}
Not

commented Sep 27, 2018

Is there a way to force a certain amount of cells instead of it indefinitely repeating? Either way, thank you, this was very useful!

For example, unityObjectToWorld, or unitySHAr. You must declare all Material properties in a single CBUFFER named UnityPerMaterial. You can see the compatibility status of a Shader in the Inspector panel.

Simple Billboard shader for Unity. GitHub Gist: instantly share code, notes, and snippets. Simple Billboard shader for Unity. GitHub Gist: instantly share code, notes, and snippets.

commented Feb 11, 2019

Unity_objecttoworld Position

Noticed a bug, if you wish to center the grids over the center of the object position, as I believe this is trying to achieve...

.. This should be += rather than -=, and then is only accurate when the grid spacing is 1 (meter). For higher amounts you need...

Edit: Clarification / error

Unity_objecttoworldUnity_objecttoworldUnity_objecttoworld

Unity_objecttoworld Instancing

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment