I’d like to be able to see the player when a large object comes between the camera and the player.
I think this involves two different problems:
Rendering when the camera is inside an object
Currently, when the camera is inside an object, the interior polygons aren’t rendered, or they appear solid if I enable Material DrawBackFace. I’d like to render them semi-transparent. How can I achieve that?
Rendering an object between the camera and the player
If an object is between the camera and the player, it fully obstructs the view. In this case, I’d like the entire object to be rendered semi-transparent.
I can use ZGEBullet zbtRayTest to trace a line between the camera and the player and check for collisions in between. But is there a better way to achieve this, perhaps with shaders or depth comparison?
Filming an object behind a wall
Moderator: Moderators
Re: Filming an object behind a wall
Hi Ats,
There's a bunch of different ways to tackle this kind of situation. The easiest approach is probably the "Super Mario Sunshine" method .. where you basically render a "shadow" version of your character ( depth-testing disabled ) after rendering your environment, but before rendering your character as usual ( depth-testing enabled ). You can use the same approach for semi transparant / dithered effects. Attached is a simple example
K
There's a bunch of different ways to tackle this kind of situation. The easiest approach is probably the "Super Mario Sunshine" method .. where you basically render a "shadow" version of your character ( depth-testing disabled ) after rendering your environment, but before rendering your character as usual ( depth-testing enabled ). You can use the same approach for semi transparant / dithered effects. Attached is a simple example

K
- Attachments
-
- Sonic.zgeproj
- (63.47 KiB) Downloaded 87 times
Re: Filming an object behind a wall
I saw your example with Jet Set Radio years ago, but I hadn’t thought about it in this context. It’s not exactly what I’m trying to achieve, but I’ll give it a try. It’s a simple approach, so it might work well 

Re: Filming an object behind a wall
Hi Ats,
Coming back to your original question(s) ..
K
Coming back to your original question(s) ..
You can render the inside of a object using a different material. Depending on whether you're using shaders or not you can render a mesh twice ( once using back culling & once using front culling ), or you can render double-sided and use the gl_FrontFacing variable in your fragment shader.
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
<OnLoaded>
<ZExternalLibrary ModuleName="OpenGL32">
<Source>
<![CDATA[//
const int GL_FRONT = 0x0404;
const int GL_BACK = 0x0405;
//
void glCullFace(int mode){}]]>
</Source>
</ZExternalLibrary>
<ZExpression>
<Expression>
<![CDATA[//
for(int i=0; i<8; i++)
{
float a = i*PI/4;
Box.Position.X = sin(a)*8;
Box.Position.Z = cos(a)*8;
Box.Rotation.Y = i/8f;
createModel(Box);
}]]>
</Expression>
</ZExpression>
</OnLoaded>
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[//
App.CameraRotation.Y += App.DeltaTime/32;
//
float a = App.CameraRotation.Y*PI*2;
App.CameraPosition.X = -sin(a)*8;
App.CameraPosition.Z = cos(a)*8;]]>
</Expression>
</ZExpression>
</OnUpdate>
<Content>
<Model Name="Box" Position="-5.6569 0 5.6569" Rotation="0 0.875 0" RenderOrder="1">
<OnRender>
<ZExpression>
<Expression>
<![CDATA[// You might want to do a fast collision check ( AABB for example )
// and only render the back material when the collision is TRUE
@UseMaterial(Material: BoxBackMaterial);
glCullFace(GL_FRONT);
@RenderMesh(Mesh: BoxMesh);
@UseMaterial(Material: BoxFrontMaterial);
glCullFace(GL_BACK);
@RenderMesh(Mesh: BoxMesh);]]>
</Expression>
</ZExpression>
</OnRender>
</Model>
<Mesh Name="BoxMesh">
<Producers>
<MeshBox/>
</Producers>
</Mesh>
<Material Name="BoxBackMaterial" Shading="1" Color="0 0.502 1 0.5" Light="0" Blend="1"/>
<Material Name="BoxFrontMaterial" Shading="1" Color="0 0.502 1 1"/>
</Content>
</ZApplication>
That's pretty ambiguous. How do/would you determine whether a object is between the camera and the player? And what counts as "fully obstructs the view"? Most games do these kinds of things in screen-space, not at "object" level.
Is there any particular game that does what you're trying to do? That might make it a bit easier to give you a useful answer.
K
Re: Filming an object behind a wall
Again, a perfect example. I'll play a bit with the shadow hedgehog visuals and see if it is enough, or if back culling materials are needed. Thanks 
