Hiya guys.
I got a bee in my bonnet about texture-generation via shader again...
Basically what Im trying to do is use a multi-texture shader to actually
GENERATE a texture for later use.
Im currently using the below PROTOTYPE shader to to apply and blend multiple textures
onto an object based on its mesh's vertex-heights.
This works fine as it is. (Prototype remember!)
But what I actually WANT it to do is to just run the shader for one frame, take that
'generated' texture and 'save' it into another BMAP that I can then apply to the
entity, so I dont need to generate the blended map every frame...
Ive been playing with 'bmap_rendertarget' and 'view.PROCESS_TARGET' and the like,
but I havent been able to get ANY data into the 'target' bmap at all... So I wont go
over any of those tests, because I was probably using them completely wrong...
I know this shader is horrible, and (ATM) ill-suited to the task, but its a prototype
that was basically written to test proof-of-concept of the vertex-shader
height extractions and the pixel-shader blending-based-on-height calculations.
So I'm needing help PRIMARILY on the lite-c code 'around' the shader to capture the
render-target. But help on any rotation/translation of the model object-space data
will be appreciated...
//Application fed data
const float4x4 matWorldViewProj;
texture Sand_BM_bmap, Grass_BM_bmap, Rock_BM_bmap, Snow_BM_bmap;
// ColorMap Samplers
sampler SandSampler = sampler_state { Texture = <Sand_BM_bmap>; };
sampler GrassSampler = sampler_state { Texture = <Grass_BM_bmap>; };
sampler RockSampler = sampler_state { Texture = <Rock_BM_bmap>; };
sampler SnowSampler = sampler_state { Texture = <Snow_BM_bmap>; };
#define cMult 0.0001002707309736288
#define aSubtract 0.2727272727272727
float random(float4 t)
{
float a, b, c, d;
a=t.x+t.z*cMult+aSubtract-floor(t.x);
a*=a; b=t.y+a; b-=floor(b);
c=t.z+b; c-=floor(c); d=c;
a+=c*cMult+aSubtract-floor(a);
a*=a; b+=a; b-=floor(b);
c+=b; c-=floor(c);
return ((a+b+c+d)/4);
}
// Vertex Shader:
void TerrPaintVS( in float4 InPos: POSITION, in float2 InTex: TEXCOORD0,
out float4 OutPos: POSITION, out float2 OutTex: TEXCOORD0,
out float Height: TEXCOORD1 )
{
// Transform the vertex from object space to projected world space:
OutPos = mul(InPos, matWorldViewProj);
// Pass the texture coordinate to the pixel shader:
OutTex = InTex;
// Capture the Height of this vertex from object space... SEEMINGLY
Height = InPos.y;
// OPTIONALLY add some randomness to the demarkation line
Height += (random(InPos)*20)-5;
}
// Pixel Shader:
float4 TerrPaintPS( in float4 InPos: POSITION, in float2 InTex: TEXCOORD0,
in float Height:TEXCOORD1 ): COLOR
{
float4 Color = tex2D(SandSampler, InTex);
if(Height < 42) Color = lerp(tex2D(SandSampler,InTex), tex2D(GrassSampler,InTex), (Height-32)/10);
else if(Height < 75) Color = tex2D(GrassSampler, InTex);
else if(Height < 85) Color = lerp(tex2D(GrassSampler,InTex), tex2D(RockSampler,InTex), (Height-75)/10);
else if(Height < 120) Color = tex2D(RockSampler, InTex);
else if(Height < 130) Color = lerp(tex2D(RockSampler,InTex), tex2D(SnowSampler,InTex), (Height-120)/10);
else Color = tex2D(SnowSampler, InTex);
return Color;
}
// Technique:
technique AmbientTechnique
{
pass P0
{
VertexShader = compile vs_2_0 TerrPaintVS();
PixelShader = compile ps_2_0 TerrPaintPS();
}
}
/*
1 1 1 1 1 1 0.75 0.5 0.25 0
11 12 13 14 15 16 17 18 19 20
#define RANDOM_IA 16807
#define RANDOM_IM 2147483647
#define RANDOM_AM (1.0f/float(RANDOM_IM))
#define RANDOM_IQ 127773
#define RANDOM_IR 2836
#define RANDOM_MASK 123459876
int random_x;
float random ()
{
int k; float ans;
random_x ^= RANDOM_MASK;
k = random_x / RANDOM_IQ;
random_x = RANDOM_IA * (random_x - k * RANDOM_IQ ) - RANDOM_IR * k;
if ( random_x < 0 ) random_x += RANDOM_IM;
ans = RANDOM_AM * random_x;
random_x ^= RANDOM_MASK;
return ans;
}
float random ( float low, float high )
{
float v = random();
return low * ( 1.0f - v ) + high * v;
}
float2 random ( float2 low, float2 high )
{
float2 v = float2( random(), random() );
return low * ( 1.0f - v ) + high * v;
}
float3 random ( float3 low, float3 high )
{
float3 v = float3( random(), random(), random() );
return low * ( 1.0f - v ) + high * v;
}
void seed ( int value )
{
random_x = value;
random();
}
*/
Thanks guys... again.