Hello
Noobie question here for you. I'm copying the example from the help files in GSE (the example titled: How to create custom texture effects), and have managed to successfully port the cube into my game world (which is a hacked version of the top-down spaceship example that is right at the begining of the help files).
I have changed the spaceship example to always keep the spaceship in the middle of the screen, so I can fly around asteroids that I have put into the game, and I've also managed to set a boundary to stop the spaceship flying off in one direction for ever.
Now I want to adapt the custom texture effects code to stay in one place while my spaceship flies around it. I did this by updating the custom texture effect "world-view-projection" data with the view of the spaceship during the draw() function.
This makes the cube stay in one place, but the texture on the cube moves with the spaceship. What I think is happening is that the tex2D part of the code is using the spaceship view to position the texture on the cube. So when the spaceship moves the texture moves around on the cube.
Any idea how I can edit the custom texture "fx" file to seperate cube coords from texture coords
Many thanks,
SuperArmySoldier
Here is the ReallySimpleTexture.fx code...
uniform extern float4x4 WorldViewProj : WORLDVIEWPROJECTION;
uniform extern texture UserTexture;
struct VS_OUTPUT
{
float4 position : POSITION;
float4 textureCoordinate : TEXCOORD0;
};
sampler textureSampler = sampler_state
{
Texture = <UserTexture>;
mipfilter = LINEAR;
};
VS_OUTPUT Transform(
float4 Position : POSITION,
float4 TextureCoordinate : TEXCOORD0 )
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.position = mul(Position, WorldViewProj);
Out.textureCoordinate = TextureCoordinate;
return Out;
}
float4 ApplyTexture(VS_OUTPUT vsout) : COLOR
{
return tex2D(textureSampler, vsout.textureCoordinate).rgba;
}
technique TransformAndTexture
{
pass P0
{
vertexShader = compile vs_2_0 Transform();
pixelShader = compile ps_2_0 ApplyTexture();
}
}