Sign in to follow this  
ali rahimi

Custom tilling per each MipMap level.

Recommended Posts

[font="verdana, sans-serif"][size="2"]Hello guys.[/size][/font]
[font="verdana, sans-serif"] [/font][font="verdana, sans-serif"][size="2"]I want to use a Custom tilling per each MipMap level for landscape (Like [url="http://lumion3d.com/"]lumion[/url]). If you notice in [url="http://lumion3d.com/"]lumion[/url] landscape tilling change based on camera distance. Close distance have more tile's. One way is to do the tilling in photoshop per each mipmap, but problem is then you will have a low res tilling in close distance. (Cause it tiled in photoshop). Therefore iam trying to do the tilling in a shader itself. I setup an array of float2. X is tilling amount and Y is the mipmap count. But it don't work correct for some reason.[/size][/font]
[font="verdana, sans-serif"][size="2"]And i am using Quest3D for this. [/size][/font]
[font="verdana, sans-serif"] [/font][font="verdana, sans-serif"] [/font][code]
int UseTangent : UseTangent;
int UseBiNormal : UseBiNormal;

float4x4 wvp : WorldViewProjection;
float4x4 worldI : WorldInverse;
float4x4 world : World;

texture Texture_Map : TEXTURE0
<
string ResourceType = "2D";
>;

sampler2D Texture_MapSampler = sampler_state
{
Texture = <Texture_Map>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};

static float2 Tile_UV_Index[10] =
{
2,0,
4,1,
8,2,
16,3,
32,4,
64,5,
128,6,
256,7,
512,8,
1024,9,
};

//-------------------------------------------------------------------------------
// UV_Cordinate function
//-------------------------------------------------------------------------------
float4 UV_Cordinate (float3 VertexPosition)
{
float4 UV_Cordinate_Result = float4(0,0,0,0);
for(int i=0; i<10; i++)
{
float2 UV_X = float2(VertexPosition.y, VertexPosition.z);
float4 Output = float4((UV_X/(Tile_UV_Index[i].x)).xy, 0, Tile_UV_Index[i].y);
UV_Cordinate_Result += Output;
}
return UV_Cordinate_Result;
}
//-------------------------------------------------------------------------------
// input from application
struct a2v {
float4 position : POSITION;
float2 texCoord : TEXCOORD0;

};

// output to fragment program
struct v2f {
float4 position : POSITION;
float2 texCoord : TEXCOORD0;
float4 wposition : TEXCOORD2;

};

// Ambient Pass Vertex Shader:
v2f av(a2v In)
{
v2f Out = (v2f)0;
Out.position = mul(In.position, wvp); //transform vert position to homogeneous clip space
Out.wposition = mul(In.position, world); //world space vertex position passed out
Out.wposition.xyzw = Out.wposition.xzyw; //Output vertex position in world space - swizzled for Y up
Out.wposition.y = -Out.wposition.y;
Out.texCoord = In.texCoord; //pass through texture coordinates from channel 1

return Out;
}

// Ambient Pass Pixel Shader:
float4 af(v2f In) : COLOR
{
float3 VertexPosition = In.wposition.xyz;
float2 UV_X = float2(VertexPosition.y, VertexPosition.z);


// float4 Texture_Map = tex2Dlod(Texture_MapSampler, float4((UV_X/1).xy, 0, 1)); // correct result, last float1 at the end is mipmap level.
float4 Texture_Map = tex2Dlod(Texture_MapSampler,float4(UV_Cordinate(VertexPosition))); // But function dont look correct.
float3 input1 = Texture_Map.rgb;

float4 ret = float4(input1, 1);
return ret;
}

technique Complete
{
pass ambient
{
VertexShader = compile vs_3_0 av();
ZEnable = true;
ZWriteEnable = true;
CullMode = ccw;
ShadeMode = Gouraud;
AlphaBlendEnable = false;
AlphaTestEnable = FALSE;
PixelShader = compile ps_3_0 af();
}

}
[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this