It looks like you're new here. If you want to get involved, click one of these buttons!
application:setBackgroundColor(0x2288aa) clownTexture=Texture.new("clown8.png") palettes=RenderTarget.new(256,256) -- 256 palettes of 256 colours each, so far I'm only using 1 clown=Pixel.new(clownTexture) clown:setPosition(100,100) clown:setScale(3) shaderV=[[ attribute highp vec3 vVertex; attribute mediump vec2 vTexCoord; uniform highp mat4 vMatrix; varying mediump vec2 fTexCoord; void main() { vec4 vertex = vec4(vVertex,1.0); gl_Position = vMatrix*vertex; fTexCoord=vTexCoord; } ]] paletteF=[[ uniform lowp sampler2D fTexture; uniform lowp sampler2D fPalettes; uniform float palette; varying mediump vec2 fTexCoord; void main() { lowp vec4 colour8 = texture2D(fTexture,fTexCoord); lowp vec2 index = vec2(colour8.r,palette); lowp vec4 colour32 = texture2D(fPalettes,index); gl_FragColor = colour32; } ]] local result,paletteShader=pcall(Shader.new,shaderV,paletteF,Shader.FLAG_FROM_CODE,{ {name="vMatrix",type=Shader.CMATRIX,sys=Shader.SYS_WVP,vertex=true}, {name="fTexture",type=Shader.CTEXTURE,vertex=false}, {name="fPalettes",type=Shader.CTEXTURE,vertex=false}, {name="palette",type=Shader.CFLOAT,vertex=false}, }, {{name="vVertex",type=Shader.DFLOAT,mult=3,slot=0,offset=0}, {name="vColor",type=Shader.DUBYTE,mult=4,slot=1,offset=0}, {name="vTexCoord",type=Shader.DFLOAT,mult=2,slot=2,offset=0}, }) if not result then print("Shader error:",paletteShader) end clown:setTexture(palettes,1) clown:setShader(paletteShader) stage:addChild(clown) function setPalette(p,c) palettes:clear(0xffffff,0) local pixel=Pixel.new() for loop=1,#c do pixel:setPosition(loop-1,p-1) pixel:setColor(c[loop][1],c[loop][2] or 1) palettes:draw(pixel) end end paletteNo=1 myPalette={{0x000000},{0xffffff},{0xffbf5f},{0xff9f3f},{0xff5f1f},{0xbf5f3f},{0x9f1f1f},{0x9f9f9f},{0x5f5f5f},{0xff7676},{0xff00ff,0}} setPalette(paletteNo,myPalette) clown:setShaderConstant("palette",Shader.CFLOAT,1,paletteNo-1) count=0 function gameLoop(e) count=count+1 if count%120==0 then myPalette[2]={math.random(0xffffff)} setPalette(paletteNo,myPalette) end end stage:addEventListener(Event.ENTER_FRAME,gameLoop) |
Likes: antix
Comments
https://www.dropbox.com/s/fpcyj3hj56rgaui/clown8.zip?dl=0
https://deluxepixel.com
https://deluxepixel.com
Couldn't get it to load into an art package, but added it to Gideros project anyway... nope. Just not working. :-(
Here is a rar of the entire project:
https://www.dropbox.com/s/v4riik4ryxb8l2x/PalettesClown.rar?dl=0
https://deluxepixel.com
good example to get to know shaders better.
Likes: SinisterSoft
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: SinisterSoft
https://forum.giderosmobile.com/discussion/8473/psprites/p1?new=1
https://deluxepixel.com