stupid pixel shader

Started by
13 comments, last by prux 15 years, 7 months ago
hey! Im (would) use DX 8.1 and vertex shader... heres the example:

sampler2D g_samSrcColor;

float4 main( float2 Tex : TEXCOORD0 ) : COLOR0
{
    float4 Color;
    
    Color = tex2D( g_samSrcColor, Tex.xy)*4;
    return Color;
}

technique PostProcess
{
    pass p1
    {
        VertexShader = null;
        PixelShader = compile ps_1_4 main();
    }

}
the samples is "converted" to assembly, because 8.1 doesnt know HLSL language: fxc.exe /nologo /Tps_1_2 /Emain shader.ps > shader.asm

//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.08.299.0000
//
//   fxc /nologo /Tps_1_2 /Emain shader.ps
//
//
// Parameters:
//
//   sampler2D g_samSrcColor;
//
//
// Registers:
//
//   Name          Reg   Size
//   ------------- ----- ----
//   g_samSrcColor s0       1
//

    ps.1.2
    def c0, 4, 4, 4, 4
    tex t0
    mul r0, t0, c0

// approximately 2 instruction slots used (1 texture, 1 arithmetic)

this currently does nothing... although theres another example: ps.1.0 def c0, 1.0f, 1.0f,1.0f, 1.0f tex t0 sub r0,c0,t0 this works (at least has got effect). Only this example works, this wastebasket doesnt want to work for me!! Any idea why?
Advertisement
Why are you using DX 8.1? Why not 9?
This is your life, and it's ending one minute at a time. - Fight club
it dont works under 9 neither
This may happend due to many reasons, most probably your card is an ATI card and you are trying to run a PS1.2.

Due to lack of standarization on the first PS cards, nVidia video cards are able to handle PS 1.1, 1.2, 1.3 and 2.0 or higher. ATI video cards are able to handle PS 1.4 and 2.0 or higher. So if you try to run a 1.2 shader in an ATI card it may fail

In the other hand, there is no support for PS1.0 in any card. 1.0 was something like the first PS concept by nVidia and was never released in any video card so trying to make a 1.0 shader will probably fail.

That said, I agree with EmptyVoid (a really empty name I must say) and suggest you to move to PS2.0 or higher unless you have a really compelling reason to stay with 1.x shaders.

Luck!
Guimo

and I guess, Pixel Shader 2.0 is only available under DX 9 isnt it?
luckily I found some correction, I can still use it but there are more questions tough.

So, heres an example:

sampler2D g_samSrcColor;
float4 main( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color;

Tex.x = Tex.x * 0.5;
Color = tex2D( g_samSrcColor, Tex.xy);
return Color;
}

technique PostProcess
{
pass p1
{
VertexShader = null;
PixelShader = compile ps_1_4 main();
}
}

it works. Theres a color sample:

Quote:Color = tex2D( input , Tex.xy)*3;


this also works,

Quote:Color.r = Color.r / 2;


this too, but WHEN I want to

Quote:Color.r = Color.r * 2;


the FXC says:

Quote:shader.ps(18): warning X4704: literal values outside range -1 to 1 are clamped on all ps_1_x shading models


and it dont work :S

Thx the replies! I think I tried to "hard" examples first.
Mint látod, a szineket -1 és 1 közé "szorítja", mivel osztásnál egyre inkább a 0 felé halad az érték, ellenben szorzásnál könnyen áteshet ezeken.

Szineket többnyire 0..1 tartományban határozunk meg.

So, understand? :)
furcsa, idáig 0...255 tartományban mozogtak... akkor hogy lehet ezt megoldani? :)
Minden grafikus API (OpenGL, DX) a szineket float-ként tárolja, 0..1 tartományban, a nagyobb precizitás miatt. Persze te megadhatod 0..255 között (opengl-ben pl. glColor3ub, DX-ben nem tudom), de "belül" úgy is float-ban tárolódik, és ebben a formában is dolgozik vele.

Lehet, nem örülnek itt, hogy magyarul irunk. :D
its clear now, but I dont know then how to avoid this... when I mul the whole color (Color = tex2D( input , Tex.xy)*3;) it works, and when just a part of it (Color = tex2D( input , Tex.xy).R*3;) it doesnt?

This topic is closed to new replies.

Advertisement