1. Vertex shader/pixel shader version
2. data-flow / interaction of application, vertex-shaders, pixel-shaders, cull/clip/project
In DirectX 9 Graphics, How does data flow between: application software vertex shader projection polygon culling polygon clipping pixel shader frame buffer Where is this described in detail? In particular, I never see a clear statement of how many polygons exit the vertex shader before any-of-them are processed by the pixel shader. And, how is culling and projection done between the vertex shader and pixel shader? I see that streams of data (index/vertex/other) flow into the vertex shader (pixel-shader too?), but not how my application (or DirectX either) can cull/clip/project vertex shader output before it gets jammed (by app or DX?) into the pixel shader. Does the vertex shader generate 1 or more streams?
3. Basic texture example (texture+sampler+vertex shader+pixel shader) for FX Composer 2.5 (cgfx)
4. Basic Vertex Shader and Basic Pixel Shader
According to FX Composer 2.5 it seems my vertex shader was flawed...
actually the code was ripped from the internet I think and then modified.
The problem seemed to be with the "mul" parameters... these needed to be
swapped.
Now it seems to draw alright:
At least in FX Composer 2.5... (z and y would need to be swapped though)
Here are my basic vertex and pixel shader examples ! ;)
Now I try them out to see if that helps in the opengl delphi test program...
// *** BEGIN OF EXAMPLE ***
/*
% Description of my shader.
% Second line of description for my shader.
keywords: material classic
date: YYMMDD
*/
// unused for now:
texture ColorTexture <
string ResourceName = "default_color.dds";
string UIName = "Diffuse Texture";
string ResourceType = "2D";
>;
//float4x4 WorldViewProj : WorldViewProjection;
// Vertex shader input structure
struct VertexShaderInput
{
// basic inputs
float4 mPosition : POSITION;
float2 mTexture : TEXCOORD0;
// extra inputs, go here
float3 mExample : COLOR1;
};
// Vertex shader output structure
struct VertexShaderOutput
{
// basic outputs
float4 mPosition : POSITION;
float2 mTexture : TEXCOORD0;
};
// Global variables
float4x4 GlobalModelViewProjection : WorldViewProjection;
// Name: Simple Vertex Shader
// Type: Vertex shader
// Desc: Vertex transformation and texture coord set to vertex position
//
VertexShaderOutput VertexShaderMain( in VertexShaderInput ParaInput )
{
VertexShaderOutput vOut; // create an output vertex local variable
// ParaInput.mPosition.z = sin(ParaInput.mPosition.x*3.14/3 +
ParaInput.mPosition.y*3.14/5 + ParaInput.mExample.x)*3;
vOut.mPosition = mul(GlobalModelViewProjection, ParaInput.mPosition);
//apply vertex transformation
vOut.mTexture.x = ParaInput.mPosition.x;
vOut.mTexture.y = ParaInput.mPosition.z;
// vOut.mTexture = ParaInput.mTexture; //copy original texcoords
return vOut; //return output vertex
}
//float4 mainVS(float3 pos : POSITION) : POSITION{
// return mul(WorldViewProj, float4(pos.xyz, 1.0));
//}
//float4 mainPS() : COLOR {
//
// return float4(1.0, 1.0, 1.0, 1.0);
//}
// Pixel shader input structure
struct TPixelShaderInput
{
// basic inputs
float2 mPosition : TEXCOORD0;
float2 mColor : COLOR;
// extra inputs, go here
};
// Pixel shader output structure
struct TPixelShaderOutput
{
// basic outputs
// maybe must be float4 ?
float3 mColor : COLOR;
};
// Global variables would go here
// Name: Simple Pixel Shader
// Type: Pixel shader
// Desc: Set pixel color based on input position
// basic pixel shader
TPixelShaderOutput PixelShaderMain( in TPixelShaderInput ParaInput ) : COLOR
{
TPixelShaderOutput vOutput;
vOutput.mColor.r = 0.5 + ParaInput.mPosition.x/2;
vOutput.mColor.g = 0.5 + ParaInput.mPosition.y/2;
vOutput.mColor.b = 0;
return vOutput;
}
technique technique0 {
pass p0 {
CullFaceEnable = false;
VertexProgram = compile vp40 VertexShaderMain();
FragmentProgram = compile fp40 PixelShaderMain();
}
}
// *** END OF EXAMPLE ***
Bye,
Skybuck.
5. Basic texture example (texture+sampler+vertex shader+pixel shader) for FX Composer 2.5 (cgfx)
6. Basic Vertex Shader and Basic Pixel Shader
According to FX Composer 2.5 it seems my vertex shader was flawed...
actually the code was ripped from the internet I think and then modified.
The problem seemed to be with the "mul" parameters... these needed to be
swapped.
Now it seems to draw alright:
At least in FX Composer 2.5... (z and y would need to be swapped though)
Here are my basic vertex and pixel shader examples ! ;)
Now I try them out to see if that helps in the opengl delphi test program...
// *** BEGIN OF EXAMPLE ***
/*
% Description of my shader.
% Second line of description for my shader.
keywords: material classic
date: YYMMDD
*/
// unused for now:
texture ColorTexture <
string ResourceName = "default_color.dds";
string UIName = "Diffuse Texture";
string ResourceType = "2D";
>;
//float4x4 WorldViewProj : WorldViewProjection;
// Vertex shader input structure
struct VertexShaderInput
{
// basic inputs
float4 mPosition : POSITION;
float2 mTexture : TEXCOORD0;
// extra inputs, go here
float3 mExample : COLOR1;
};
// Vertex shader output structure
struct VertexShaderOutput
{
// basic outputs
float4 mPosition : POSITION;
float2 mTexture : TEXCOORD0;
};
// Global variables
float4x4 GlobalModelViewProjection : WorldViewProjection;
// Name: Simple Vertex Shader
// Type: Vertex shader
// Desc: Vertex transformation and texture coord set to vertex position
//
VertexShaderOutput VertexShaderMain( in VertexShaderInput ParaInput )
{
VertexShaderOutput vOut; // create an output vertex local variable
// ParaInput.mPosition.z = sin(ParaInput.mPosition.x*3.14/3 +
ParaInput.mPosition.y*3.14/5 + ParaInput.mExample.x)*3;
vOut.mPosition = mul(GlobalModelViewProjection, ParaInput.mPosition);
//apply vertex transformation
vOut.mTexture.x = ParaInput.mPosition.x;
vOut.mTexture.y = ParaInput.mPosition.z;
// vOut.mTexture = ParaInput.mTexture; //copy original texcoords
return vOut; //return output vertex
}
//float4 mainVS(float3 pos : POSITION) : POSITION{
// return mul(WorldViewProj, float4(pos.xyz, 1.0));
//}
//float4 mainPS() : COLOR {
//
// return float4(1.0, 1.0, 1.0, 1.0);
//}
// Pixel shader input structure
struct TPixelShaderInput
{
// basic inputs
float2 mPosition : TEXCOORD0;
float2 mColor : COLOR;
// extra inputs, go here
};
// Pixel shader output structure
struct TPixelShaderOutput
{
// basic outputs
// maybe must be float4 ?
float3 mColor : COLOR;
};
// Global variables would go here
// Name: Simple Pixel Shader
// Type: Pixel shader
// Desc: Set pixel color based on input position
// basic pixel shader
TPixelShaderOutput PixelShaderMain( in TPixelShaderInput ParaInput ) : COLOR
{
TPixelShaderOutput vOutput;
vOutput.mColor.r = 0.5 + ParaInput.mPosition.x/2;
vOutput.mColor.g = 0.5 + ParaInput.mPosition.y/2;
vOutput.mColor.b = 0;
return vOutput;
}
technique technique0 {
pass p0 {
CullFaceEnable = false;
VertexProgram = compile vp40 VertexShaderMain();
FragmentProgram = compile fp40 PixelShaderMain();
}
}
// *** END OF EXAMPLE ***
Bye,
Skybuck.
7. How to save processing when repeating unchanged images?
Hi, As you will see, I'm a newb to managed c# directx...please help! I'm writing a windowed, not full-screen application whose main window the user can resize. The background image for this window should scale to fit the size of the window. Also, there are a number of sprites, and this application is effectively all 2-d. The DX surface I'm using is a UserControl that I'm placing on a form. The UserControl uses a Panel for it's DX drawing control. Now, I'm drawing two triangle primitives with a texture that's loaded from a .jpg for the background image. My concern is that the call to load the texture looks like this: this.texBackground = TextureLoader.FromFile(device, strTexFilePath); Since this call depends on a 'device', it's invalidated when the main Panel is resized (right?). So, I have to reload the background texture, and all the textures for all of my sprites everytime the window is resized (right?). Now, if it were just one resize event, it wouldn't be that bad, but users tend to drag their mouse around until they get it just right. So here is my main concern: the resizing is slow and painful to watch because of all the texture reloading! What can I do about all of this? Thanks in advance