forked from zalo/MathUtilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Yeouch signed cube blitting sucks! Almost wish I stayed with the numerical derivatives... hell, a numerical derivative here would probably be cheaper...
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
Shader "Unlit/blitCube" | ||
{ | ||
Properties | ||
{ | ||
_Center ("Center", Vector) = (0.5,0.5,0.5,0.0) | ||
_Extent ("Extent", Vector) = (0.15,0.15,0.15,0.0) | ||
} | ||
|
||
SubShader | ||
{ | ||
Lighting Off | ||
Blend One Zero | ||
|
||
Pass | ||
{ | ||
CGPROGRAM | ||
#include "UnityCustomRenderTexture.cginc" | ||
|
||
#pragma vertex CustomRenderTextureVertexShader | ||
#pragma fragment frag | ||
|
||
float3 _Center; | ||
float3 _Extent; | ||
|
||
//WHY IS NEAREST POINT ON THE SURFACE OF A CUBE SO HARD | ||
float4 frag(v2f_customrendertexture IN) : COLOR | ||
{ | ||
float4 col = tex3D(_SelfTexture3D, IN.globalTexcoord + float3(0, 0, 0.5/_CustomRenderTextureDepth)); | ||
float3 boxSpacePos = (IN.globalTexcoord - _Center.xyz); | ||
float distMultiplier = 1.0; | ||
|
||
if(abs(boxSpacePos.x) < _Extent.x && | ||
abs(boxSpacePos.y) < _Extent.y && | ||
abs(boxSpacePos.z) < _Extent.z){ | ||
float maxCoord = max(max(abs(boxSpacePos.x), | ||
abs(boxSpacePos.y)), | ||
abs(boxSpacePos.z)); | ||
if(maxCoord == abs(boxSpacePos.x)){ | ||
boxSpacePos.x = sign(boxSpacePos.x) * _Extent.x; | ||
}else if(maxCoord == abs(boxSpacePos.y)){ | ||
boxSpacePos.y = sign(boxSpacePos.y) * _Extent.y; | ||
}else if(maxCoord == abs(boxSpacePos.z)){ | ||
boxSpacePos.z = sign(boxSpacePos.z) * _Extent.z; | ||
} | ||
distMultiplier *= -1.0; | ||
} else { | ||
boxSpacePos = float3(sign(boxSpacePos.x) * min(abs(boxSpacePos.x), _Extent.x), | ||
sign(boxSpacePos.y) * min(abs(boxSpacePos.y), _Extent.y), | ||
sign(boxSpacePos.z) * min(abs(boxSpacePos.z), _Extent.z)); | ||
} | ||
|
||
float3 posOnSurface = (boxSpacePos+_Center.xyz); | ||
float newDistance = length(IN.globalTexcoord-posOnSurface) * distMultiplier; | ||
if(newDistance<col.a){ | ||
col.rgb = (IN.globalTexcoord-posOnSurface)/newDistance; | ||
col.a = newDistance; | ||
} | ||
return col; | ||
} | ||
ENDCG | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.