├── LICENSE.md ├── README.md └── assets └── maujoe.custom_gradient_texture ├── LICENSE.md ├── README.md ├── custom_gradient_texture.gd ├── example.tres ├── icon.jpg └── info.jpg /LICENSE.md: -------------------------------------------------------------------------------- 1 | Released under the MIT License: 2 | 3 | Copyright (c) 2019 Jaccomo Lorenz (Maujoe) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Godot Custom Gradient Texture 2 | 3 | A simple resource for the godot game engine that allows to create linear, radial and rectangular gradient textures unlike the the build-in gradient texture (at this point of time). 4 | 5 | ##### Note: 6 | 7 | - The gradient color doesn't update in the editor due to some issues but the texture can be updated manually by changing one of the other settings or by clicken to the "Click To Update Texture" property in the inspector (See below). 8 | - generating big textures can take 2-3 seconds 9 | 10 | ## How to create and use the texture: 11 | ![See info.jpg](/assets/maujoe.custom_gradient_texture/info.jpg) 12 | -------------------------------------------------------------------------------- /assets/maujoe.custom_gradient_texture/LICENSE.md: -------------------------------------------------------------------------------- 1 | Released under the MIT License: 2 | 3 | Copyright (c) 2019 Jaccomo Lorenz (Maujoe) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /assets/maujoe.custom_gradient_texture/README.md: -------------------------------------------------------------------------------- 1 | # Godot Custom Gradient Texture 2 | 3 | A simple resource for the godot game engine that allows to create linear, radial and rectangular gradient textures unlike the the build-in gradient texture (at this point of time). 4 | 5 | ##### Note: 6 | 7 | - The gradient color doesn't update in the editor due to some issues but the texture can be updated manually by changing one of the other settings or by clicken to the "Click To Update Texture" property in the inspector (See below). 8 | - generating big textures can take 2-3 seconds 9 | 10 | ## How to create and use the texture: 11 | ![See info.jpg](info.jpg) 12 | -------------------------------------------------------------------------------- /assets/maujoe.custom_gradient_texture/custom_gradient_texture.gd: -------------------------------------------------------------------------------- 1 | tool 2 | extends ImageTexture 3 | class_name CustomGradientTexture 4 | 5 | enum GradientType {LINEAR, RADIAL, RECTANGULAR} 6 | 7 | # Workaround for manual texture update 8 | # because updating it while editing the gradient doesn't work well 9 | enum Btn {ClickToUpdateTexture} 10 | export(bool) var click_to_update_texture = null setget _update_texture 11 | 12 | export(GradientType) var type = GradientType.LINEAR setget set_type 13 | export var size = Vector2(256, 256) setget set_size 14 | export(Gradient) var gradient setget set_gradient 15 | 16 | var data 17 | 18 | func _init(): 19 | data = Image.new() 20 | data.create(size.x, size.y, false, Image.FORMAT_RGBA8) 21 | 22 | func _update(): 23 | if not gradient: 24 | return 25 | 26 | data.lock() 27 | var radius = (size - Vector2(1.0, 1.0)) / 2 28 | var ratio = size.x / size.y 29 | 30 | if type == GradientType.LINEAR: 31 | for x in range(size.x): 32 | var ofs = float(x) / (size.x - 1) 33 | var color = gradient.interpolate(ofs) 34 | 35 | for y in range(size.y): 36 | data.set_pixel(x, y, color) 37 | 38 | elif type == GradientType.RADIAL: 39 | for x in range(size.x): 40 | for y in range(size.y): 41 | var dist = Vector2(x / ratio, y).distance_to(Vector2(radius.x / ratio, radius.y)) 42 | var ofs = dist / radius.y 43 | var color = gradient.interpolate(ofs) 44 | data.set_pixel(x, y, color) 45 | 46 | # Rectangular 47 | else: 48 | for x in range(size.x): 49 | for y in range(size.y): 50 | var dist_x = Vector2(x, 0).distance_to(Vector2(radius.x, 0)) 51 | var dist_y = Vector2(0, y).distance_to(Vector2(0, radius.y)) 52 | var ofs 53 | 54 | if dist_x > dist_y * ratio: 55 | ofs = dist_x / radius.x 56 | else: 57 | ofs = dist_y / radius.y 58 | 59 | var color = gradient.interpolate(ofs) 60 | data.set_pixel(x, y, color) 61 | 62 | data.unlock() 63 | create_from_image(data) 64 | 65 | # Workaournd that allow to manual update the texture 66 | #warning-ignore:unused_argument 67 | func _update_texture(value): 68 | _update(); 69 | 70 | func set_type(value): 71 | type = value 72 | _update() 73 | 74 | func set_size(value): 75 | size = value 76 | 77 | if size.x > 4096: 78 | size.x = 4096 79 | if size.y > 4096: 80 | size.y = 4096 81 | 82 | data.resize(size.x, size.y) 83 | _update() 84 | 85 | func set_gradient(value): 86 | gradient = value 87 | _update() 88 | -------------------------------------------------------------------------------- /assets/maujoe.custom_gradient_texture/icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaccomoLorenz/godot-custom-gradient-texture/c20e183e3a02c7efdefe4f78761b7e893703fbef/assets/maujoe.custom_gradient_texture/icon.jpg -------------------------------------------------------------------------------- /assets/maujoe.custom_gradient_texture/info.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JaccomoLorenz/godot-custom-gradient-texture/c20e183e3a02c7efdefe4f78761b7e893703fbef/assets/maujoe.custom_gradient_texture/info.jpg --------------------------------------------------------------------------------