├── shader.png ├── shader2.png ├── shader3.png ├── README.md └── moisture.txt /shader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brukoslav/MagicaVoxel_shader/HEAD/shader.png -------------------------------------------------------------------------------- /shader2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brukoslav/MagicaVoxel_shader/HEAD/shader2.png -------------------------------------------------------------------------------- /shader3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brukoslav/MagicaVoxel_shader/HEAD/shader3.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Moisture Magica voxel Shader 2 | Repository for magica voxel shader. 3 | 4 | ## Installation 5 | 6 | Install the shader by copying the file `moisture.txt` into the `shader` directory of your MagicaVoxel installation. 7 | 8 | ## Usage 9 | 10 | After installing the shader you should see them in the shader menu. 11 | 12 | Use them according to the description below and try mixing them up for better results. You can ask me anything in [twitter](https://twitter.com/EKremlinois). 13 | 14 | ### Moisture Shader 15 | 16 | Inspired on [shader by patStar](https://github.com/patStar) (thanks!). 17 | This shader let your create the effect of moisiture on your voxel buildings. 18 | 19 | ![...](shader2.png?raw=true "Title") 20 | 21 | There are 6 parameters: 22 | 23 | | Parameter | Range | Description | 24 | | ------ | ------ | ------ | 25 | | Modo | 0 to 1 |Moisture will grow downwards (0) or upwards (1) .| 26 | | Avance | 0 to 1 |How speed moisture will grow in each step. | 27 | | Random Seed | 0 to 1000000| Using the shader on the same scene will always yield the exact same result as long as you don't change this value. Play with this to yield different patterns on the same scene. | 28 | | Additional Colors | -255 to 255 | You may paint the different layers of your plant in different colors. The base Color will be the selected color but you can define a range of colors following or preceding the selected color here. | 29 | | Avance Colors | 0 to 1 | How speed other colors will appear in your moisture. | 30 | | Unif Colors | 0 to 1 | Bigger values give you a more random other-colors moisture, lower values seems more unified. | 31 | 32 | ### Tips 33 | 34 | ![...](shader3.png?raw=true "Title") 35 | -------------------------------------------------------------------------------- /moisture.txt: -------------------------------------------------------------------------------- 1 | // xs_begin 2 | // author : '@brukoslav' 3 | // arg : {id = '0' name = 'Modo' value = '0' range = '0 3' step = '1' decimal = '0' } 4 | // arg : {id = '1' name = 'Avance' value = '0.5' range = '0 1' step = '0.01' decimal = '1' } 5 | // arg : { id = '2' name = 'Random Seed' value = '123' range = '0 1000000' step = '1' decimal = '0' } 6 | // arg : { id = '3' name = 'Additional Colors' value = '0' range = '-255 255' step = '1' decimal = '0' } 7 | // arg : { id = '4' name = 'Avance Colors' value = '0.5' range = '0 1' step = '0.01' decimal = '2' } 8 | // arg : { id = '5' name = 'Unif Colors' value = '0.5' range = '0 1' step = '0.01' decimal = '2' } 9 | // xs_end 10 | 11 | float modo = float(iArgs[0]); 12 | float avance = float(iArgs[1]); 13 | float seed = float(iArgs[2]); 14 | float colorRange = float(iArgs[3]); 15 | float avanceColor = float(iArgs[4]); 16 | float avanceColorMedio = float(iArgs[5]); 17 | 18 | bool isGrowColor(vec3 v){ 19 | return voxel(v) >= min(i_color_index, i_color_index + colorRange) && voxel(v) <= max(i_color_index, i_color_index + colorRange); 20 | } 21 | 22 | float dir() { 23 | return (1 - modo*2); 24 | } 25 | 26 | //Add more randomness 27 | float totalMios(vec3 v) { 28 | float a = 0; 29 | float distance = 10; 30 | for(float x=-distance; x<=distance;x+=1.){ 31 | for(float y=-distance; y<=distance;y+=1.){ 32 | for(float z=-distance; z<=distance;z+=1.){ 33 | if (isGrowColor(vec3(v.x+x,v.y+y,v.z+z))) { 34 | a = a + voxel(vec3(v.x+x,v.y+y,v.z+z)); 35 | } 36 | } 37 | } 38 | } 39 | return a; 40 | } 41 | 42 | float random(vec3 v){ 43 | float n = v.x*v.y*v.z + seed; 44 | return abs(fract(sin(1./tan(n) + (totalMios(v) + seed) * 1235.342))); 45 | } 46 | 47 | float random2(vec3 v){ 48 | float n = v.x*v.y*v.z + seed + 1500; 49 | return abs(fract(sin(1./tan(n) + (totalMios(v) + seed) * 1235.342))); 50 | } 51 | 52 | 53 | bool shouldBePlaced(vec3 v){ 54 | float dif = (i_color_index + colorRange - voxel(v)); 55 | if(isGrowColor(vec3(v.x,v.y,v.z + dir() )) && !isGrowColor(v) && random(v) < avance){ 56 | seed += 1; 57 | return true; 58 | } 59 | return false; 60 | } 61 | 62 | bool ladosParecidos(vec3 v) { 63 | //Si existe una (o dos?) vecina que sea de ese color 64 | int vecina = 0; 65 | if (voxel(vec3(v.x+1.,v.y,v.z)) == voxel(v) + 1) { 66 | vecina++; 67 | } 68 | if (voxel(vec3(v.x-1.,v.y,v.z)) == voxel(v) + 1) { 69 | vecina++; 70 | } 71 | if (voxel(vec3(v.x,v.y+1.,v.z)) == voxel(v) + 1) { 72 | vecina++; 73 | } 74 | if (voxel(vec3(v.x,v.y-1.,v.z)) == voxel(v) + 1) { 75 | vecina++; 76 | } 77 | if (vecina>0) { 78 | return true; 79 | } else { 80 | if(random2(v) > avanceColorMedio) { 81 | return true; 82 | } else { 83 | return false; 84 | } 85 | } 86 | } 87 | 88 | float map(vec3 v) { 89 | //Si no hay nada arriba o es mayor, aumenta 90 | if ( isGrowColor(v) && ladosParecidos(v) && (!isGrowColor(vec3(v.x,v.y,v.z + dir())) || voxel(v) < voxel(vec3(v.x,v.y,v.z + dir())) ) ) { 91 | if (random(v) < avanceColor) { 92 | return min(i_color_index + colorRange,voxel(v) + 1); 93 | } else { 94 | return voxel(v); 95 | } 96 | } else if(shouldBePlaced(v) && voxel(v)!=0 && !isGrowColor(v)){ 97 | return i_color_index; 98 | //if(random(v) < avanceColor*(i_color_index + colorRange - voxel(v))) { 99 | // return min(i_color_index + colorRange, voxel(vec3(v.x,v.y,v.z + dir() )) + 1); 100 | //} else { 101 | // return voxel(vec3(v.x,v.y,v.z - dir() )); 102 | //} 103 | } else { 104 | return voxel(v); 105 | } 106 | } 107 | --------------------------------------------------------------------------------