Need help with 3D technique.
Need help with 3D technique.
Hi,
I´m trying to create realistic shadows inside a box that has holes on some of the walls. Light is coming from both outside the box and also from the inside.
The box is supposed to be fully inclosed with 6 sides. My problem is that I want to remove one side so I can see what´s inside, but without removing the shadows that this side creates.
How can I achieve this? The issue comes mainly with the outside light that in some positions shines right into the box through my "invisible wall".
Any ideas?
//Andreas..
I´m trying to create realistic shadows inside a box that has holes on some of the walls. Light is coming from both outside the box and also from the inside.
The box is supposed to be fully inclosed with 6 sides. My problem is that I want to remove one side so I can see what´s inside, but without removing the shadows that this side creates.
How can I achieve this? The issue comes mainly with the outside light that in some positions shines right into the box through my "invisible wall".
Any ideas?
//Andreas..
Re: Need help with 3D technique.
Fully transparent texture will do it... Shadows are still cast by invisible objects
Re: Need help with 3D technique.
Thanks for your reply!
But I thought that light passes through transparent textures and created correct shadows. Am I wrong?
I need to test that. If I for example replaced my "holes" in the box with "windows"(a couple of polygons with a 90% transparent windowtexture), wouldn´t light pass through those anymore at all?
I assumed that if I do that then light will pass but the intensity would be 10% and still create shadows.
But I thought that light passes through transparent textures and created correct shadows. Am I wrong?
I need to test that. If I for example replaced my "holes" in the box with "windows"(a couple of polygons with a 90% transparent windowtexture), wouldn´t light pass through those anymore at all?
I assumed that if I do that then light will pass but the intensity would be 10% and still create shadows.
Re: Need help with 3D technique.
I did a test earlier. A cube with a fully transparent texture will still cast a shadow on terrain
Re: Need help with 3D technique.
Hi,
Your suggestions work! A 100% transparent texture doesn´t let any light pass.
But I´m having trouble with getting the correct result without messing up everything else.
To enable a texture with a alpha channel I need to set some parameters in the material file.
Like:
scene_blend alpha_blend
depth_write off
colour_op alpha_blend
But my whole scene is the same mesh and entity and everything is using the same textureatlas, where I altered the alphachannel only on the part that the transparent side uses.
But the parameter "depth_write off" destroys everything. The lighting and shadows are gone and the whole mesh´s polygons orders are changed.
I assume I could do the transparent side of the cube as a separate mesh/entity with its own material and texture, but that´s not optimal.
There must be a way I can use a textureatlas where the alphachannel is different over the texture?
Any ideas?
Your suggestions work! A 100% transparent texture doesn´t let any light pass.
But I´m having trouble with getting the correct result without messing up everything else.
To enable a texture with a alpha channel I need to set some parameters in the material file.
Like:
scene_blend alpha_blend
depth_write off
colour_op alpha_blend
But my whole scene is the same mesh and entity and everything is using the same textureatlas, where I altered the alphachannel only on the part that the transparent side uses.
But the parameter "depth_write off" destroys everything. The lighting and shadows are gone and the whole mesh´s polygons orders are changed.
I assume I could do the transparent side of the cube as a separate mesh/entity with its own material and texture, but that´s not optimal.
There must be a way I can use a textureatlas where the alphachannel is different over the texture?
Any ideas?
Re: Need help with 3D technique.
Hello,
Stencil shadows are calculated using a stencil mask created from the base mesh. The stencil buffer doesn't care if you have a transparent texture as it just works off of the geometry. If you use texture shadows then the shadows shouldn't be cast through the transparent textures.
Just a little explanation on why this works.mrw wrote: A 100% transparent texture doesn´t let any light pass.
Stencil shadows are calculated using a stencil mask created from the base mesh. The stencil buffer doesn't care if you have a transparent texture as it just works off of the geometry. If you use texture shadows then the shadows shouldn't be cast through the transparent textures.
"depth_write on" is needed for alpha blending otherwise you'll get the fun house mirrors. The current PB/Ogre version doesn't support OIT (Order Independent Transparency) shaders.mrw wrote: But the parameter "depth_write off" destroys everything. The lighting and shadows are gone and the whole mesh´s polygons orders are changed.
It's not optimal, but it might be the best route when limited to older versions of DX/OGL.mrw wrote: I assume I could do the transparent side of the cube as a separate mesh/entity with its own material and texture, but that´s not optimal.
Re: Need help with 3D technique.
Thanks for your answer.
Seems really stupid if this didn´t work.
If I model a spaceship with a windscreen that´s partially transparent by using the alphachannel, what would I have to do to make that work? Have the windscreen as a completely separate object? Or any other technique?
If that is the case is it because PB uses a very old OGRE-version?
And on another note, if I wanted shadows, or atleast controlled light intensity through an alphatexture. Is this doable in current PB/OGRE?
But when I set this to ON I don´t get any alpha blending at all. Does this mean that I cannot use alphatextures on complex meshes since it messes things up?"depth_write on" is needed for alpha blending otherwise you'll get the fun house mirrors
Seems really stupid if this didn´t work.
If I model a spaceship with a windscreen that´s partially transparent by using the alphachannel, what would I have to do to make that work? Have the windscreen as a completely separate object? Or any other technique?
If that is the case is it because PB uses a very old OGRE-version?
And on another note, if I wanted shadows, or atleast controlled light intensity through an alphatexture. Is this doable in current PB/OGRE?
Re: Need help with 3D technique.
See if replacing
with this helps.mrw wrote: scene_blend alpha_blend
depth_write off
colour_op alpha_blend
Code: Select all
scene_blend alpha_blend
cull_hardware none
cull_software none
There might be a way to limit which materials are affected by which lights. Then you could have different lights for inside and outside. I don't remember for sure though if that's possible. I'm not sure about the shadow coloring portion.mrw wrote: And on another note, if I wanted shadows, or atleast controlled light intensity through an alphatexture. Is this doable in current PB/OGRE?
Re: Need help with 3D technique.
Ok,
I replaced "depth_write off" and "colour_op alpha_blend", with "cull_hardware none" and "cull_software none", but that didn´t help.
It just displays everything as it was before I added the alphachannel. Plus added backfaces to every polygon.
Can we confirm that it´s not possible to mix textures with and without alphachannel within the same mesh/entity? If not then how come it is so difficult to achieve that?
As I asked before: If I create a spaceship with a partially see-through windscreen, do I have to create the windscreen as a separate mesh/entity, or not?
Is there any example among the PB-3D ones that does this? Or if anyone has done this and come to any conclusion?
I can adapt to either answers, but I would like to know which it is.
OGRE seems to be overly complex.
I remember when I used Blitz3D to do lots of stuff like this and it was supereasy. If the texture had alphainformation it simply used that anywhere on the model. I just set the UV and thats´that. And if certain polygons needed other "material" settings(shininess, and things like that) I just grouped those together and specified another "surface". All within the same model-object.
With PB/OGRE everything regarding 3D takes 10 times as long just to figure out how to do stuff.
I replaced "depth_write off" and "colour_op alpha_blend", with "cull_hardware none" and "cull_software none", but that didn´t help.
It just displays everything as it was before I added the alphachannel. Plus added backfaces to every polygon.
Can we confirm that it´s not possible to mix textures with and without alphachannel within the same mesh/entity? If not then how come it is so difficult to achieve that?
As I asked before: If I create a spaceship with a partially see-through windscreen, do I have to create the windscreen as a separate mesh/entity, or not?
Is there any example among the PB-3D ones that does this? Or if anyone has done this and come to any conclusion?
I can adapt to either answers, but I would like to know which it is.
OGRE seems to be overly complex.
I remember when I used Blitz3D to do lots of stuff like this and it was supereasy. If the texture had alphainformation it simply used that anywhere on the model. I just set the UV and thats´that. And if certain polygons needed other "material" settings(shininess, and things like that) I just grouped those together and specified another "surface". All within the same model-object.
With PB/OGRE everything regarding 3D takes 10 times as long just to figure out how to do stuff.
Re: Need help with 3D technique.
I don't know what to tell you. For me, it's a bit of a guessing game without seeing your code.
If PB/Ogre is giving you this much grieve then maybe going back to Blitz3D is the answer.
If PB/Ogre is giving you this much grieve then maybe going back to Blitz3D is the answer.
Re: Need help with 3D technique.
Well, if can you produce a simple cube where all sides are textured from a 32-bit TGA-file, where 5 sides are fully non-transparent(pixelvalue in alpha=255) and one side has some transparency(random mix of alphavalues(0-255)) created from the alphachannel in the texture, I would be more than grateful.I don't know what to tell you. For me, it's a bit of a guessing game without seeing your code.
If you manage that with the whole cube is the same mesh/entity then you accomplish something I can´t. Which would be great!
Nah, Blitz3D is too old and not supported anymore. Dev has converted it to opensource and AFAIK no one has continued where he left. I switched to PB since it has so many advantages over Blitz3D. In every aspect I think, except 3D...If PB/Ogre is giving you this much grieve then maybe going back to Blitz3D is the answer.
Re: Need help with 3D technique.
After some experimenting and research it appears that Ogre(not sure about modern versions) doesn't do sorting for individual alpha faces. It only sorts the alpha entities.
Which means creating a separate entity for your windshield may be the best route.
Problem example.
Which means creating a separate entity for your windshield may be the best route.
Problem example.
Code: Select all
EnableExplicit
InitEngine3D()
InitSprite()
Enumeration
#Camera
#Cube
#CubeMesh
#Light
#Material
#Texture
#Window
EndEnumeration
Define.l CubeMesh
Define.l DeskH = 600
Define.l DeskW = 800
Define.l Event
If OpenWindow(#Window, 0, 0, DeskW, DeskH, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(#Window), 0, 0, DeskW, DeskH)
CreateTexture(#Texture, 256, 256)
StartDrawing(TextureOutput(#Texture))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, 128, 128, RGBA(255,0,0,32))
Box(128, 0, 128, 128, RGBA(0,255,0,255))
Box(0, 128, 128, 128, RGBA(0,0,255,32))
Box(128, 128, 128, 128, RGBA(255,255,255,255))
StopDrawing()
CreateMaterial(#Material, TextureID(#Texture))
MaterialBlendingMode(#Material, #PB_Material_AlphaBlend)
MaterialCullingMode(#Material, #PB_Material_NoCulling)
CreateCube(#CubeMesh, 50)
CreateEntity(#Cube, MeshID(#CubeMesh), MaterialID(#Material))
CreateLight(#Light, RGB(255,255,255), 100, 100, 100)
CreateCamera(#Camera, 0, 0, 100, 100)
MoveCamera(#Camera, 0, 30, 150, #PB_Absolute)
CameraLookAt(#Camera, 0, 0, 0)
CameraBackColor(#Camera, RGB(60,70,80))
WorldShadows(#PB_Shadow_Modulative)
Repeat
Event = WindowEvent()
RotateEntity(#Cube, 0, 1, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until Event = #PB_Event_CloseWindow
EndIf
EndIf
End
Re: Need help with 3D technique.
in purebasic v5.60 and above there is a new parameter #PB_Material_AlphaReject for the function SetMaterialAttribute. it do the same as in the material script, but we don't need the material script.
from the docs:
#PB_Material_AlphaReject: Enables alpha reject on the texture (useful for semi transparent textures like trees, window, etc).
look https://www.purebasic.com/documentation ... ibute.html
also https://www.purebasic.com/news80.php
@Samuel, you told me long time ago somewhere that we can add specific materials to every submesh when i have tried to make a points mesh contains several sizes of sprite points, so i have used this approach
it seems to work
@mrw, download this semi tranparent map
https://s13.postimg.org/3lb4ahwfr/world_map2.png
this is the original map:
https://s13.postimg.org/kylepjexz/world_map.png
i have changed it trasparency to 30% opacity. i don't know how to do it correctly in photoshop, it is a complex program. so i have changed only the ocean tranparency part .the #PB_Material_AlphaReject works better with semi transparent textures in which it can increase or decrease the trasparency.
SetMaterialAttribute(Mat, #PB_Material_AlphaReject, 75)
change 75 to 128 and you get full transparent map (ie on the ocean part)
every picture have its own specific
it is possible that some graphics cards does not display exactly what we need
by the way we can't cast the color of the semi tranparent mat to the shadow such as the color of stained glass on the table. may be but i have no idea
PB 5.60 or above only, tested with 5.61
from the docs:
#PB_Material_AlphaReject: Enables alpha reject on the texture (useful for semi transparent textures like trees, window, etc).
look https://www.purebasic.com/documentation ... ibute.html
also https://www.purebasic.com/news80.php
@Samuel, you told me long time ago somewhere that we can add specific materials to every submesh when i have tried to make a points mesh contains several sizes of sprite points, so i have used this approach
it seems to work
@mrw, download this semi tranparent map
https://s13.postimg.org/3lb4ahwfr/world_map2.png
this is the original map:
https://s13.postimg.org/kylepjexz/world_map.png
i have changed it trasparency to 30% opacity. i don't know how to do it correctly in photoshop, it is a complex program. so i have changed only the ocean tranparency part .the #PB_Material_AlphaReject works better with semi transparent textures in which it can increase or decrease the trasparency.
SetMaterialAttribute(Mat, #PB_Material_AlphaReject, 75)
change 75 to 128 and you get full transparent map (ie on the ocean part)
every picture have its own specific
it is possible that some graphics cards does not display exactly what we need
by the way we can't cast the color of the semi tranparent mat to the shadow such as the color of stained glass on the table. may be but i have no idea
PB 5.60 or above only, tested with 5.61
Code: Select all
#CameraSpeed = 1
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
DeskWid=DesktopWidth(0)
DeskHei=DesktopHeight(0)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
If OpenWindow(0, 0, 0, DeskWid, DeskHei, "Alpha to Shadow ..... use mouse/arrows to move/rotate the cam", #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0), 0, 0, DeskWid, DeskHei, 0, 0, 0)
;Parse3DScripts()
Tex = LoadTexture(#PB_Any, "world_map2.png");"3d-clipart-ghost-1.png")
Mat = CreateMaterial(#PB_Any, TextureID(Tex))
MaterialBlendingMode(Mat, #PB_Material_AlphaBlend)
MaterialCullingMode(Mat, #PB_Material_NoCulling )
SetMaterialAttribute(Mat, #PB_Material_DepthCheck, #True)
SetMaterialAttribute(Mat, #PB_Material_DepthWrite ,1)
SetMaterialAttribute(Mat, #PB_Material_AlphaReject, 75);128
CreateMaterial(0,LoadTexture(0,"Geebee2.bmp"))
MaterialCullingMode(0, #PB_Material_NoCulling )
PlaneTexture = LoadTexture(#PB_Any, "MRAMOR6X6.jpg");"3d-clipart-ghost-1.png")
PlaneMaterial=CreateMaterial(#PB_Any, TextureID(PlaneTexture))
PlaneMesh=CreatePlane(#PB_Any,400,400,1,1,1,1)
PlaneEntity=CreateEntity(#PB_Any,MeshID(PlaneMesh),MaterialID(PlaneMaterial),0,-40,0)
EntityRenderMode(PlaneEntity,0);#PB_Entity_CastShadow )
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 20, 80, #PB_Absolute)
CameraBackColor(0, RGB(255,255,0))
CameraLookAt(0,0,-20,0)
CreateLight(0,RGB(150,150,150),0,100,0)
CreateMesh(0)
MeshVertexPosition(-5,-5,0)
MeshVertexTextureCoordinate(0,0)
MeshVertexPosition(-5,5,0)
MeshVertexTextureCoordinate(0,1)
MeshVertexPosition(5,5,0)
MeshVertexTextureCoordinate(1,1)
MeshVertexPosition(5,-5,0)
MeshVertexTextureCoordinate(1,0)
MeshFace(0,1,2)
MeshFace(0,2,3)
AddSubMesh()
MeshVertexPosition(5,-5,10)
MeshVertexTextureCoordinate(0,0)
MeshVertexPosition(-5,-5,10)
MeshVertexTextureCoordinate(0,1)
MeshVertexPosition(-5,-5,0)
MeshVertexTextureCoordinate(1,1)
MeshVertexPosition(5,-5,0)
MeshVertexTextureCoordinate(1,0)
MeshFace(0,1,2)
MeshFace(0,2,3)
AddSubMesh()
MeshVertexPosition(5,5,0)
MeshVertexTextureCoordinate(0,0)
MeshVertexPosition(5,5,10)
MeshVertexTextureCoordinate(0,1)
MeshVertexPosition(5,-5,10)
MeshVertexTextureCoordinate(1,1)
MeshVertexPosition(5,-5,0)
MeshVertexTextureCoordinate(1,0)
MeshFace(0,1,2)
MeshFace(0,2,3)
FinishMesh(#True)
NormalizeMesh(0)
UpdateMeshBoundingBox(0)
SetMeshMaterial(0, MaterialID(0), 0)
SetMeshMaterial(0, MaterialID(Mat), 1)
SetMeshMaterial(0, MaterialID(Mat), 2)
;-Entity
CreateEntity(0, MeshID(0), #PB_Material_None)
ScaleEntity(0, 2, 2, 2)
;WorldShadows(#PB_Shadow_TextureAdditive, 0, RGB(127, 127, 127), 4096)
WorldShadows(#PB_Shadow_TextureModulative, 0, RGB(127, 127, 127), 4096)
EntityRenderMode(BoxEntity, #PB_Entity_CastShadow )
Repeat
Repeat
ev = WindowEvent()
Until ev=0
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
RotateEntity(0,0,0.5,0,#PB_Relative)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(0, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndIf
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Last edited by applePi on Wed Feb 21, 2018 5:24 am, edited 1 time in total.
Re: Need help with 3D technique.
Interesting example! Thanks for that!
I didn´t know that you can set different materials to submeshes. That way it´s still one entity, which is excellent.
But I think it still has the same problem with polygon sorting. Atleast for me on my machine. When the vertical side which has the transparent texture shows its outside to the camera, the Geebee-textured polygons doesn´t show through, but the horizontal does.
But if I change "SetMaterialAttribute(Mat, #PB_Material_DepthWrite ,1)" to "SetMaterialAttribute(Mat, #PB_Material_DepthWrite ,0)" then the cube looks correct, but then your nice(extremely nice actually! or is it a trick I´m missing?) textureshadow is gone.
I didn´t know that you can set different materials to submeshes. That way it´s still one entity, which is excellent.
But I think it still has the same problem with polygon sorting. Atleast for me on my machine. When the vertical side which has the transparent texture shows its outside to the camera, the Geebee-textured polygons doesn´t show through, but the horizontal does.
But if I change "SetMaterialAttribute(Mat, #PB_Material_DepthWrite ,1)" to "SetMaterialAttribute(Mat, #PB_Material_DepthWrite ,0)" then the cube looks correct, but then your nice(extremely nice actually! or is it a trick I´m missing?) textureshadow is gone.
Re: Need help with 3D technique.
my case is different, i only can't see the ground through the horizontal face.
but change the shadow from #PB_Shadow_TextureAdditive to #PB_Shadow_TextureModulative then i can see again the ground
i have replaced the white ground with another textured one. the code is edited.
there is still many things to experiment with in PB v5.62.
there are #PB_Material_DepthCheck ,#PB_Material_DepthWrite ,#PB_Material_AlphaReject, #PB_Material_TAM , #PB_Material_EnvironmentMap.
i have found a new example called Material2.pb in the 5.62 examples which show some of these parameters.
in the Material2.pb example there is :
SetMaterialAttribute(0,#PB_Material_AlphaReject,-160,0)
note -160. if change it to 160 look the sphere will be different.
i will try to make a texture with several spots of transparency with a graphics editor, then wrapping this texture to a cube or other model and using #PB_Material_AlphaReject and its related parameters. to see if it works.
but change the shadow from #PB_Shadow_TextureAdditive to #PB_Shadow_TextureModulative then i can see again the ground
i have replaced the white ground with another textured one. the code is edited.
there is still many things to experiment with in PB v5.62.
there are #PB_Material_DepthCheck ,#PB_Material_DepthWrite ,#PB_Material_AlphaReject, #PB_Material_TAM , #PB_Material_EnvironmentMap.
i have found a new example called Material2.pb in the 5.62 examples which show some of these parameters.
in the Material2.pb example there is :
SetMaterialAttribute(0,#PB_Material_AlphaReject,-160,0)
note -160. if change it to 160 look the sphere will be different.
i will try to make a texture with several spots of transparency with a graphics editor, then wrapping this texture to a cube or other model and using #PB_Material_AlphaReject and its related parameters. to see if it works.