Jump to content

Two texture layers on same polygons?


Roland
 Share

Recommended Posts

Programmers making art ... yeah.. I know ... :)

 

Anyway. I making some stone walls and had an idea of using two texture layers.

One layer that is tiled and another that is not. The tiled layer is the base diffuse color (and normal map) while the non-tiled layer would be some dirt and grime added. My idea was to get a high detail on the base color and then add some flavor to that using the second layer.

 

But how is this done? Or is it even possible to do.

 

I have seen that its possible to have two UV-maps on the models and use different textures for each of them. Is that how to do it? And if so. Can Leadwerks handle two uv-maps with different textures?

 

Have you guys any suggestions?

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

You can do that in a shader using to 2 texcoords for diffuse if you do the tiling in the shader you can keep the other stretched. Simply multiply them to blend even. Maybe the existing shaders support it, haven't checked.

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

..something like this, should work..

 

varying vec3 lightDir,normal;

uniform sampler2D MyDifuseTexture,MyTextureOverDifuse;

 

void main()

{

vec3 ct,cf,c;

vec4 texel;

float intensity,at,af,a;

 

intensity = max(dot(lightDir,normalize(normal)),0.0);

 

cf = intensity * (gl_FrontMaterial.diffuse).rgb +

gl_FrontMaterial.ambient.rgb;

af = gl_FrontMaterial.diffuse.a;

 

texel = texture2D(MyDifuseTexture,gl_TexCoord[0].st);

 

ct = texel.rgb;

at = texel.a;

 

c = cf * ct;

a = af * at;

 

float coef = smoothstep(1.0,0.2,intensity);

c += coef * vec3(texture2D(MyTextureOverDifuse,gl_TexCoord[0].st));

 

gl_FragColor = vec4(c, a);

}

 

Link to comment
Share on other sites

You meaning detail maps ? http://www.cafu.de/w...ect_detail_maps

 

If yes then i think its just a second textures which is blended multiplytive above the first one.

Not quite. Grrrr .. my lack of English. Let's illustrate then

 

Lets say I have this tile (256x256)

 

 

and an oyerlay (512x512)

 

 

Then I want to add the tile to plane (tile 4 times = 512x512)

and the place the overlay on the same plane, like this

 

 

or without the red tile markers

 

 

and of course I want to place the overlay in code (or bye mat-file) so I can use different overlays.

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

shader change for this test was :

 

Before main() add

 

uniform sampler2D texture8;

 

Find

 

diffuse *= texture2D(LW_DIFFUSE,texcoord0);//*fOcclusionShadow

 

Add below this line :

 

diffuse *= texture2D(texture8,texcoord1); //texcoord1 reads UV channel 2

 

or use + to add it on top, use black as background.

 

Add texture8= to your mat file and use any diffuse shader.

 

Might be useful to use glsl preprocessor directives so it doesn't apply to everything.

Just create a mesh_diffuse_whateverelse_2uvmaps.frag and use

 

#declare dualUV 1

 

Then in mesh.frag test if this is true and apply the example above.

This way you can apply 2 UV sets using any shader, bump specular, glow or what not.

 

good luck smile.png

Let me know if it works or just ask,

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

@Shadmar

 

I'm probably doing something wrong.

With those changes my MaterialEditor and Editor crashes.

 

I have attached my files.

 

 

 

Ah..

 

You missed the directive around

diffuse *= texture2D(texture8,texcoord1); //texcoord1 reads UV channel 2

 

And #declare should be #define.

And The diffuse should also go in the 2uv.frag file

#define LW_DIFFUSE texture0

 

Looks good! This is what I got :

LE_roland.jpg

 

Here are the shader files fixed :

frags.zip

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...