[Shader] Querying textures in Hierarchy

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

Post Reply
TVM Cracklings
Posts: 33
Joined: 30 Sep 2015, 10:49

[Shader] Querying textures in Hierarchy

Post by TVM Cracklings » 05 Nov 2015, 04:42

Hi there.

1.

How do I actually get textures themselves in a certain order in the Hierarchy window? There's some Sas bindings about texture infos in the documentation (e.g. Ventuz.Textures[*].Mapping), but I didn't find anything related to the textures themselves.

So my question is:

In the HLSL node, is there a way to load textures in an order specified in the Hierarchy without having artists to manually bind them every time?

2.

Is there a way to uniformly transform textures without losing the translation?

Currently I'm doing

Code: Select all

Output.vUV = mul(Input.vUV,UVTranslate[0]);
in vertex shader, and then

Code: Select all

tex2D(sampIn, Input.vUV+(float2)(UVTranslate[0][2]));
in fragment shader, which is kind of ugly.


Thx

-C

User avatar
lerou
Posts: 337
Joined: 06 Sep 2013, 07:14
Location: Hamburg, Germany

Re: [Shader] Querying textures in Hierarchy

Post by lerou » 05 Nov 2015, 09:08

Ventuz.Textures[*].Mapping

Using this will give you an array of the texture mappings. The elements are associated with the texture stages. The first element belongs to texture stage 1. The second to texture stage 2 and so on. There are 8 stages.

You define your texture samplers like this:

sampler sa[8] : register (s[0]);

An array of 8 texture samplers starting at the first stage (s[0] is the first stage. As usual you start with 0 while texture stages in parameters will start at 1).

You could also do:

sampler s0 : register (s[0]);
sampler s1 : register (s[1]);

without an array.

Textures in your hierarchy will be assigned automatically. Check the texture node. It has a texture stage parameter. It's set to next by default. So the first texture in the hierarchy will be stage 1 or index 0. The second is stage 2 or index 1 and so on. You can also manually assign those stages. You don't have to bind your textures to the shader manually.

Careful: if you set the first texture in your hierarchy to stage 2 and the second one to next, it will be bound to stage 3. Stage 1 would in this case be empty.

Best,
rou

TVM Cracklings
Posts: 33
Joined: 30 Sep 2015, 10:49

Re: [Shader] Querying textures in Hierarchy

Post by TVM Cracklings » 05 Nov 2015, 11:43

Thx rou, you're awesome!

Although, if I multiply my vertex UV with the mapping matrix, the 3rd row of the matrix simply gets lost, since the UV coord is only a float2. Is there a similar way to take the translation part into account in UV coord processing, just like you do when you multiply the 4x4 translation matrix onto a float4(float3, 1.0f) (or the other way round)?

User avatar
lerou
Posts: 337
Joined: 06 Sep 2013, 07:14
Location: Hamburg, Germany

Re: [Shader] Querying textures in Hierarchy

Post by lerou » 05 Nov 2015, 13:15

same thing. Add a third value (1) to the uvs.

TVM Cracklings
Posts: 33
Joined: 30 Sep 2015, 10:49

Re: [Shader] Querying textures in Hierarchy

Post by TVM Cracklings » 05 Nov 2015, 15:37

Alright. Thought there might be a cleaner way to do it. Thanks!

Post Reply