Jump to content
  • Advertisement
Sign in to follow this  
yurixd

verifying vertex&pixel shader

This topic is 4815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have made a easy pixel and vertex shader. HOw can I verify easily without create all the application (D3Dobject, D3DRenderTarget, Texture...) that my pixel Shader it works. I know there is some programs as rendermonkey and fx composer, but I have no idea how do they work ... ! Can someone tell me a easy way to work with and verify my shaders ? My card doesn-t not support pixel shaders yet, so I need that they run in REF device! These are the codes, I am sure they compile .. Thanks and any help will be greatful! ---vertex shader---- float4x4 WorldViewProj; void VS_HLL_EX1(in float4 vPos : POSITION, in float2 vTex : TEXCOORD0, in float2 vTex1 : TEXCOORD1, out float4 oPos : POSITION, out float2 oTex : TEXCOORD0, out float2 oTex1 : TEXCOORD1) { oPos = mul(vPos, WorldViewProj); oTex = vTex;\n" oTex1 = mul(vTex1, (float2x2)WorldViewProj) + (float2)WorldViewProj[3][0]; //rotation } ---pixel shader--- sampler DiffuseSampler; sampler DiffuseSampler2; void PS_HLL_EX1(in float2 vTex : TEXCOORD0, in float2 vTex1 : TEXCOORD1, out float4 Col : COLOR0, out float4 weights : COLOR1, out float4 Col2 : COLOR2) { int i=0;\n float2 frac2; float2 texsize; float2 floor2; float2 coord2[4];//present coordonates float values [4]; float2 sampleOffsets[4];//offsets for my 4 near neighborrs in 2D, 8 in 3D texsize.x = 256; texsize.y= 256; sampleOffsets[0].x = 0; sampleOffsets[0].y = 0; sampleOffsets[1].x = 1; sampleOffsets[1].y = 0; sampleOffsets[2].x = 0; sampleOffsets[2].y = 1; sampleOffsets[3].x = 1; sampleOffsets[3].y = 1; coord2[0] = vTex1*texsize - 0.5; frac2 = frac (coord2[0]); floor2 = floor (coord2[0]); for (i=0; i<4; i++) {coord2 = (floor2 + sampleOffsets + 0.5)/texsize; values = tex2D (DiffuseSampler2, coord2); //need this values (4floats) (I have made just a texture with grey levels //so...1float) } Col.x=values[0]; Col.y=values[0]; Col.z=values[0]; Col.w=1; weights.x = (1-frac2.x)*(1-frac2.y); // 1 float output weights.y = frac2.x*(1-frac2.y);// 1 float output weights.z = (1-frac2.x)*frac2.y; //1float output weights.w = frac2.x*frac2.y; // 1float output Col2.xyzw = tex2D (DiffuseSampler, vTex);//1float (grey level) }

Share this post


Link to post
Share on other sites
Advertisement
Hi there yurixd,
How are you doing?

The Problem
Testing vertex/pixel shaders.

The Solution
I would say that the effect edit program is probably the easiest way to test your shaders. The nice thing about render monkey and fx composer is that they already have a library of nice shaders that are included.

Check out effect edit, it's a fantastic program and really simple to use and it saves you the download but... render monkey and fx composer are really in another league of their own.

If your card isn't shaders capable you might have a problem.
"Choosing the Device Type
To debug a shader, the shader must be running on the right type of Direct3D device since vertex and pixel shaders can only be debugged on certain devices. Once you determine whether you want to debug a vertex shader, a pixel shader, or both, you can use the following table to choose a device type that supports debug."


This might be an interesting read to see if what type of device you can use with vertex and pixel shaders.
Getting Started Debugging Shaders

I hope this helps.

PS: Effect edit is included in the utilities directory of your DirectX SDK installation.

Share this post


Link to post
Share on other sites
I think it should not be a problem using software implementation (REF)
watching the table of choosing devyce type for debugging in this link
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/ProgrammingGuide/HLSLShaders/DebuggingShaders.asp
isn-t it ??

Anyway, I have try to see if my pixel shader works in effect edit writting this code
float4x4 WorldViewProj;
void VS_HLL_EX1(in float4 vPos : POSITION, in float2 vTex : TEXCOORD0, in float2 vTex1 : TEXCOORD1, out float4 oPos : POSITION, out float2 oTex : TEXCOORD0, out float2 oTex1 : TEXCOORD1){
oPos = mul(vPos, WorldViewProj);
oTex = vTex;
oTex1 = mul(vTex1, (float2x2)WorldViewProj) + (float2)WorldViewProj[3][0]; //rotation
}

sampler DiffuseSampler;
sampler DiffuseSampler2;
void PS_HLL_EX1(in float2 vTex : TEXCOORD0, in float2 vTex1 : TEXCOORD1, out float4 Col : COLOR0, out float4 weights : COLOR1, out float4 Col2 : COLOR2)
{
int i=0;
float2 frac2;
float2 texsize;

float2 floor2;
float2 coord2[4];//present coordonates
float values [4];
float2 sampleOffsets[4];//offsets for my 4 near neighborrs in 2D, 8 in 3D
texsize.x = 256;
texsize.y= 256;
sampleOffsets[0].x = 0;
sampleOffsets[0].y = 0;
sampleOffsets[1].x = 1;
sampleOffsets[1].y = 0;
sampleOffsets[2].x = 0;
sampleOffsets[2].y = 1;
sampleOffsets[3].x = 1;
sampleOffsets[3].y = 1;
coord2[0] = vTex1*texsize - 0.5;
frac2 = frac (coord2[0]);
floor2 = floor (coord2[0]);
for (i=0; i<4; i++){
coord2 = (floor2 + sampleOffsets + 0.5)/texsize;
values = tex2D (DiffuseSampler2, coord2); //need this values (4floats) (I have made just a texture with grey levels //so...1float)
}
Col.x=values[0];
Col.y=values[0];
Col.z=values[0];
Col.w=1;
weights.x = (1-frac2.x)*(1-frac2.y); // 1 float output
weights.y = frac2.x*(1-frac2.y);// 1 float output
weights.z = (1-frac2.x)*frac2.y; //1float output
weights.w = frac2.x*frac2.y; // 1float output
Col2.xyzw = tex2D (DiffuseSampler, vTex);//1float (grey level)
}
but i have an error compilation telling that there are no techniques. What does mean??

Thanks,
Jesus

Share this post


Link to post
Share on other sites
Hi there yurixd,
How are you doing buddy?

The Problem
What are techniques and how do I implement them?

The Solution
A Technique
"Techniques provide the rendering muscle. A technique encapsulates the effect state that determines a rendering style. A technique is made up of one or more passes. "

This just means that your technique that you add is your kung fu. By that I mean that your technique will be the main part of your shader if your disregard the pixel and vertex shader methods.

Syntax for a Technique
technique [ id ] [< annotation(s) >]
{ pass(es) }

Example:

float4x4 worldViewProj : WORLDVIEWPROJ; //our world view projection matrix

//application to vertex structure
struct a2v
{
float4 position : POSITION0;
};

//vertex to pixel shader structure
struct v2p
{
float4 position : POSITION0;
};

//VERTEX SHADER
void vs( in a2v IN, out v2p OUT )
{
//getting to position to object space
OUT.position = mul(IN.position, worldViewProj);
}


technique simple
{
pass p0
{
vertexshader = compile vs_1_1 vs();
}
}


This is a simple diffuse shader that just shows you how to implement a technique.

I hope this helps buddy,

PS: If you want more information look at the effects the effectedit program uses and see how they are structured.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!