Skip to content

Instantly share code, notes, and snippets.

@PossiblyAShrub
Created July 14, 2020 20:45
Show Gist options
  • Save PossiblyAShrub/1bf455acd3738f5681c17c99ddd1127d to your computer and use it in GitHub Desktop.
Save PossiblyAShrub/1bf455acd3738f5681c17c99ddd1127d to your computer and use it in GitHub Desktop.
// Instructions
// 1. Download into the folder 'shader' in your MagicaVoxel install folder
// 2. Open the shaders panel on the right
// 3. Cick the cake shader and press play! Your model insides are now cake! (Colors not included)
// Copyright 2020 Aidan (@PossiblyAShrub)
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
// following conditions: The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// xs_begin
// author : '@PossiblyAShrub'
// arg : { id = '0' name = 'Num Layers' value = '8' range = '1 20' step = '1' decimal = '0' }
// xs_end
//===== user args =====
// uniform float i_args[8];
//===== built-in args =====
// uniform vec3 i_volume_size; // volume size [1-256]
// uniform float i_color_index; // color index [0-255]
// uniform vec3 i_mirror; // mirror mode [0,1]
// uniform vec3 i_axis; // axis mode [0,1]
// uniform float i_iter; // iteration index
//===== built-in functions =====
// float voxel( vec3 v ); // get voxel color index at position v
float map(vec3 v) {
// dump args into named variables
float numLayers = i_args[0];
// find all 6 neighbors
bool up = voxel(v + vec3(0, 1, 0)) != 0;
bool down = voxel(v + vec3(0, -1, 0)) != 0;
bool right = voxel(v + vec3(1, 0, 0)) != 0;
bool left = voxel(v + vec3(-1, 0, 0)) != 0;
bool front = voxel(v + vec3(0, 0, 1)) != 0;
bool back = voxel(v + vec3(0, 0, -1)) != 0;
// if all neighbors are found then we are inside the model
// so... CAKE
if (up && down && right && left && front && back) {
// then do some math to find what layer we're on
return i_color_index + floor((v.z / i_volume_size.z) * numLayers);
}
// otherwise leave things as we found them - they will never notice!
return voxel(v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment