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 / Can i apply a 2nd image to a 3D objects 1st image?

Author
Message
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 16th Jul 2017 14:46
I would like to be able to apply a 2nd image to an existing image already on an object.

For those who came through from DBPro, you were able to do this using the command;

SET DETAIL MAPPING ON Object Number, Image Number
(Detail map textures are combined with the main texture to create a multitextured object.)

So far i have been unable to find a way of doing this without creating extra objects placed in front of the originals, but this gets messy.

I am not sure if meshes is the answer to this but i have to admit that without examples i am not even sure if this is the right way to go.

If anyone can help or even point me in the right direction then your input will be appreciated.

Thanks
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 16th Jul 2017 18:09 Edited at: 16th Jul 2017 18:20
Detailmapping is a shader effect.
You can find the default object shader here.
Real Detailmapping isn't an easy shader but the effect you describe could also be made like this:

Not Tested glsl Code

A real Detail shader would be needed for details on large objects like terrain where you don't want to map a second texture to all polygons in the object and it involves the depth buffer to filter far fragments

Using AGKv2 Tier1
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 17th Jul 2017 12:30
Hello janbo, phew,
Thank you for helping and pointing me in the right direction.
I've not ventured in to shaders so it does look a bit daunting but i will do my best to see where i get.
It certainly makes me appreciate how good DBPro was in its own right but i do think AppGameKit 3D has a long way to go yet.

Thank you again.
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 17th Jul 2017 21:46 Edited at: 17th Jul 2017 21:51
Using it is easy

You only need 5 steps:
• Just look for the default shader in the documentation copy paste the VertexShader into some nice called files
• Load the default shader and my custom shader with ShaderID=LoadShader("NiceDefaultVertex.vs","NiceCustomFragment.ps")
• Bind the Shader to the object with SetObjectShader(ObjectID,ShaderID)
• Give the object two textures with SetObjectImage(ObjectID,Image1ID,0) and SetObjectImage(ObjectID,Image2ID,1)
• Be happy ! : )

Using AGKv2 Tier1
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 18th Jul 2017 13:40
Hi janbo, thanks for the additional info but i cannot get it to work.

I must have made an error but do not know where. This is what i have done;

1) create and position a 3D plane object.

2) created a file "NiceDefaultVertex.vs" in which i have copied and pasted what i think is the default vertex shader, i.e


I may have this wrong.

3) created a file "NiceCustomFragment.ps" which contains your coding under the above heading "Not Tested glsl Code"

4) applied the following code next;


5) all files/images are in my media folder.

The object does not display at all. Are you able to tell where i have gone wrong?
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 18th Jul 2017 16:25 Edited at: 18th Jul 2017 16:27
Nice, you made everything right...even the prediction where you made the mistake ^^

The one you choose was the default vertex shader for sprites
It must be:

NiceDefaultVertex.vs

Using AGKv2 Tier1
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 18th Jul 2017 16:52
Wow, thank you. Works perfectly.
Now the hard bit, to try to understand what you did so that i can do these myself.

Big thanks
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 18th Jul 2017 19:38 Edited at: 18th Jul 2017 19:42
I commented the two lines I changed.
uniform sampler2D texture1; <- this is just like a variable declaration for textures
To be specific uniforms are variables which get values from AGK.
The sampler2D keyword means its a 2 dimensional texture.
And texture1is just a name.

mediump vec3 color = light * mix(texture2D(texture0, uvVarying).rgb, texture2D(texture1, uvVarying).rgb, 0.5) ;
mediump is the variable precision
vec3 is just the datatype (xyz or rgb)
The light variable is filled by AppGameKit a line above.
I explain the mix Command later...
And then we have those texture2D statements with the sampler name (texture0 and texture1) and the position from where it should look up the pixel value from the texture (uvVarying)
uvVarying is declared as a varying...a varying is a variable passed from the vertex shader to the fragment shader.
You see the .xyz behind the texture2D command... its called swizzle ..you could also make it to float with .x or .z or .r or vec2 with .xy or .xz or yz or .rg and so on ^^
Now the mix command is just a neat way to linear blend the first parameter with the second parameter or:
Result = FirstParam + (1.0 - BelndValue) + SecondParam * BelndValue

Welkome to the world of shader

Using AGKv2 Tier1

Login to post a reply

Server time is: 2024-11-24 11:51:56
Your offset time is: 2024-11-24 11:51:56