Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / set camera range and ising it with shader

Author
Message
Kuper
17
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 17th Dec 2014 08:13 Edited at: 17th Dec 2014 09:46
HI!
I discover that changing camera range in dbpro also added some offsets to depth value that i used in shader.
So i need your help.I need to have my camera range like 10,15000 but exactly the same depth value in shader like I have camera range 1,15000. So i need to set near camera range but have correct depth render in same time.

I attached files with some example.Its simple - you change camera range in dbpro and depth value is changing is shader.

Also here is shader code :

matrix WorldVP:WorldViewProjection;

struct In_Geometry
{
float4 Pos: POSITION;
};
struct Out_Geometry
{
float4 Pos: POSITION;
float4 Depth:TEXCOORD1;
};
Out_Geometry VS_Geometry(In_Geometry IN)
{
Out_Geometry OUT;
OUT.Pos=mul(IN.Pos,WorldVP);
OUT.Depth=OUT.Pos;
return OUT;
}

float4 PS_Geometry(Out_Geometry IN) : COLOR
{
float check=((IN.Depth.z)/(IN.Depth.w));

float3 color=float3(1,0,0);
if (check>0.9980)
{
color=float3(0,1,0);
}

return float4(color,1);
}


technique Geometry
{
pass p1
{
vertexShader = compile vs_3_0 VS_Geometry();
pixelShader = compile ps_3_0 PS_Geometry();
}
}

Thanks


PS
I also get an idea to set WorldVP matrix - manually , using custom camera settings. It maybe will work but I dont know how to set dbpro matrixes for WorldViewProjection
I find this code but it doesnt work for me



Attachments

Login to view attachments
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 17th Dec 2014 12:20
Care to explain what it is you want to achieve more in detail?
If you change the camera range, the depth values will of course change as well. Basically a screen-space depth value is a non-linear transform of the distance from the pixel being rendered to the camera's near plane (which is either 1 unit in front of the camera with the range (1, 15000) or 10 units in front of it with the range (10, 15000)) into the 0..1 range. Most of the resolution will be used close to the camera, meaning that (just an example) objects with a distance of 1 through 100 from the camera will get depth values from 0 to 0.9, the remaining 14089 units will all be squeezed into the last 0.9..1.0 range.

Kuper
17
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 17th Dec 2014 13:28
So I need to change camera range to 20,15000 but have depth render like camera range is still 1,15000 . I think it is possible to do by setting WorldViewProjecting matrix manually - set camera to custom range and then set WorldViewProjecting matrix with it.

Login to post a reply

Server time is: 2025-05-11 08:11:31
Your offset time is: 2025-05-11 08:11:31