About Monkey 2 › Forums › Monkey 2 Development › Idea for a function to load shaders.
This topic contains 3 replies, has 3 voices, and was last updated by
cocon 2 years, 6 months ago.
-
AuthorPosts
-
October 17, 2016 at 8:30 pm #4490
Initially I created this for an OpenGL example, perhaps this could go into mojo.graphics.glutil since it’s pretty reusable code.
Monkey1234567891011Function glLoadProgram:GLuint(vertexSource:String, fragmentSource:String)Local vs := mojo.graphics.glutil.glCompile(GL_VERTEX_SHADER, vertexSource)Local fs := mojo.graphics.glutil. glCompile(GL_FRAGMENT_SHADER, fragmentSource)Local program := glCreateProgram()glAttachShader(program, vs)glAttachShader(program, fs)mojo.graphics.glutil.glLink(program)glDeleteShader(vs)glDeleteShader(fs)Return programEndOctober 17, 2016 at 11:43 pm #4494The glutil stuff wasn’t really meant to be ‘public’, but it would definitely be nice to have.
Let me clean it up a bit, perhaps move it to GLES20 module(?) etc, then we can start adding fun stuff to it.
October 18, 2016 at 10:59 am #4509Mark… Further to this:
I noticed the general rendering of mojo is opengl to a buffer then final shader to screen.
Is there a possibility of opening this shader up so added ‘screen’ shader could be created. E.G. blurs, color to mono, etc
Just a thought
October 18, 2016 at 3:45 pm #4512On what Adam said, it would be very interesting to use custom user shaders at will. It reminds me of Minecraft where is heavily modded on shaders, beyond any initial plan. I think that this gets closer to a material/shader system (like Unity does).
Here is now a silly hack to make it work, theoretically it should work, but I have not compiled it yet.
In the file mojo.graphics.canvas
Monkey123456789101112131415161718192021222324252627282930313233343536' This is the default shader of the Monkey renderer (only for shapes)Field _shader:Shader' This user shader field is added and two methods as well' to assign/deassign a value to the object.Field _userShader:ShaderMethod EnableUserShader(s:Shader)_userShader = sEndMethod DisableUserShader()_userShader = NullEnd' Then there will be a smart private property to return either the' default shader or the user shader.'Property DefaultShader:ShaderIf _userShader <> Null Then Return _userShaderReturn _shaderEnd' Then all of the methods that use the method AddDrawOp will be changed to use' the smart private property.Method DrawRect( x:Float,y:Float,w:Float,h:Float )Local x0:=x,y0:=y,x1:=x+w,y1:=y+hAddDrawOp( DefaultShader,_material,_blendMode,_textureFilter,4,1 )' etc ...End' For the record this is the actual method that accepts the shader.' perhaps instead of changing ALL of the draw methods that use the AddDrawOp,' the hack could be injected here instead.Method AddDrawOp( shader:Shader,material:UniformBlock,blendMode:BlendMode,textureFilter:TextureFilter,primOrder:int,primCount:Int ) -
AuthorPosts
You must be logged in to reply to this topic.