Hmm. I think this is the right way to create an index texture. This one's for a 4x4 tiling like the flowers texture (two edge types).
http://dl.dropbox.com/u/20733494/wangindex.ppm
I'm not 100% sure I have the y axis correct because they weren't entirely specific in the chapter. Could take a vertical mirror to correct.
Code written in R cause I'm more familiar with it... I can generate more like it fairly easily if it's correct.
I guess once I have the shader implemented, I'll see if it works right...
Edit: Modified texture so I could see what was happening. Numbered from the bottom left (0) across, then the next row up, and so on, to 15.
The column scramble is working, anyway - you can see it goes fairly randomly. But row scramble, not so great (thus 12-15 are pretty much all in the same row, as are 8-11, 4-7, 0-3). I believe this is due to a bug in my index texture, cause when I use the x-coord both ways, it looks much more scrambled.
I'm also having trouble with
mode=linear
Within the track.shd. The .tga has only 4 brightnesses: 0%, 33%, 66%, 100%. And yet this is producing weird in between results...
& number free result, which looks more random since the tiles aren't all marked:
Nice.
So does a tool make that texture for you?
That is the bit I struggle with the most... scattering UVW's is probably the easiest bit, as said, with manual control built in where you need it
That said, being able to do it over a low density mesh is nice!
Dave
Nice.
So does a tool make that texture for you?
// stick this line up near the baseMap
uniform sampler2D indexMap : TEXUNIT1,
// this is where the modifications go. Making this the wang tiling version of standard.
// number of output tiles (what does this mean?)
// should replace one of these with scale input
float2 mappingScale1 = float2((1.0f/8.0f),(1.0f/8.0f));
float2 mappingScale2 = float2((128.0f),(128.0f));
float2 mappingAddress = IN.tc0 * mappingScale1;
float4 whichTile = tex2D(indexMap, float2(0.5f,0.5f)/mappingScale2 + floor(mappingAddress*mappingScale2)/mappingScale2);
whichTile = floor(whichTile*float4(3.0f,3.0f,3.0f,1.0f) + 0.25f)/4.0f;
// number of input tiles (should be 4?)
float2 tileScale = float2(4,4);
// get correct mipmapping?
float2 tileScaledTex = IN.tc0 * float2(4/4,4/4);
float4 baseCol=tex2D(baseMap,whichTile.rg + frac(mappingAddress)*float2(32,32), ddx(tileScaledTex),ddy(tileScaledTex));
// this all replaces the following line:
//baseCol=tex2D(baseMap,IN.tc0);
Hmm. I think this is the right way to create an index texture. This one's for a 4x4 tiling like the flowers texture (two edge types).
http://dl.dropbox.com/u/20733494/wangindex.ppm
I'm not 100% sure I have the y axis correct because they weren't entirely specific in the chapter. Could take a vertical mirror to correct.
Code written in R cause I'm more familiar with it... I can generate more like it fairly easily if it's correct.
----------8<---------------------
Basically you need to give it another texture input. Apparently texRECT doesn't currently work (always returns 0) so I had to kludge it a little. Way too many constants in there for now.
Code:// stick this line up near the baseMap uniform sampler2D indexMap : TEXUNIT1, // this is where the modifications go. Making this the wang tiling version of standard. // number of output tiles (what does this mean?) // should replace one of these with scale input float2 mappingScale1 = float2((1.0f/8.0f),(1.0f/8.0f)); float2 mappingScale2 = float2((128.0f),(128.0f)); float2 mappingAddress = IN.tc0 * mappingScale1; float4 whichTile = tex2D(indexMap, float2(0.5f,0.5f)/mappingScale2 + floor(mappingAddress*mappingScale2)/mappingScale2); whichTile = floor(whichTile*float4(3.0f,3.0f,3.0f,1.0f) + 0.25f)/4.0f; // number of input tiles (should be 4?) float2 tileScale = float2(4,4); // get correct mipmapping? float2 tileScaledTex = IN.tc0 * float2(4/4,4/4); float4 baseCol=tex2D(baseMap,whichTile.rg + frac(mappingAddress)*float2(32,32), ddx(tileScaledTex),ddy(tileScaledTex)); // this all replaces the following line: //baseCol=tex2D(baseMap,IN.tc0);
float2 mappingAddress = IN.tc0 * mappingScale1;
#include "../../../renderer/shaders/atmosphere.cg"
#include "../../../renderer/shaders/lighting.cg"
#include "../../../renderer/shaders/shadowmapping.cg"
// Vertex to pixel shader structure
struct v2p
{
float4 Position : TEXCOORD4; //POSITION;
float3 normal : TEXCOORD5;
float3 RayleighColor: TEXCOORD2;
float3 MieColor : TEXCOORD3;
float2 tc0 : TEXCOORD0;
float3 Direction : TEXCOORD1;
float extinction : TEXCOORD6;
float2 color : COLOR;
//float2 vpos : VPOS;
};
void main(
// In
in v2p IN,
// Out
out float4 outColor : COLOR0,
#ifdef CSM_MRT
out float4 outShadow : COLOR1,
#endif
// Constants
uniform sampler2D baseMap : TEXUNIT0,
uniform sampler2D Mapa : TEXUNIT1,
uniform sampler2D Mapb : TEXUNIT2,
uniform sampler2D Mapc : TEXUNIT3,
uniform sampler2D Mapd : TEXUNIT4,
uniform float3 lightDirection,
uniform float3 lightColor,
uniform float3 lightAmbient,
uniform float3 eyePosW,
uniform float atmosRayleigh,
uniform float atmosMie,
uniform float3 Ke,
uniform float3 Ka,
uniform float3 Kd,
uniform float3 Ks,
uniform float shininess,
#ifdef CSM
uniform sampler2D shadowArray : TEXUNIT7,
uniform float4x4 smTexMatArray[SM_MAX_SPLITS],
uniform float smSplits,
#endif
uniform float sunny,
uniform float exposure,
uniform floatscale
)
{
float3 skyColor;
float4 mixa, mixb;
float pi=3.141592654;
float2 RotationMatrix = float2(cos(0.25*pi),-sin(0.25*pi));
#ifdef CSM
float shadow;
// Output shadowing and normals
shadow=GetShadowFactor(IN.Position, IN.normal,shadowArray, smTexMatArray, smSplits, lightDirection)*sunny;
#else
const float shadow=sunny;
#endif
// Get sky gradient color
skyColor.rgb=GetSkyColor(lightDirection,IN.Direction,IN.RayleighColor,IN.MieColor,atmosRayleigh,atmosMie,lightColor,lightAmbient);
// Get base texture color
float4 baseCol=tex2D(baseMap,IN.tc0);
float2 tc=float2(IN.Position.x,IN.Position.z)*scale;
float4 Cola=tex2D(Mapa,tc.xy);
float4 Colb=tex2D(Mapb,tc.xy);
float4 Colc=tex2D(Mapc,tc.xy);
float4 Colarot=tex2D(Mapa,(tc*RotationMatrix));
float4 Colbrot=tex2D(Mapb,((tc*RotationMatrix)*RotationMatrix));
float4 Colcrot=tex2D(Mapc,(((tc*RotationMatrix)*RotationMatrix)*RotationMatrix));
float4 mixmapsa, mixmapsb, mixmapsc;
if (((baseCol.g-1)*2) >0)
mixmapsa=Cola;
else
mixmapsa=Colarot;
if (((baseCol.g-1)*2) >0)
mixmapsb=Colb;
else
mixmapsb=Colbrot;
if (((baseCol.g-1)*2) >0)
mixmapsc=Colc;
else
mixmapsc=Colcrot;
mixa = lerp(mixmapsa, mixmapsb, baseCol.a);
mixb = lerp(mixmapsb, mixmapsc, baseCol.a);
float4 diffusecol=lerp(mixa, mixb, baseCol.a);
//float4 baseCol=tex2D(baseMap,IN.tc0*RotationMatrix);
// Lighting
float3 ambient,diffuse,specular;
LightingSun(Ke,Ka,Kd,Ks,shininess,lightDirection,lightColor,lightAmbient,IN.Position.xyz,IN.normal,eyePosW,
ambient,diffuse,specular);
// Store shadowed color in COLOR0, lit color additions (spec+diff) in COLOR1
float3 sdColor=diffusecol*(diffuse*baseCol.r)+specular*diffusecol.a;
float3 ambientColor=diffusecol*((ambient*baseCol.r)+Ke);
// HDR toning of sky (for LDR shaders)
//skyColor.rgb=1.0-exp(-exposure*skyColor.rgb);
#ifdef CSM_MRT
// Mix sky with texture color based on atmospheric influence
outColor.rgb=lerp(skyColor,ambientColor,IN.extinction);
//outShadow.rgb=lerp(skyColor*(IN.extinction),sdColor,IN.extinction);
outShadow.rgb=sdColor*IN.extinction;
outShadow.a=shadow;
//outColor.rgb=outShadow.a;
//outShadow.rgba=0;
// Blending
outColor.a=1; //baseCol.a;
//outShadow.a=1; //baseCol.a;
#else
// Mix sky with texture color based on atmospheric influence
outColor.rgb=lerp(skyColor,ambientColor+sdColor*shadow,IN.extinction);
// Blending
outColor.a=1;
#endif
}
While I do agree with Mr Whippy to some extent, breaking in detail or using decals has its place, this wang tiling ALSO has a lot of valid uses. Great for adding variation to different large surfaces that don't justify lots extra poly's, like roofing, tin & iron surfaces, grass, dirt, cement & concrete. Anything where tiling is needed but tiling seams aren't.
Can u draw me a diagram of how the wang tile is laid out in your examle? I don't quite follow how the edges work. I've had a go at making a grass wang tile, but wasn't that successful