Created
July 24, 2023 20:27
-
-
Save marutypes/fe06ecaa9c3a453e784db8810a81460f to your computer and use it in GitHub Desktop.
Print Value In Shader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Debugger" | |
{ | |
Properties | |
{ | |
[HideInInspector] _texcoord( "", 2D ) = "white" {} | |
} | |
Subshader | |
{ | |
Tags { "RenderType" = "Opaque" } | |
CGPROGRAM | |
#pragma surface SurfaceShader Standard fullforwardshadows addshadow | |
struct Input | |
{ | |
float2 uv_texcoord; //float2 uv_MainTex; | |
}; | |
// "PrintValue" function by P.Malin | |
float PrintValue( float2 vCoords, float fValue, float fMaxDigits, float fDecimalPlaces ) | |
{ | |
if ((vCoords.y < 0.0) || (vCoords.y >= 1.0)) return 0.0; | |
bool bNeg = ( fValue < 0.0 ); | |
fValue = abs(fValue); | |
float fBiggestIndex = max(floor(log2(abs(fValue)) / log2(10.0)), 0.0); | |
float fDigitIndex = fMaxDigits - floor(vCoords.x); | |
float fCharBin = 0.0; | |
if(fDigitIndex > (-fDecimalPlaces - 1.01)) | |
{ | |
if(fDigitIndex > fBiggestIndex) | |
{ | |
if((bNeg) && (fDigitIndex < (fBiggestIndex+1.5))) fCharBin = 1792.0; | |
} | |
else | |
{ | |
if(fDigitIndex == -1.0) | |
{ | |
if(fDecimalPlaces > 0.0) fCharBin = 2.0; | |
} | |
else | |
{ | |
float fReducedRangeValue = fValue; | |
if(fDigitIndex < 0.0) { fReducedRangeValue = frac( fValue ); fDigitIndex += 1.0; } | |
float fDigitValue = (abs(fReducedRangeValue / (pow(10.0, fDigitIndex)))); | |
int x = int(floor(fDigitValue - 10.0 * floor(fDigitValue/10.0))); | |
fCharBin = x==0?480599.0:x==1?139810.0:x==2?476951.0:x==3?476999.0:x==4?350020.0:x==5?464711.0:x==6?464727.0:x==7?476228.0:x==8?481111.0:x==9?481095.0:0.0; | |
} | |
} | |
} | |
float result = (fCharBin / pow(2.0, floor(frac(vCoords.x) * 4.0) + (floor(vCoords.y * 5.0) * 4.0))); | |
return floor(result - 2.0 * floor(result/2.0)); | |
} | |
void SurfaceShader (Input IN, inout SurfaceOutputStandard o) | |
{ | |
float2 uv = IN.uv_texcoord.xy; //IN.uv_MainTex | |
float number = 123.0; | |
if (uv.x > 0.8 && uv.y > 0.8) | |
{ | |
float2 font = float2(36.0, 45.0); | |
float2 position = float2(0.72,0.9); | |
float3 base = PrintValue( (uv - position) * font, number, 6.0, 2.0).xxx; | |
o.Albedo = float4(base, 1.0); | |
} | |
else | |
o.Albedo = float4(uv, 0.0, 1.0); //o.Albedo = tex2D(_MainTex,IN.uv_MainTex); | |
o.Normal = float3(0.0, 0.0, 1.0); | |
o.Metallic = 0.0; | |
o.Smoothness = 0.0; | |
} | |
ENDCG | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment