Version 1.0 Author JoaoB ("João B" on Brazilian forums) Release Date May 9th 2010
Introduction "A shader is a RGSS class with special methods used to apply pixel-level effects in bitmaps." Sorry, but there's no way to hardware-accelerate this script (well, RGSS itself isn't hardware-accelerated). This script is slow, specially in RGSS2, but there are some uses.
Features
Easy shader creation using the def [tt]Shader::apply(x, y)[/tt]
#=============================================================================== # class Shader #=============================================================================== class Shader
def self.apply(x, y) return @@bitmap.get_pixel(x, y) end
def self.bitmap=(bitmap) @@bitmap = bitmap end
def self.bitmap2=(bitmap2) @@bitmap2 = bitmap end
def self.need_two_bitmaps return false end
def self.size if need_two_bitmaps width = [@@bitmap.width, @@bitmap2.width].max height = [@@bitmap.height, @@bitmap2.height].max else width = @@bitmap.width height = @@bitmap.height end return [width, height] end
def self.parameters=(params) @@parameters = params end end
#=============================================================================== # Bitmap mods #=============================================================================== class Bitmap def apply_shader(shader, other_bitmap = nil, parameters = {}) shader.parameters = parameters return if shader.need_two_bitmaps and not other_bitmap.is_a?(Bitmap) need_two_bitmaps = shader.need_two_bitmaps
def copy copy_bitmap = Bitmap.new(self.width, self.height) copy_bitmap.blt(0, 0, self, Rect.new(0, 0, self.width, self.height)) return copy_bitmap end end #=============================================================================== # End of script #===============================================================================
Custom Shader
Custom Shader
CODE
#=============================================================================== # RGSS Shaders System (shader definition) #------------------------------------------------------------------------------- # Author: JoaoB # WARNING: Place this script AFTER "Shader System" # Script where the shaders will be defined #===============================================================================
def self.apply(x, y) color = @@bitmap.get_pixel(x, y) bw = color.red*0.3 + color.green*0.59 + color.blue*0.11 return Color.new(bw, bw, bw, color.alpha) end
end
#=============================================================================== # End of script #===============================================================================
Customization Well, the customization possibilities are almost infinite. I said "almost" because it depends on the bitmap size, shader complexity and other things. Attached is an HTML file with instruction.
Compatibility It's compatible with any other script you post. In addiction, there's the def [tt]Bitmap::copy[/tt], which returns a copy of the bitmap, not the bitmap itself (yes, there are differences).
Screenshot There are various effects you can achieve with this script; no number of screenshots can show all of them.
Screenshot
This is a screenshot of one of the shaders that come with the script.
The same shader, on RMVX.
Installation To install the script, copy the scripts Shader System and Custom Shader in that order. To create and apply the shaders, see the attached HTML file.
FAQ Q: Does it work on RMVX? A: Yes, it does, but it's much slower.
Terms and Conditions Well, you can use it freely in your game, but please, give me credit if you use it and let me know if you post it in another forum.
Credits The system was made by me, but the inspiration came from Adobe Pixel Bender.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.