How to create pixelshader with mp3d
Posted: Wed Sep 15, 2010 9:56 pm
Hi folks,
I would like to introduce you to a program that I created with my mp3d Lib (sourcecode is in my mp3d engine available). It is possible to create pixel shader and test them. The generated pixel shader can then be used with the mp3d Lib. You can compile the shader and then use him permanently. The execution speed depends on the graphics card. An image with 1024 * 1024 pixels with 16 bit takes me an average of 3 ms. I give you 54 test shader. The strength of the shader is the real-time changes (which I have not integrated into this shader program). The help button has no function. Anyone who has a desire to help can write a help file and send me the text (as MessageRequester)?
PixelShaderprogram
http://www.file-upload.net/download-282 ... r.zip.html
Here is a little introduction. The program can load two images called TextureA and TextureB. Further, there are three variables Var1.f, Var2.f and Var3.f which can be controlled via sliders. The range is from 0-1 here (float) and the default is 0.5 (middle)
Example Shader:
Creating a shader: This is written as ascii text and corresponds to the C language
1) Import of the variables
Here the texture is defined TextureA. variables are to upper / lower case sensetive!
Here is the "Slider Variabel" is defined and delivered
2) treatment of texture in the shader
The functions AddressU etc. define the properties of the texture in the shader
3) Function invers
PSInverse -> name of function
float2 Tex : TEXCOORD0 -> Doublefloat, these are the texturecoords
return 1.0f - tex2D(Sampler1, Tex); -> Texture return means, the color rgba is 255,255,255,255 minus color and make every color invers
3) Brightness function
Example of brightness Shader
Var1 = 0.5(middle of the Slider) * 2 = 1 every color are color * 1. Slider up Hoch = color * 2 or Slider down color * 0
4) start function
technique t1 -> this i one of some possible functions you can write in a shader (The Pixelshadertestprogramm use t1 to start a shader)
pass p1 -> Number of passes p1 = 1. For more complex shaders, you have several loops / steps and then requires several iterations
PixelShader = compile ps_2_0 PSInverse(); -> Depending on the graphics card can be used more and more complex commands
Here is the finished shader to to invert a texture
finished shader
Greetings
Michael
I would like to introduce you to a program that I created with my mp3d Lib (sourcecode is in my mp3d engine available). It is possible to create pixel shader and test them. The generated pixel shader can then be used with the mp3d Lib. You can compile the shader and then use him permanently. The execution speed depends on the graphics card. An image with 1024 * 1024 pixels with 16 bit takes me an average of 3 ms. I give you 54 test shader. The strength of the shader is the real-time changes (which I have not integrated into this shader program). The help button has no function. Anyone who has a desire to help can write a help file and send me the text (as MessageRequester)?
PixelShaderprogram
http://www.file-upload.net/download-282 ... r.zip.html
Here is a little introduction. The program can load two images called TextureA and TextureB. Further, there are three variables Var1.f, Var2.f and Var3.f which can be controlled via sliders. The range is from 0-1 here (float) and the default is 0.5 (middle)
Example Shader:
Creating a shader: This is written as ascii text and corresponds to the C language
1) Import of the variables
Code: Select all
texture TextureA;
Code: Select all
float Var1;
2) treatment of texture in the shader
Code: Select all
sampler Sampler1 = sampler_state
{
texture = <TextureA>;
AddressU = Clamp;
AddressV = Clamp;
MipFilter = None;
MagFilter = None;
MinFilter = None;
};
3) Function invers
Code: Select all
float4 PSInverse(float2 Tex : TEXCOORD0) : COLOR
{
return 1.0f - tex2D(Sampler1, Tex);
}
float2 Tex : TEXCOORD0 -> Doublefloat, these are the texturecoords
return 1.0f - tex2D(Sampler1, Tex); -> Texture return means, the color rgba is 255,255,255,255 minus color and make every color invers
3) Brightness function
Example of brightness Shader
Code: Select all
return tex2D(Sampler1, Tex)*Var1*2;
4) start function
Code: Select all
technique t1
{
pass p1
{
PixelShader = compile ps_2_0 PSInverse();
}
}
pass p1 -> Number of passes p1 = 1. For more complex shaders, you have several loops / steps and then requires several iterations
PixelShader = compile ps_2_0 PSInverse(); -> Depending on the graphics card can be used more and more complex commands
Here is the finished shader to to invert a texture
finished shader
Code: Select all
texture TextureA;
sampler Sampler1 = sampler_state
{
texture = <TextureA>;
};
float4 PSInverse(float2 Tex : TEXCOORD0) : COLOR
{
return 1 - tex2D(Sampler1, Tex);
}
technique t1
{
pass p1
{
PixelShader = compile ps_2_0 PSInverse();
}
}
Michael