Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Any info on writing agk shaders?

Author
Message
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 22nd Jan 2013 18:04
Paul : it's my conclusion too. I don't see big performances problems with or without it

Thanks !
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 22nd Jan 2013 19:26
Back and a bit more rested then yesterday

Quote: "EDIT : are we sure that pixels "merging" from texture0 and texture1 takes more time than calculate the distance ? And shaders processing is after clipping and culling in the pipeline so ... maybe it's not necessary "
Quote: "Shaders in general don't like branching, so it can be quicker to apply a technique to all pixels rather than say "if this pixel is here do this". Since parts of the model that are very far away will have fewer pixels covering them they will have less impact on the pixel shader anyway. The biggest performance impact is probably from the pixels close to the screen looking up 2 textures instead of 1, which is unavoidable for the result you want, so I wouldn't worry about it. "

You get a distance with this as its already done in the shader.
(gl_FragCoord.z/gl_FragCoord.w)
i dont know how you guys would do this caculation but this is fast.
these two are clipping plane and end parameter.
This is how you would add a distance based fog effect to a shader.

gl_FragColor = mix(texture2D(texture0, texCoord0),vec4(1.0,1.0,1.0,0.0),(gl_FragCoord.z/gl_FragCoord.w)/50.0);

This line adds an fast distance based fog effect to your shader.
There is a complicated way of doing things and the easy way

And also as a note is that you should do all calculations that can be done per vertex in the vertex shader and as little as possible in the pixel shader.

Quote: "EDIT 3 : GRRRR Damn floats ... was using "1" instead of "1.0" ... i will fix the code in my previous posts "

Android is extremely case sensetiv
To bad i went to bed befor reading this
Could have saved you some trouble
Quote: "That's right, althrough, it's really easy what MikeMax did. It's simply applying one, tiled texture, plus the original mesh texture. Then you "blend" them, and you get the result above."

Its the visuals we are after and not the means of getting there
I think its great that he share wath he did even if its simpel.
I started an overcomplicated shader that did the same result but feelt a bit overworked

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 22nd Jan 2013 19:58
Quote: "gl_FragColor = mix(texture2D(texture0, texCoord0),vec4(1.0,1.0,1.0,0.0),(gl_FragCoord.z/gl_FragCoord.w)/50.0);"


Thanks for the fog effect Cliff, it was my next thing in roadmap to apply clipping planes

I will try it

Quote: "Quote: "That's right, althrough, it's really easy what MikeMax did. It's simply applying one, tiled texture, plus the original mesh texture. Then you "blend" them, and you get the result above."
Its the visuals we are after and not the means of getting there
I think its great that he share wath he did even if its simpel.
I started an overcomplicated shader that did the same result but feelt a bit overworked "


I love the KISS principle : KEEP IT SIMPLE and STUPID :p that's the way a code works better and mainly faster ... nothing more.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 22nd Jan 2013 20:07
Quote: "Thanks for the fog effect Cliff, it was my next thing in roadmap to apply clipping planes

I will try it "

You know that iam a mind reader

If you nead something yust ask so will i try to help

How is your performance on droid and windows with the shader on ?

When i get the time so will i fool around and see wath i can do more to the shader you are using.

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 22nd Jan 2013 22:04 Edited at: 22nd Jan 2013 22:13
For the fog effect it works ... but doesn't give the same effect as the real glFog due to the fact that it doesn't create a fog vertical plane and only apply fog effect on terrain meshes (rendered pixels) ... and partial clipped objects are not hidden by the fog effect :p (normal because they have no more pixel to display at this clipped distance :p). So it will difficult to create the effect i want with shaders only (taking care of the skybox which is small but with DepthWrite deactivated) ...

I have already make few vertical planes (with additive alpha) oriented and sized with camera and FOV which works almost well for a fog effect .. the problem is the sky which is fogged too (and i don't want that).. i tried to play with Depth Read/Write modes but no success.

There is certainly a solution !

Maybe ... using your shader on the terrain and adding a real vertical plane (with the same fog shader to create an opaque plane with the same ending fog color) just before the far clip plane (of CamRange) and applying a shader on this real plane which will verify the alpha value of 254 (previously set on the sky texture or object) to let the sky pixel to render instead of the real (clip) vertical plane ... ouch ! lol (sorry for my english and my explanations lol)

if you have any idea ...?

to remind it, the goal is : to reduce the camrange and having everything after hidden by a fog vertical plane .. while having the sky correctly displayed

Any chance to see glFog implemented in next beta release ? (lol)

Edit : maybe an idea with my planes ... defining a height (to prevent fogging the sky) for them with everything clipped behind combined with terrain shader). i will make a try.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 22nd Jan 2013 22:20 Edited at: 22nd Jan 2013 22:22
I havent tryed this!

vec4(0.0,0.0,0.0,1.0)

The last one is alpha color and i dont know if you can apply alpha transparency in the shader on the top of my head?

Does this work with blending the mesh in to the skybox?

Dont forget to apply transparency to the mesh before trying.

gl_FragColor = mix(texture2D(texture0, texCoord0),vec4(0.0,0.0,0.0,1.0),(gl_FragCoord.z/gl_FragCoord.w)/50.0);

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 22nd Jan 2013 23:19
Quote: "Does this work with blending the mesh in to the skybox?"


Yes it could do the trick and gradient alpha is working with shaders but apparently .. setting the mesh as transparent deactivate the depth write (that's the goal lol !) so all object behind mesh are visible lol without any mesh behind it could be cool .. i will test with depth read and write different parameters to test
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 22nd Jan 2013 23:25
Quote: "setting the mesh as transparent deactivate the depth write (that's the goal lol !) so all object behind mesh are visible lol without any mesh behind it could be cool .. i will test with depth read and write different parameters to test"

lmao

I have also experienced some weird stuff in my editor when applying transparency to objects
Quote: "setting the mesh as transparent deactivate the depth write (that's the goal lol !) "

Try to set objects depth write after the transparency?
Transparency automaticly turns it off

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 23rd Jan 2013 00:26
Ok .. the visual result is not as expected ... but forcing the depthwrite after the transparency works well

But the problem is : the Tegra2 Devices (and there is a lot of devices equipped with it) don't manage well alpha transparencies ... (40fps without and 17fps with "alpha transparency fog" )

so this solution is unacceptable !

i will put this fog/fading problem aside for the moment
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 23rd Jan 2013 00:52
If I've understood what you are trying to do correctly, could you apply a fog shader to the sky box so that it becomes the fog color below a certain height?
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 23rd Jan 2013 01:43
ho ! nice idea ! i will take a look at this
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 23rd Jan 2013 13:10
It works but still not as expected visually , i need to improve it to make a part of the sky to be gradient ...
Sharisu
12
Years of Service
User Offline
Joined: 9th Nov 2011
Location: BY, Minsk
Posted: 3rd Feb 2013 16:02
Question about the shader. Can I use my shader with transparency?
gl_FragColor = vec4 (color, alpha.w);
But the image is not affected.
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 13th Feb 2013 15:02
Quote: "Question about the shader. Can I use my shader with transparency?
gl_FragColor = vec4 (color, alpha.w);
But the image is not affected. "

Wath are you trying to do ?
And dont your object have an texture as its applied in the shader to the object also.
You only seam to have the object color?

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 15th Feb 2013 12:03
Made an pretty cool discovery today
So if anyone is writing a shader for agk so is this an must

This code part should be at the top of your pixel shader.


Now do you wonder wath this code does ?
It simply first checks if the device is an mobile device.
then does it check if the device supports high precicion calculations or not.
And if it dosent so does it set it to medium precision.
I only tested this on some parts of my segments on an test map and i got an increase in 10 fps by doing this.

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Feb 2013 13:24
That looks like some vital info Cliff, looks like being ill isn't slowing you down too much


this.mess = abs(sin(times#))
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 15th Feb 2013 13:30
I had a mail from Blackberry this morning about GPUs. Apparently you need to set a lot of conditionals for the two different GPUs in different devices. Just to add to the general confusion.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 15th Feb 2013 14:41
Quote: "That looks like some vital info Cliff, looks like being ill isn't slowing you down too much "

Only that iam slow in the head by the illnes and having a hard time focusing on a single large project
Iam pretty worried about the surgery on monday and this helps me to not think to much about it
Quote: "I had a mail from Blackberry this morning about GPUs. Apparently you need to set a lot of conditionals for the two different GPUs in different devices. Just to add to the general confusion."

Its a mess to write for multiple devices
precision highp float
precision mediump float
precision lowp float
is not supported on computers and will crash your agk app.
Thats why i made this as it checks first if its an mobile device.
#ifdef GL_ES

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 8th Mar 2013 15:45
IS anyone has a good shader to create shiny effect ?
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 8th Mar 2013 20:20
I have zero experience of writing shaders. I would be very grateful for someone to provide me with a shader that could simply rotate the UV on a texture as this isn't available for AppGameKit yet...

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 12th Mar 2013 17:42
Quote: "I have zero experience of writing shaders. I would be very grateful for someone to provide me with a shader that could simply rotate the UV on a texture as this isn't available for AppGameKit yet..."

Hi my friend i havent bin around for a while
Do you mean mirrored?



If you look at this part !
uv0Varying = uv * uvBounds0.xy + uvBounds0.zw;

So if iam not wrong?
uv is the start coord!
Usually are these 0.0 and 0.0.
Change them to 1.0 and 0.0.

uvBounds0.xy
is the end coords.
1.0 and 1.0.
If you change the first one to 0.0 so should you now have an mirrored texture.

The easiest way is to make an uniform like this.
uniform vec4 myuv;
The do you pass your uv data in to the shader from agk.

should look like this.
uv0Varying = myuv + uvBounds0.zw;

uvBounds0.zw
is only used if your texture is an atlas texture.

so if its not so could it look like this.
uv0Varying = myuv;

And please bare in mind that i havent tested this and it could have some huge faults as iam not on my usuall computer with all my shader stuff.
So this is simply on the top of my head

Quote: "IS anyone has a good shader to create shiny effect ?"

In wath way do you mean shiny ?
Glossy or simply extremely shiny like chrome?

I dont know if i have the time to do a shader but i strongly recomend that you check the 2 books i tipped earlier about.
Highly recomended is opengl es 2.0 programing guide by aftab munshi.

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 12th Mar 2013 22:43
Hi Cliff,

No, I mean just scroll the texture (like setting the UV offsets) which there is no AppGameKit command for yet.

This would probably start me off playing with shaders I think

lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 13th Mar 2013 11:05
I have a question for you Cliff

I have a simple 3d scene going with some basic shapes and planes. When I simply use setObjectLightMode(obj, 1) and put directional and pointlights on the scene it all works great. The objects are affected by the light like you would expect.

Then I tried the shaders that came with the 3d-example in AppGameKit and made simple lightmaps for some objects, but all I could see then was essentially the lightmap embossed on the object and the object no longer responded to where the pointlight moved to.

Is this because the shaders are too basic or is that what lightmaps are supposed to do? I'm quite clueless when it comes to 3d but I'm trying to learn

Thanks in advance

My hovercraft is full of eels
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 13th Mar 2013 11:30
yes you have to add lights management in your lightmap shader The basic shaders manage lights but if you replace it ...so i've also done it for my detail map which didn't take lights into account but now the problem is that it's slowing down a lot on mobile devices... (2 textures + lights) :p maybe i will have to manage the distance to prevent working on all displayed pixels ... but what is the interest of affecting lights over a lightmapped object .... ?
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 13th Mar 2013 14:31 Edited at: 13th Mar 2013 19:31
Ok I see, thanks.

No real interest I'm testing various things to see what happens.

What I'm really after is what nz0 mentions, to in the end create a animate-texture function by scrolling UV by use of shaders, but at the same time use lighting like it works at default.

Even when I don't use a lightmap image but load the shaders from the 3d-example the light doesn't affect objects.

So yeah, what I want to make is shaders that work like the default ones in AppGameKit as far as shading and lighteffects but be able to scroll the textures with UV.


Edit: I think I'm on my way to succeeding

My hovercraft is full of eels
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 13th Mar 2013 23:44 Edited at: 14th Mar 2013 15:45
So I managed to animate textures.

Mind you this was a test, but it was successful. I'll be making a set of dynamic functions for animating textures, hopefully similar to AnimateSprite.

For now you can test this and see how it's done. I haven't really commented on anything in the code yet but if there are any questions just ask. I'll be working on the full set of animation-functions instead of perfecting this example.

Please mind that the image I used to animate isn't really set up for it, it's uneven and everything but it works to show this off.

There's a light at the mouse-pointer just to prove that it's a 3d-plane and not a sprite

The entire project is included in a RAR, code is posted here if anyone is just curious.



Vertex Shader:



Pixel Shader:



Have fun

My hovercraft is full of eels

Attachments

Login to view attachments
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 14th Mar 2013 15:48
Problem with the above vertex-shader:

It works fine on pc but not on the Android player 1088. The texture is off center with each frame.

If anyone knows what the difference between Android and PC when passing uvVarying from the vertex to pixel shader would be very helpful!

My hovercraft is full of eels
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 14th Mar 2013 16:09 Edited at: 14th Mar 2013 18:20
New Shader: Ripple Effect (1 texture, 1 pointlight, 1 directional light)



To use put this in your main loop:


or put a float variable in place of timer() and adjust it yourself.

Vertex shader:



Pixel Shader:


My hovercraft is full of eels

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 14th Mar 2013 16:28
Cool! I can see this being useful when I get to doing 3D stuff.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 14th Mar 2013 17:50
Quote: "If anyone knows what the difference between Android and PC when passing uvVarying from the vertex to pixel shader would be very helpful!"


The big difference i saw is that you have to explicitly write all your numbers as float values everywhere in shaders in android ( "1.0" instead of just "1")

Your ripple effect is great !

No idea for a shiny effect ? :p
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 14th Mar 2013 17:55 Edited at: 14th Mar 2013 17:56
It would be cool to have a wiki for AppGameKit Shaders code snippets with a image gallery to quickly see the effects of shaders
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 14th Mar 2013 18:02
Join the AGK Wiki here and add such a page.

It does sound like it would be useful.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 14th Mar 2013 18:23 Edited at: 14th Mar 2013 18:31
What do you specifically mean by shiny MikeMax? The default pointslight shader already seems to give a pretty shiny effect to me? Maybe you could link to a screenshot of something resembling what you have in mind

Thanks for your comments peeps.

My hovercraft is full of eels
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 14th Mar 2013 18:44 Edited at: 14th Mar 2013 18:45
Ripple Shader update: Now distorts pointlight (water/wavy glass effect)



Using the same vertex shader as above.

Fragment(pixel) shader:


My hovercraft is full of eels

Attachments

Login to view attachments
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 14th Mar 2013 19:08
Quote: "Then I tried the shaders that came with the 3d-example in AppGameKit and made simple lightmaps for some objects, but all I could see then was essentially the lightmap embossed on the object and the object no longer responded to where the pointlight moved to."

Agk uses internal shaders and when you set your own shader to the object so are the internal ones not used
You nead to code the lights in to your shader
Quote: "No, I mean just scroll the texture (like setting the UV offsets) which there is no AppGameKit command for yet."

I tested this in the vertex shader and it works on both android and computer

texcoord = uv*vec2(1.0,1.0)+scrollit;

the vertex shader neads an uniform called uniform vec2 scrollit;

And in agk do you simply scroll it like this.

SetShaderConstantByName( myShader, "scrollit",scroll# ,0.0,0, 0 )
scroll#=scroll#+0.02

if you want to scroll in 2 directions.
SetShaderConstantByName( myShader, "scrollit",scroll# ,scroll#,0, 0 )
scroll#=scroll#+0.02
I hope it helps
Quote: "New Shader: Ripple Effect (1 texture, 1 pointlight, 1 directional light)"

Looks very nice

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 14th Mar 2013 19:14 Edited at: 14th Mar 2013 19:29
Thanks for that Cliff.

The thing is I don't just want to scroll, I want to overstretch the texture so that you can have several frames and then scroll it

It works really good on PC but it doesn't look quite right on android.
I use this line to do it:

uvVarying = uv * enduv.xy + vec2(startuv.x, startuv.y);

where enduv is actually the scale of the texture and startuv the scrolling.

My hovercraft is full of eels
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 14th Mar 2013 19:15 Edited at: 14th Mar 2013 19:17
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 14th Mar 2013 19:24 Edited at: 14th Mar 2013 19:26
Quote: "Thanks for that Cliff.

The thing is I don't just want to scroll, I want to overstretch the texture so that you can have several frames and then scroll it

It works really good on PC but it doesn't look quite right on android.
I use this line to do it:

uvVarying = uv * enduv.xy + vec2(startuv.x, startuv.y);

where enduv is actually the scale of the texture and startuv the scrolling."


First question is why do you use vec 4?

uniform vec4 enduv;
uniform vec4 startuv;

agk uses 4 slots for passing stuff to the shader.
But if its an vec 2 so do it only use the first 2 slots

It dosent work better if you switch places ?
uvVarying = uv * startuv.xy+enduv.xy;

Dont forget to change.
uniform vec2 enduv;
uniform vec2 startuv;

uvVarying = uv * startuv.xy+(this do agk use for atlas textures if you look at agks internal shaders);

I understand that you want an animated fx where you use various parts of an image as frames?

And i dont belive you can scroll an atlas texture?
As open gl simply draws an image edge against edge if you scroll?

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 14th Mar 2013 19:31 Edited at: 14th Mar 2013 19:37
Here it is on PC:
http://www.youtube.com/watch?v=nPHTYER3aMg

Yes I realized later that I could use vec2 In the beginning I just did exactly what Paul posted early in this thread but I've learned a tiny bit more about it all now, hehe.

I just tried "uvVarying = uv * startuv.xy+enduv.xy;" and that didn't work at all.

I'll figure out what's wrong on android with some debugging, it's all cool!

This worked with them being vec2's: uvVarying = uv * enduv + startuv;

Still not on android tho

My hovercraft is full of eels
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 14th Mar 2013 19:31
Quote: "It's a shiny/specular hilighting "

If i get the time so could i look it up in some of my books
But you know that it would be very slow on mobiles ?
And i have very little time and could take a while until i do one

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 14th Mar 2013 19:39
Quote: ""It's a shiny/specular hilighting""


I assume this involves passing the camera position to the shader. Any ready varyings for that Cliff or do we have to pass camera-pos with a vec3?

My hovercraft is full of eels
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 14th Mar 2013 19:59
a lot of mobile games use this shiny effect why should it be slower ?
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 14th Mar 2013 21:26
Well I just think that the first one looks like the directional light would look and the second like the pointlight _could_ look

I guess specular light involves the light always shining back towards the camera tho?

My hovercraft is full of eels
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 14th Mar 2013 22:02
Quote: "a lot of mobile games use this shiny effect why should it be slower ? "

Its pretty much that it uses alot of calculations in the fragment shader that makes it slow.

And yes alot of games on the market uses it well and are many times coded in as a part of the core and not added in externally like in agk.

Something like how tgc do with the internal agk shaders.
And the ones that writes gamelofts etc shaders are probably 10 times better then us hobbyist to write them

I suspect you want the fx for your hovercrafts ?
And thats not to slow as they will probably be very small parts of the screen

Paul at tgc are a pretty clever one and helped me alot on learning the basics and iam still learning
Maybe we should ask him about a specular shader as a part of agk

My experiments with shaders have showed to be very slow many times as iam still learning and finding stuff that is better constantly.

When i look at some of my first shaders so do i laugh out loud and think about wath i whas thinking when i wrote them.

I have a bunch of ongoing work but will see if i get the time to look at some basic shader that you could insert in to your own

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 14th Mar 2013 22:39
You could test if this works ?
I found it in one of my books and adds specular to a light.

float nDotL = dot(normal,light);
float rDotV = dot(viewdirection,(2.0*normal)*nDotL-light);
float specular = specularcolor*pow(rDotV,specularpower);

This should be done after the light calculation and added as the light in the frag color.
I hope it helps.

I where to lazy to write a complete shader

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 15th Mar 2013 01:19
viewdirection ?
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 15th Mar 2013 10:45
I think you'd have to send camera-information in setShaderConstantByName to a vec3 or vec4 called viewdirection in this case. It's an uneducated guess

My hovercraft is full of eels
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Mar 2013 13:39
Not on my pc right now but I would love to start an AppGameKit shader library where we can all upload examples like these and then I can keep the first post up to date with a full list of shaders and simple examples.


this.mess = abs(sin(times#))
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 15th Mar 2013 14:56
Quote: "Not on my pc right now but I would love to start an AppGameKit shader library where we can all upload examples like these and then I can keep the first post up to date with a full list of shaders and simple examples.
"


Would be great
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 16th Mar 2013 10:10
Quote: "viewdirection ?"
Quote: "I think you'd have to send camera-information in setShaderConstantByName to a vec3 or vec4 called viewdirection in this case. It's an uneducated guess "

Could be easially done with getting the angle towards the object from an dummy object

That snippet neads the info but i belive there is simplier ones?

I tested the code and used a lights direction and the result is only weird
Or i made something wrong as iam pretty tired from my illnes.
Quote: "Not on my pc right now but I would love to start an AppGameKit shader library where we can all upload examples like these and then I can keep the first post up to date with a full list of shaders and simple examples."

Mak a sticky so will i try to fill in some does and donts in making shaders
I have learned alot since after i started this thread
And i will try to rework some of my first ones to be proper

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz

Login to post a reply

Server time is: 2024-05-08 23:34:41
Your offset time is: 2024-05-08 23:34:41