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 / [SOLVED] 3D object with emission map

Author
Message
JohnStabler
AGK Bronze Backer
10
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 25th May 2020 16:55
Hi!

Just wondering if anyone has implemented emission maps in a shader and if they are willing to share the code?

Thanks!

The author of this post has marked a post as an answer.

Go to answer

janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 25th May 2020 17:38
Well, I can suggest you my shader pack
Selfillumination + Glow effect
JohnStabler
AGK Bronze Backer
10
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 25th May 2020 19:58
Janbo,

I downloaded the shader kit on release. I tried the include but it broke my skybox unfortunately. Was just after a simple shader to add to the object.

Thanks
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 26th May 2020 20:35
Quote: "it broke my skybox"

And what happened to your skybox ?
I guess your skybox is a normal object ?
So did you add it to the system with SP_AddObject() , like you would do with other objects ?
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 26th May 2020 23:08
This post has been marked by the post author as the answer.
Here is an example below to add emissive with basic lighting and fog. I haven't tested this, so consider that it may need a little fixing/modification, I just put this together quickly as a rough example. This example has the diffuse texture in index 0 and any emissive texture in index 1 (so you'd need to texture the object you apply the shader to in that order):

Vertex Shader:


Fragment Shader:
JohnStabler
AGK Bronze Backer
10
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 14th Jun 2020 14:11
@janbo

I did use the SP_AddObject() but no joy. I was using the manual DrawObject() with the skybox and hiding it before rendering other stuff. Not sure if that made a difference.

@SFSW

That shader worked perfectly. Thank you!
JohnStabler
AGK Bronze Backer
10
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 15th Jun 2020 11:26
@SFSW

Actually, there is one problem I'm having. Object transparency no longer works. I'm assuming that's because the alpha is being explicitly set to 1.0 in the shader. How can I fix this?

Thanks!
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 15th Jun 2020 11:44
You can replace:
gl_FragColor = vec4(color,1.0);

with:
gl_FragColor = vec4(color,Diffuse.a);

in the fragment shader and so the alpha is used.
JohnStabler
AGK Bronze Backer
10
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 15th Jun 2020 12:14
Thanks for the quick response @Bengismo

I wasn't very clear in my post, so I apologise. I was referring to the SetObjectColorAlpha() transparency, not transparency in the diffuse texture. It is my understanding that diffuse.a give the alpha value from the texture, not the alpha value for the object.

Thanks
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 15th Jun 2020 12:19 Edited at: 15th Jun 2020 12:21
Ohh sorry. I just read it quick without realising what you are after.

in the shader, agk_MeshDiffuse holds the objects colour so you can use the alpha in that with agk_MeshDiffuse.a

You can use this fragment shader:


I havent tested it but this should apply the Objects alpha to the final render... you can combine that with the diffuse alpha too if wanted - depending on what you are trying to achieve.
JohnStabler
AGK Bronze Backer
10
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 15th Jun 2020 12:31
@Bengismo

That did the trick! I'm not using transparency in textures at the moment, but I've left it as agk_MeshDiffuse.a * diffuse.a.

Thanks so much for your help. I really do need to learn more about shaders. I have only a very basic understanding.

Login to post a reply

Server time is: 2024-04-20 01:09:44
Your offset time is: 2024-04-20 01:09:44