Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
0 registered members (), 635 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Simulate alpha channel? #226178
09/08/08 11:21
09/08/08 11:21
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

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 frown

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
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

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:

Quote:
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: RyuMaster] #226359
09/09/08 12:16
09/09/08 12:16
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline
Senior Expert
ello  Offline
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
you could use entSkin1 and entSkin2 in the code, which would than use the first and second skin of your model. now it uses material skins

btw, you dont need two skins, since one skin can have rgb + alpha informations

Re: Stimulating the alpha channel? [Re: ello] #226389
09/09/08 15:27
09/09/08 15:27
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

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
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

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 Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
That code snippet isn't Lite-C nor C-script based wink wink
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 smile smile

I'll comment the errors and give you the matching code:

- error comment:
Quote:
few ";" vere mising after struct and samplers

Since HLSL is C like, you need to be carryful when using semicolons.
Code:
 
// sampler 
sampler colorSampler = sampler_state 
{
texture = <yourTextureFile>;
}; // -> important !! 


Code:
// structure
struct vertexInput 
{
float4 position : POSITION0;
float4 texCoord : TEXCOORD0;
}; // -> important !! 


Quote:
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.

Code:
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:

Code:
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
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

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
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

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] #226636
09/10/08 16:18
09/10/08 16:18
Joined: Oct 2005
Posts: 4,771
Bay City, MI
lostclimate Offline
Expert
lostclimate  Offline
Expert

Joined: Oct 2005
Posts: 4,771
Bay City, MI
"float3 color = tex2D(ColorMapSampler, InTex);"
should be:
"float3 color = tex2D(ColorMapSampler, InTex).rgb;"

Re: Simulate alpha channel? [Re: RyuMaster] #226651
09/10/08 17:16
09/10/08 17:16
Joined: Aug 2006
Posts: 155
R
RyuMaster Offline OP
Member
RyuMaster  Offline OP
Member
R

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***
Page 1 of 2 1 2

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1