HLSL will work with DirectX 9, 10, and 11. Some of the HLSL functions change depending on which version your targeting.
Unfortunately, PB's OGRE implementation is currently limited to DirectX 9. Which leaves us with shader models 1-3.
Here's a little info on HLSL shaders and their models.
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Hopefully down the line we will at least have access to DirectX 11 (DirectX 10 isn't worth the time in my opinion).
3D Anaglyph compositor
Re: 3D Anaglyph compositor
Cool, works like a charm.. lets go into the cathedral ...Samuel wrote:Here's the HLSL version with Kelebrindae's example code.
..
Let me know if something doesn't look right.

"Daddy, I'll run faster, then it is not so far..."
Re: 3D Anaglyph compositor
Its amazing!! Just merged the two projects together:
http://www.purebasic.fr/english/viewtop ... 36&t=57871
Download this:
http://www.2shared.com/file/U64lXeUl/sibenik.html
and this:
https://dl.dropboxusercontent.com/s/whd ... phHLSL.zip
Copy all files in the same directory. And use this code for cathedral.pb
http://www.purebasic.fr/english/viewtop ... 36&t=57871
Download this:
http://www.2shared.com/file/U64lXeUl/sibenik.html
and this:
https://dl.dropboxusercontent.com/s/whd ... phHLSL.zip
Copy all files in the same directory. And use this code for cathedral.pb
Code: Select all
; quick and dirty modified cathedral.pb from applePi and Samuel
#LEFTCAM = 0
#RIGHTCAM = 1
#EYES_DISTANCE = 0.05
#SCREENWIDTH = 1280
#SCREENHEIGHT = 1024
Define.f MouseX,MouseY,KeyX,KeyY
;#CameraSpeed = 0.05
#CameraSpeed = 0.2
Enumeration
#MESH
#TEX
#TEX_plane
#MAT
#MAT_plane
#plane
#cathedral
#camera
#mainwin
EndEnumeration
Global Quit.b = #False
Speed = 0.5
;- Initialisation
If InitEngine3D(#PB_Engine3D_DebugLog) = 0
MessageRequester( "Error" , "Can't initialize 3D, check if engine3D.dll is available" , 0 )
End
ElseIf InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse()=0
MessageRequester( "Error" , "Can't initialize Screen, mouse or keyboard" , 0 )
End
EndIf
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "use the mouse and arrow keys to move ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, #PB_Screen_SmartSynchronization)
;Initialize environment
;- Ressources
Add3DArchive("compositors\", #PB_3DArchive_FileSystem )
Add3DArchive("shaders\", #PB_3DArchive_FileSystem )
Add3DArchive("textures\", #PB_3DArchive_FileSystem )
Add3DArchive("meshes\", #PB_3DArchive_FileSystem )
Add3DArchive("materials\", #PB_3DArchive_FileSystem )
;- Cathedral
Add3DArchive("Data\", #PB_3DArchive_FileSystem)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Parse3DScripts()
CreateMaterial(#MAT_plane, LoadTexture(#TEX_plane, "basalt.jpg"))
;CreatePlane(#Mesh, TileSizeX, TileSizeZ, TileCountX, TileCountZ, TextureRepeatCountX, TextureRepeatCountZ)
CreatePlane(#plane, 100, 100, 1, 1, 10, 10)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))
LoadMesh(#MESH, "sibenik.mesh")
CreateEntity(#cathedral, MeshID(#MESH), #PB_Material_None )
ScaleEntity(#cathedral,0.5,0.5,0.5)
EntityRenderMode(#cathedral, #PB_Entity_CastShadow)
MoveEntity(#cathedral,0,8,6)
CreateLight(0,RGB(255,255,255),-100,40,30)
CreateLight(1,RGB(255,255,255),0,10,6)
CreateLight(2,RGB(255,255,255),-150,40,30)
CreateLight(3,RGB(255,255,255),150,40,30)
CreateLight(4,RGB(200,190,200),0,3,-10)
;- Lights
AmbientColor($555555)
CreateLight(0, $FFFFFF, 20,50,50)
LightAttenuation(0, 750, 0)
WorldShadows(#PB_Shadow_Additive)
;- Cameras
CreateCamera(#LEFTCAM, 0,0,100,100)
CameraBackColor(#LEFTCAM,0)
MoveCamera(#LEFTCAM, #EYES_DISTANCE, 0, 0,#PB_Absolute)
CreateCamera(#RIGHTCAM, 0,0,100,100)
CameraBackColor(#RIGHTCAM,0)
MoveCamera(#RIGHTCAM, -#EYES_DISTANCE, 0, 0,#PB_Absolute)
; Both cameras (the eyes) are attached to a node (the head)
camNode = CreateNode(#PB_Any,0,0,0)
AttachNodeObject(camNode,CameraID(#LEFTCAM))
AttachNodeObject(camNode,CameraID(#RIGHTCAM))
MoveNode(camNode,0,2,5)
CameraLookAt(#LEFTCAM, 0 , 2, 0)
CameraLookAt(#RIGHTCAM, 0 , 2, 0)
; The view from the "right-eye" camera is rendered to a texture.
; The last param (Ogre name) is used so the render texture can be used in the material script.
rightEyeTex = CreateRenderTexture(#PB_Any,CameraID(#RIGHTCAM),#SCREENWIDTH,#SCREENHEIGHT,#PB_Texture_AutomaticUpdate,"rightEye")
;- Compositor
; This full-screen compositor renders the scene from the "left-eye" camera to a texture,
; then calls a material which passes the "left-eye" and "right-eye" textures to a shader.
; The shader merges the red from one cam and green & blue from the other to get the final result.
CreateCompositorEffect(0, CameraID(0), "stereoscopy")
rot.l=1
;Main loop
;- Main loop
Repeat
While WindowEvent(): Wend
ExamineKeyboard()
; Cameras movement
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed
MouseY = -MouseDeltaY() * #CameraSpeed
EndIf
RotateNode(camNode, MouseY, MouseX, 0, #PB_Relative)
; Cube movements
RotateEntity(cube,0.5,0.2,0.3, #PB_Relative)
moveTimer1 + 0.005
moveTimer2 + 0.007
MoveEntity(cube,3 * Cos(moveTimer1),2,-3 + 5 * Sin(moveTimer2),#PB_Absolute)
; Render scene
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
"Daddy, I'll run faster, then it is not so far..."
- Bananenfreak
- Enthusiast
- Posts: 519
- Joined: Mon Apr 15, 2013 12:22 pm
Re: 3D Anaglyph compositor
This 2shared-thing. Where is this "second" downloadbutton? I only see one -.-
EDIT: With Adblockplus I only have the small downloadbutton. Thank you ABP
EDIT: With Adblockplus I only have the small downloadbutton. Thank you ABP

Last edited by Bananenfreak on Fri Jul 18, 2014 3:09 pm, edited 1 time in total.
Re: 3D Anaglyph compositor
thanks dige, it is a great scene to see a big building in "cinematic 3D view", i haven't expected this possibility at all.
for the testers just change a tiny changes to get the example works as you want.
thanks again Kelebrindae, Samuel, dige
for the testers just change a tiny changes to get the example works as you want.
thanks again Kelebrindae, Samuel, dige
- Bananenfreak
- Enthusiast
- Posts: 519
- Joined: Mon Apr 15, 2013 12:22 pm
Re: 3D Anaglyph compositor
@Kelebrindae:
Why there is everything in graytones? In Minecraft there it is not so gray...
Hmm, you convert both Pictures to grayscale, but why?
EDIT:
I found an plugin with data for anaglyph! We can´t use plugins, but perhaps those cg, material,...-files only code is left
http://www.ogre3d.org/forums/viewtopic. ... 55117092a2
Why there is everything in graytones? In Minecraft there it is not so gray...
Hmm, you convert both Pictures to grayscale, but why?
EDIT:
I found an plugin with data for anaglyph! We can´t use plugins, but perhaps those cg, material,...-files only code is left

http://www.ogre3d.org/forums/viewtopic. ... 55117092a2
Re: 3D Anaglyph compositor
I'm not sure why he has it in grey scale. I don't know much about this anaglyph stuff.Bananenfreak wrote:@Kelebrindae:
Why there is everything in graytones? In Minecraft there it is not so gray...
Hmm, you convert both Pictures to grayscale, but why?

What I do know is how to make the compositor return the textures original color values without affecting the anaglyph stuff.
Simply replace the stereoscopy.HLSL or CG file (depending on which example your using) with this.
Make sure to save it as stereoscopy.CG or stereoscopy.HLSL (depending).
Code: Select all
sampler2D leftEye : register(s0);
sampler2D rightEye : register(s1);
float4 stereoscopy_ps( float4 pos : POSITION,
float2 iTexCoord : TEXCOORD0) : COLOR
{
float3 color1 = tex2D(rightEye, iTexCoord).rgb;
float3 color2 = tex2D(leftEye, iTexCoord).rgb;
// Returns the red from the right-eye + green & blue from the left-eye
return float4(color1.r,color2.g,color2.b, 1.0);
}
- Bananenfreak
- Enthusiast
- Posts: 519
- Joined: Mon Apr 15, 2013 12:22 pm
-
- Enthusiast
- Posts: 151
- Joined: Tue Apr 01, 2008 3:23 pm
Re: 3D Anaglyph compositor
Hi guys,
First, thanks a lot for your work and your comments!
Second: Why did I convert all to greyscale?
=> Because the red or cyan areas of the image will interfere with the analygh technic and mess with the 3D effect.
There's solutions, of course: before rendering the image, the red and cyan areas of the original image must be altered to look respectively more purple and more blue.
Please see this excellent illustration made by Dobro (the anaglyph specialist on the french forums): The first image is the original one, the second is altered to make the anaglyph effect work better:
http://www.purebasic.fr/french/viewtopi ... he#p153973
First, thanks a lot for your work and your comments!

Second: Why did I convert all to greyscale?
=> Because the red or cyan areas of the image will interfere with the analygh technic and mess with the 3D effect.
There's solutions, of course: before rendering the image, the red and cyan areas of the original image must be altered to look respectively more purple and more blue.
Please see this excellent illustration made by Dobro (the anaglyph specialist on the french forums): The first image is the original one, the second is altered to make the anaglyph effect work better:
http://www.purebasic.fr/french/viewtopi ... he#p153973