Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualGeneralQuery

Posted 22 September 2012 - 08:39 AM

I'll stick to texture splatting then.

One last question. I'm not sure what the colour mask is used for?


If you have a splatting shader that has 4 texture slots for 4 texture materials but any given chunk can have any 4 textures from a set of 8 that you bind dynamically, you need a means of ensuring that the correct colour channel is sampled for an arbitrary material texture.

E.g. let's say that you have a blend weight texture array of 2 elements containing the first 4 and second 4 splat weightings for the 8 materials. If grass resides in the green channel of the second element texture then you'd pass the elemend index and colour mask for that material as a uniform for your splatting shader. Eg:


Vector4 maskGrass(0.0, 0.0, 1.0, 0.0); // Mask out the red, blue and alpha colour channels, leaving only the green channel
UInt idxGrass = 1; // 2nd element of weight array texture

SomeAPI.SetShaderUniforms(rgbaMask = maskGrass, texElement = idxGrass);

// shader code

vec3 uvCoords = vec3(FragCoords, texElement);

vec4 w= sampler2DArray(Weights, uvCoords) * rgbaMask; // Will leave us with the vector [0, 0, green, 0]

float weight = w.x + w.y + w.z + w.w; // Will leave us with just the green channel

lerp(a, b, weight); // splat our textures using the calculated blend weight for this material


That way you can send only the materials you need to the shader (which, of course, could be submitted in any order).

If you're hard coding your texture splatting, i.e. it will splat 8 textures regardless of how many are needed, then you do not need to do this.

#2GeneralQuery

Posted 22 September 2012 - 08:38 AM

I'll stick to texture splatting then.

One last question. I'm not sure what the colour mask is used for?


If you have a splatting shader that has 4 texture slots for 4 texture materials but any given chunk can have any 4 textures from a set of 8 that you bind dynamically, you need a means of ensuring that the correct colour channel is sampled for an arbitrary material texture.

E.g. let's say that you have a blend weight texture array of 2 elements containing the first 4 and second 4 splat weightings for the 8 materials. If grass resides in the green channel of the second element texture then you'd pass the elemend index and colour mask for that material as a uniform for your splatting shader. Eg:


Vector4 maskGrass(0.0, 0.0, 1.0, 0.0); // Mask out the red, blue and alpha colour channels, leaving only the green channel
UInt idxGrass = 1; // 2nd element of weight array texture

SomeAPI.SetShaderUniforms(maskGrass = rgbaMask, idxGrass = texElement);

// shader code

vec3 uvCoords = vec3(FragCoords, texElement);

vec4 w= sampler2DArray(Weights, uvCoords) * rgbaMask; // Will leave us with the vector [0, 0, green, 0]

float weight = w.x + w.y + w.z + w.w; // Will leave us with just the green channel

lerp(a, b, weight); // splat our textures using the calculated blend weight for this material


That way you can send only the materials you need to the shader (which, of course, could be submitted in any order).

If you're hard coding your texture splatting, i.e. it will splat 8 textures regardless of how many are needed, then you do not need to do this.

#1GeneralQuery

Posted 22 September 2012 - 08:36 AM

I'll stick to texture splatting then.

One last question. I'm not sure what the colour mask is used for?


If you have a splatting shader that has 4 texture slots for 4 texture materials but any given chunk can have any 4 textures from a set of 8 that you bind dynamically, you need a means of ensuring that the correct colour channel is sampled for an arbitrary material texture.

E.g. let's say that you have a blend weight texture array of 2 elements containing the first 4 and second 4 splat weightings for the 8 materials. If grass resides in the green channel of the second element texture then you'd pass the elemend index and colour mask for that material as a uniform for your splatting shader. Eg:


Vector4 maskGrass(0.0, 0.0, 1.0, 0.0);
UInt idxGrass = 1;

SomeAPI.SetUniforms(maskGrass = rgbaMask, idxGrass = texElement);

// shader code

vec3 uvCoords = vec3(FragCoords, texElement);

vec4 w= sampler2DArray(Weights, uvCoords) * rgbaMask;

float weight = w.x + w.y + w.x + w.y;

lerp(a, b, weight);


That way you can send only the materials you need to the shader (which, of course, could be submitted in any order).

If you're hard coding your texture splatting, i.e. it will splat 8 textures regardless of how many are needed, then you do not need to do this.

PARTNERS