|
0 registered members (),
635
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Simulate alpha channel?
#226178
09/08/08 11:21
09/08/08 11:21
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
Hi! I'm trying to simulate alpha channel for a long time, but all this shader and postprocessing stuff seems to be too complex  What I need to do is: 1. Render scene as usual with all objects on it. Player entity might be hidden by other entities. 2. Render scene with no entities at all. 3. Output scene(2) with no entites + only visible parts of player entity from scene(1). This way entities on the scene will act like alpha channel and they will not be displayed on teh final render, except main player. Is it possibile to make it somehow? I'll appreciate any pointer on this matter, I do not know where to start from. Regards, Konstantin.
Last edited by RyuMaster; 09/09/08 00:31.
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Simulate alpha channel?
[Re: RyuMaster]
#226260
09/08/08 18:17
09/08/08 18:17
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
I have found this topic at the forums: http://www.coniserver.net/ubb7/ubbthreads.php?ubb=showflat&Number=136642&Searchpage=1&Main=15891&Words=%22render+to+alpha%22&Search=true#Post136642 There is some shader sample inside: float4x4 matWorldViewProj;
struct vertexInput { float4 position : POSITION0; float4 texCoord : TEXCOORD0; }
struct vertexOutput { float4 position : POSITION0; float4 texCoord : TEXCOORD0; }
texture mtlSkin1; // color texture mtlSkin2; // alpha
sampler colorSampler = sampler_state { texture = <mtlSkin1>; } sampler alphaSampler = sampler_state { texture = <mtlSkin2>; }
vertexOutput VS(in vertexInput IN) { vertexOutput OUT;
OUT.position = mul(IN.position, matWorldViewProj); OUT.texCoord = IN.texCoord; }
float4 PS(in vertexOutput IN) : COLOR0 { float3 color = tex2D(colorSampler, IN.texCoord).rgb; float alpha = tex2D(alphaSampler, IN.texCoord).rgb;
return float4(color, alpha); }
technique simple { pass p0 { AlphaBlendEnable = true;
VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_1_4 PS(); } } Maybe it can be adapted somehow? Curenntly I do not undestand, if I assign this shader to the player model, where will it take alpha info and rgb info from? What pars I should be chanign on the way to adapting it to my needs?
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Stimulating the alpha channel?
[Re: ello]
#226389
09/09/08 15:27
09/09/08 15:27
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
In other words, all I need is to assign this code to entity with correct textures, and it will render only this entity, and all other objects will be threaten as alpha but will not be drawn? I'll test and see how it works.
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Stimulating the alpha channel?
[Re: RyuMaster]
#226393
09/09/08 16:04
09/09/08 16:04
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
Is this code for Lite-C? I can not gei it running, few ";" vere mising after struct and samplers, and now I'm stuck with error ***'VS': function must return a value***
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Stimulating the alpha channel?
[Re: RyuMaster]
#226548
09/10/08 10:05
09/10/08 10:05
|
Joined: Mar 2006
Posts: 2,758 Antwerp,Belgium
frazzle
Expert
|
Expert
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
|
That code snippet isn't Lite-C nor C-script based  It's called HLSL, a shader language for simulating vertex and pixel based effects on D3D. The errors you get from the compiler are quite basic and due to the fact that you probably never have heard of HLSL, I recommend that you first start with getting to know the very basic of it  I'll comment the errors and give you the matching code: - error comment: few ";" vere mising after struct and samplers Since HLSL is C like, you need to be carryful when using semicolons.
// sampler
sampler colorSampler = sampler_state
{
texture = <yourTextureFile>;
}; // -> important !!
// structure
struct vertexInput
{
float4 position : POSITION0;
float4 texCoord : TEXCOORD0;
}; // -> important !!
and now I'm stuck with error ***'VS': function must return a value*** Again, since HLSL is C based, you need to apply for the correct syntax. You get this error because your vertex shader doesn't return a value since you don't adress the function for it correctly. If you don't want your function to return a value, then you should use a void function.
void VS(in float4 InPos : POSITION, in float2 InTex : TEXCOORD0,
out float4 OutPos : POSITION, out float2 OutTex : TEXCOORD0)
{
OutPos = mul(InPos, matWorldViewProj);
OutTex = InTex;
}
- matching code: I'll make the function as basic as possible for an alpha based effect. This means, no structures but with a void function:
float4x4 matWorldViewProj;
texture entSkin1;
// color map which means the initial skin you applied for your model. This must also
// contain an alpha channel -> RGBA map which can be done with Adobe, The Gimp, ...
// This is what ello indicated before as well.
sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
};
void VS(in float4 InPos : POSITION, in float2 InTex : TEXCOORD0,
out float4 OutPos : POSITION, out float2 OutTex : TEXCOORD0)
{
OutPos = mul(InPos, matWorldViewProj);
OutTex = InTex;
}
float4 PS(in float2 InTex : TEXCOORD0) : COLOR
{
float4 color = tex2D(ColorMapSampler, InTex);
return color;
}
technique AlphaMapping
{
pass p0
{
AlphaBlendEnable = true;
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_1_1 PS();
}
}
This should work properly if I didn't forget anything stupid ^^ Cheers Frazzle
Antec® Case Intel® X58 Chipset Intel® i7 975 Quad Core 8 GB RAM DDR3 SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB NVIDIA® GeForce GTX 295 Memory 1795GB
|
|
|
Re: Stimulating the alpha channel?
[Re: frazzle]
#226608
09/10/08 15:13
09/10/08 15:13
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
Thanks a lot, very good explanation! I have completed shader workshop as well, now it all seems more familair. I'll try to get it working.
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Simulate alpha channel?
[Re: RyuMaster]
#226619
09/10/08 15:41
09/10/08 15:41
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
"Cannot implicitly convert from float3 to float4. reutn color"
What can cause this error? I have tried manipulating var and function types, but it helps not.
Also I have question. I was looking at teh code many times, but still can not get, what part of it actually renders all entities to black? As I understand, it should render all black and only one having alpha channel white, and then mix them on final.
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
Re: Simulate alpha channel?
[Re: RyuMaster]
#226651
09/10/08 17:16
09/10/08 17:16
|
Joined: Aug 2006
Posts: 155
RyuMaster
OP
Member
|
OP
Member
Joined: Aug 2006
Posts: 155
|
Still the same error, this is odd. Maybe I must return 4 colors when there is alpha channel, 3 is not enough? Well, anyway, I think I can write shader myself, as soon as I understand one question. I'll try explain it one more time, probably I'm confusing things here. Here is some stupid picture (thanks paint) Green square is some panel with layer-1, which is always drawn at the back of the stage. Red cube is just a simple entity. Yellow rocket is player character, which has shader assigned to it. (1). Pictures is what we should get on normal render. It is not good. ()2. Second - we render all entites to black, and all entites with assigned shader - to white. So we get black and white "alpha channel" for scene entitites. (3). We mix them on some level, and we get result as on picture 3. I'm not asking for shader, maybe I can write it myslef after I hear some theory, like is it possible to combine them to get result "3"? Because, if I do it after scene is rendered, on pixel level, all pixel witch are behind entities will be already clipped away, correct? So, if I use this "alpha channel", and remove all what was black from final render, will I get what I need? No any "black holes"? I just do not get it, how is it going to work?
What kills me not, that makes me stronger.
***Working on RPG/RTS***
|
|
|
|