   HLSL - Problem with blending texture-scales
  Hi there!I'm writing a planetary engine for a computer graphics project. Being new to hlsl I need some help with implementing texture scaling:My idea was that I could blend different scales of a texture relative to the camera distance from the ground to keep it nice at lower camera heights.Now, the VertexShader code for this looks something like this:float2 TexScale : TEXTURE1float2 TexFactor : TEXTURE2float h = distance(EyePos,pos_ws);float ldHeight = log2(h);// Cut the floating point factor of the heightfactorint ldHeightI = ldHeight;// Bring the scale down to some value between 0 and 1TexScale[0]= saturate((ldHeightI+1)/20.0);TexScale[1]= saturate((ldHeightI+2)/20.0);// The blend-factor of each texture componentTexFactor[0]= 1-frac(ldHeight);TexFactor[1]= frac(ldHeight);In the pixel shader I want to use those values to blend the same texture with two different scales:c  =  tex2D(ts0, in.TexCoord / in.TexScale[0]) * in.TexFactor[0];c +=  tex2D(ts0, in.TexCoord / in.TexScale[1]) * in.TexFactor[1];To make this code easier to follow, three examples:ldHeight = 11.8 ->TexScale =  {0.6, 0.65}, TexFactor = { 0.2,  0.8}ldHeight = 11.1 ->TexScale =  {0.6, 0.65}, TexFactor = { 0.9,  0.1}ldHeight = 10.8 ->TexScale =  {0.55, 0.6}, TexFactor = { 0.2,  0.8}What looked good in my head looks crappy in reality: The textures are blended nicely in the range where only the TexFactor changes, at the distances where the TexScale changes (like in the transition from the second example to the third example), there is an awful distortion.I think both TexScale and TexFactor are interpolated over the pixels, and that messes up the algorithm. 1.) Is it possible to pass values into the pixel shader that aren't interpolated?2.) Or, if this is not the case, how could i implement texture scaling in relation to the camera distance?3.) Or is the code in itself crap? :)As I said, i'm pretty lost here...Thanks for the help!greetingsJohannes   
  Hi Johannes,if I got you right, you're trying to blend a texture with itself. I'm not sure if this is a good way of adding detail, but as long as it looks right...As for your question: 1. There is no way to pass not interpolated values to the pixelshader (in fact which fragment should get which value then?)2. You could try to just round the scale values up to .5 in your pixelshader, although I would suggest to pass them as multipliers in the range 1.0 - ... anyway.I hope this helps.Regards,Elshad.   ;  You could interpolate the vertex position and do all the other maths in the pixel shader. That will avoid the problems from interpolation, but doing more work in the pixel shader will slow things down somewhat.   ;  First of all, thanks for the replies.@Elshad: I use multitexturing based on the terrain height, so in fact I'm scaling 4 textures(left it out of the code to keep things clean). That way the tiling effect is not that visible, and it would require at least 16 different textures to get detail right at all heights, which is pretty much data (regardless the effort to create them, they have to be seamingless because i'm using a cube of quadtrees to describe my planet). I will try the thing with the rounding when i'm back home tomorow, though I can't really say if it works now...I use PIX, but I think the Pixelshader got too complex, when i try to debug a pixel the debugger just jumps around randomly o.O - Anyone has an idea what the reason is and if there's something to do against that?@Adam: The thing with the pixelshader workload is that I use pixel lighting, which is calculated in the ps and shader model 2.0 doesn't allow more than 68 instructions in the ps. Switching to pixel lighting made me change the code in the beginning, because my ps wouldn't compile anymore...