habe ich hier ein neues Tutorial über Irrlicht-Parallax-Mapping zusammengebastelt.
Es ist zugleich eine (kurze) Grafikdemonstration der Irrlicht 3D-Engine
Eine lauffähige Exe und DLLS sind dabei, falls jemand die Irrlicht Engine nicht hat/installieren will.
WICHTIG: wer den irrlicht-Wrapper 1.05 hat, der muss die aktuelle DLL im Ordner mit einer eigenen ersetzen.
Die ist integrierte ist nämlich schon für irrlicht 1.4.2, und würden einen Absturz verursachen.
In diesem Fall einfach die eigene Irrlicht.dll in den Ordner kopieren.
Mit LEER wird das Material Gewechselt.
DOWNLOAD
Hier Screenshots: (so sieht das Endergebnis aus)


DOWNLOAD
-mfg Max.
Sourcecode (wenngleich er ohne die Dateien wohl nicht läuft, Aber zur Rekonstruktion) :
[Es ist alles auf Englisch, um eventuell in den Irrlicht-Wrapper aufgenommen zu werden, evtl. in abgeänderter Version. Ich hoffe, es bleibt trotzdem verständlich
Code: Alles auswählen
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
; --- Irrlicht Parallax Example
; ------------------------------------------------------------------------------
; --- Demo: Yes
; --- Date: 29.12.2008
; --- (c) by Aigner, Max - Gemusoft - (Alias Draufgeher, max_der_held)
; --- Runs on JaPBe
; --- Most Textures and Files are owned by Gemusoft. All rights reserved. ;)
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
; -- Important Note:
; ------------------------------------------------------------------------------
; sometimes parallaxmapping only works on openGL. so use this when the screen is only black.
; ------------------------------------------------------------------------------
; -- So let's start:
; ------------------------------------------------------------------------------
; In this Tutorial you will learn how to handly parallaxmapping
; and Normalmapping in Purebasic-Irrlicht.
; If you want to learn by doing, you needn't to read all comments. Just try out and rewrite everything ;)
; first of all we include the irrlicht-wrapper from your home directory. (I load it from there, because I extended the requester.)
; If you use the standard PB-IDE it might say "OOP-ERROR" "Could not find or parse file..."
; then use (uncomment) this:
; If it is not running anyway, download the JaPBe V. 3 and try again ;)
; XIncludeFile "Irr3DRequester.pb"
XIncludeFile #PB_Compiler_Home + "examples\irrlichtwrapper\Irr3DRequester.pb"
Global cam.l ; memory-address of our cam.
Global *camlicht.l ; the same of the light. (it's not really necessary to declare it as a pointer)
Global *cube.l
Global TextGadget.l
Global material.l = #IRR_EMT_PARALLAX_MAP_SOLID ; our cube will be parallaxmapped. we need this variable later.
Global background_static.l
Global background_mesh.l
Global background_node.l
If Irr3DRequester() ; checks, if the engine is started.
; set the Title of our 3D-Window
IrrSetWindowCaption ( "Gemusoft Graphicsexample" )
; set current directory not to write too much:
IrrChangeWorkingDirectory( "media\")
; let's create a Camera
cam = IrrAddFPSCamera (0,120,40)
IrrSetNodePosition ( cam , 0 , 7 , -20 )
IrrSetCameraTarget ( cam , -10,0,0) ; set the camera lookat.
IrrSetCameraNearValue ( cam , 0.05)
IrrSetCameraClipDistance( cam , 2000)
; we load a whole world, to make it more vivit ;)
IrrLoadScene( "example.irr")
; create the Camera-Light
*camlicht = IrrAddLight ( 0 , 0 , 0 , 0.8,0.7,0.7,3) ; light following the camera.
IrrAddChildToParent ( *camlicht , cam ) ; it should follow the cam, so let's attach it to the cam.
; Note: only two lights are supported in parallax and normalmapping.
; create a parallax-cube
*cube.l = IrrAddCubeSceneNode(7)
IrrSetNodePosition ( *cube , -10 , -1 , 0)
; the first texture is the Color-map. it's any texture like for example metal.
IrrSetNodeMaterialTexture( *cube , IrrGetTexture( "default_texture.png") , 0 )
; the second texture is the Parallax-map.
; it is a normalmap ( red green blue-mixture) with a height-map (black-white-grey) in the alphachannel.
; so every pixle has a alphavalue from 0 to 255. 0 means black, 255 means white...
; Ask Wikipedia for "heightmap" and "normalmap" for further information. (or the purebasic-forum ;) )
IrrSetNodeMaterialTexture( *cube , IrrGetTexture( "default_texture_normal.png") , 1 )
; Now set the materialtype.
; a complete list of all types and its funktions is at the end. (from the "irrlicht_enums.pbi" ->irrlichtwrapper 1.4.2 )
IrrSetNodeMaterialType ( *cube , #IRR_EMT_PARALLAX_MAP_SOLID )
; hide mouse
IrrHideMouse()
; add GUI- Text
TextGadget = IrrGuiAddStaticText(" Material: ParallaxMapping" , 10,10,10+200,10+12,1,1,1) ; i wrote 10+200 to advise you, not to forget, it's not with but the End-Position
; now we du the same, to load a background mesh
background_mesh = IrrGetMesh("room.3ds")
; because the producer did a mess on texturin it irrlicht has to re-texture it:
background_static = IrrGetStaticFromMesh ( background_mesh )
IrrMakePlanarTextureMapping ( background_static , 0.005)
; now add the mesh to scene ( not the static!)
background_node = IrrAddMeshToScene ( background_mesh)
IrrSetNodeMaterialType ( background_node , #IRR_EMT_PARALLAX_MAP_SOLID)
IrrSetNodeMaterialTexture ( background_node , IrrGetTexture( "rockwall.bmp") , 0 )
IrrSetNodeMaterialTexture ( background_node , IrrGetTexture( "rockwall_parallaxmap.png") , 1 )
IrrSetNodePosition ( background_node , 3.048694, -16.834227, -3.333332 ) ; values from the IrrEdit ;)
IrrSetNodeScale ( background_node , 0.2,0.2,0.2)
IrrSetNodeMaterialFlag ( background_node , #IRR_EMF_LIGHTING , 0) ; disable lighting otherwise it would like strange..
; while irrlicht is still running
While IrrRunning()
IrrBeginScene ( 0, 0, 0 ) ; start rendering - the first three parameters are the Color irrbeginscene( R.b , G.b , B.b)
; draw the scene
IrrDrawScene () ; render the scene
IrrDrawGUI () ; render the GUI (After the scene, otherwise you would see nothing at all
IrrEndScene ()
; end with Escape
If GetAsyncKeyState_( #VK_ESCAPE)
IrrStop() ; before ending Purebasic: end irrlicht.
End ; quit.
EndIf
; change materialtype.
If GetAsyncKeyState_(#VK_SPACE) ; Windows-Api, if Space pressed
If spacereleased = 0 ; and if it is only tipped
spacereleased = 1
If material = #IRR_EMT_NORMAL_MAP_SOLID ; if the material is solid
IrrGuiSetText ( TextGadget , " Material: ParallaxMapping.") ; Update the Text-gadget we defined above
material = #IRR_EMT_PARALLAX_MAP_SOLID
IrrSetNodeMaterialType ( *cube , material) ; set the material to #irr_emt_parallax_map_solid"
IrrSetNodeMaterialType ( background_node , material)
ElseIf material = #IRR_EMT_PARALLAX_MAP_SOLID ; elseif material is parallax-map already
IrrGuiSetText ( TextGadget , " Material: Solid.")
material = #IRR_EMT_SOLID
IrrSetNodeMaterialType ( *cube , material) ; make it solid
IrrSetNodeMaterialType ( background_node , material)
ElseIf material = #IRR_EMT_SOLID ; and if it is solid
IrrGuiSetText ( TextGadget , " Material: NormalMapping.")
material = #IRR_EMT_NORMAL_MAP_SOLID ; Switch on Normal-Mapping. ;)
IrrSetNodeMaterialType ( *cube , material)
IrrSetNodeMaterialType ( background_node , material)
EndIf
EndIf
Else
spacereleased = 0 ; if we release the spacekey, we unlock the variable. now we could switch the material again
; by pressing space ;)
EndIf
Wend
EndIf
;{ Irrlicht Material Types.
; ; Standard solid material. Only first texture is used, which is
; ; supposed to be the diffuse material.
;- #IRR_EMT_SOLID = 0
; ; Solid material with 2 texture layers. The second is blended onto the
; ; first using the alpha value of the vertex colors.
; ; This material is currently not implemented in OpenGL, but it
; ; works with DirectX.
;- #IRR_EMT_SOLID_2_LAYER
; ; Material type with standard lightmap technique:
; ; There should be 2 textures: The first texture layer is a diffuse map,
; ; the second is a light map. Vertex light is ignored.
;- #IRR_EMT_LIGHTMAP
; ; Material type with lightmap technique like EMT_LIGHTMAP, but
; ; lightmap and diffuse texture are not modulated, but added instead.
;- #IRR_EMT_LIGHTMAP_ADD
; ; Material type with standard lightmap technique:
; ; There should be 2 textures: The first texture layer is a diffuse map,
; ; the second is a light map. Vertex light is ignored.
; ; The texture colors are effectively multiplyied by 2 for brightening.
; ; like known in DirectX as D3DTOP_MODULATE2X.
;- #IRR_EMT_LIGHTMAP_M2
; ; Material type with standard lightmap technique:
; ; There should be 2 textures: The first texture layer is a diffuse map,
; ; the second is a light map. Vertex light is ignored.
; ; The texture colors are effectively multiplyied by 4 for brightening.
; ; like known in DirectX as D3DTOP_MODULATE4X.
;- #IRR_EMT_LIGHTMAP_M4
; ; Like EMT_LIGHTMAP, but also supports dynamic lighting.
;- #IRR_EMT_LIGHTMAP_LIGHTING
; ; Like EMT_LIGHTMAP_M2, but also supports dynamic lighting.
;- #IRR_EMT_LIGHTMAP_LIGHTING_M2
; ; Like EMT_LIGHTMAP_4, but also supports dynamic lighting.
;- #IRR_EMT_LIGHTMAP_LIGHTING_M4
; ; Detail mapped material. The first texture is diffuse color map, the
; ; second is added to this and usually displayed with a bigger scale value
; ; so that it adds more detail. The detail map is added to the diffuse map using
; ; ADD_SIGNED, so that it is possible to add and substract color from the diffuse
; ; map. For example a value of (127,127,127) will not change the appearance of
; ; the diffuse map at all.
; ; Often used for terrain rendering.
;- #IRR_EMT_DETAIL_MAP
; ; Makes the material look like it was reflection the environment
; ; around it. To make this possible, a texture called 'sphere map'
; ; is used, which must be set as Textures[0].
;- #IRR_EMT_SPHERE_MAP
; ; A reflecting material with an
; ; optional additional non reflecting texture layer. The reflection
; ; map should be set as Texture 1.
;- #IRR_EMT_REFLECTION_2_LAYER
; ; A transparent material. Only the first texture is used.
; ; The new color is calculated by simply adding the source color and
; ; the dest color. This means if for example a billboard using a texture with
; ; black background and a red circle on it is drawn with this material, the
; ; result is that only the red circle will be drawn a little bit transparent,
; ; and everything which was black is 100% transparent and not visible.
; ; This material type is useful for e.g. particle effects.
;- #IRR_EMT_TRANSPARENT_ADD_COLOR
; ; Makes the material transparent based on the texture alpha channel.
; ; The final color is blended together from the destination color and the
; ; texture color, using the alpha channel value as blend factor.
; ; Only first texture is used. If you are using this material with small
; ; textures, it is a good idea to load the texture in 32 bit
; ; mode (video::IVideoDriver::setTextureCreationFlag()).
; ; Also, an alpha ref is used, which can be manipulated using SMaterial::MaterialTypeParam.
; ; If set to 0, the alpha ref gets its default value which is 0.5f and which means
; ; that pixels with an alpha value >127 will be written, others not. In other, simple
; ; words: this value controls how sharp the edges become when going from a
; ; transparent to a solid spot on the texture.
;- #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL
; ; Makes the material transparent based on the texture alpha channel.
; ; If the alpha channel value is greater than 127, a pixel is written to the
; ; target, otherwise not. This material does not use alpha blending
; ; and is a lot faster than EMT_TRANSPARENT_ALPHA_CHANNEL. It
; ; is ideal for drawing stuff like leafes of plants, because the borders
; ; are not blurry but sharp.
; ; Only first texture is used. If you are using this material with small
; ; textures and 3d object, it is a good idea to load the texture in 32 bit
; ; mode (video::IVideoDriver::setTextureCreationFlag()).
;- #IRR_EMT_TRANSPARENT_ALPHA_CHANNEL_REF
; ; Makes the material transparent based on the vertex alpha value.
;- #IRR_EMT_TRANSPARENT_VERTEX_ALPHA
; ; A transparent reflecting material with an
; ; optional additional non reflecting texture layer. The reflection
; ; map should be set as Texture 1. The transparency depends on the
; ; alpha value in the vertex colors. A texture which will not reflect
; ; can be set als Texture 2.
; ; Please note that this material type is currently not 100% implemented
; ; in OpenGL. It works in Direct3D.
;- #IRR_EMT_TRANSPARENT_REFLECTION_2_LAYER
; ; A solid normal map renderer. First texture is the color map, the
; ; second should be the normal map. Note that you should use this material
; ; only when drawing geometry consisting of vertices of type S3DVertexTangents
; ; (EVT_TANGENTS). You can convert any mesh into this format using
; ; IMeshManipulator::createMeshWithTangents() (See SpecialFX2 Tutorial).
; ; This shader runs on vertex shader 1.1 and pixel shader 1.1 capable hardware and
; ; falls back on a fixed function lighted material if this hardware is not available.
; ; Only two lights are supported by this shader, if there are more, the nearest two
; ; are chosen. Currently, this shader is only implemented for the D3D8 and D3D9 renderers.
;- #IRR_EMT_NORMAL_MAP_SOLID
; ; A transparent normal map renderer. First texture is the color map, the
; ; second should be the normal map. Note that you should use this material
; ; only when drawing geometry consisting of vertices of type S3DVertexTangents
; ; (EVT_TANGENTS). You can convert any mesh into this format using
; ; IMeshManipulator::createMeshWithTangents() (See SpecialFX2 Tutorial).
; ; This shader runs on vertex shader 1.1 and pixel shader 1.1 capable hardware and
; ; falls back on a fixed function lighted material if this hardware is not available.
; ; Only two lights are supported by this shader, if there are more, the nearest two
; ; are chosen. Currently, this shader is only implemented for the D3D8 and D3D9 renderers.
;- #IRR_EMT_NORMAL_MAP_TRANSPARENT_ADD_COLOR
; ; A transparent (based on the vertex alpha value) normal map renderer.
; ; First texture is the color map, the
; ; second should be the normal map. Note that you should use this material
; ; only when drawing geometry consisting of vertices of type S3DVertexTangents
; ; (EVT_TANGENTS). You can convert any mesh into this format using
; ; IMeshManipulator::createMeshWithTangents() (See SpecialFX2 Tutorial).
; ; This shader runs on vertex shader 1.1 and pixel shader 1.1 capable hardware and
; ; falls back on a fixed function lighted material if this hardware is not available.
; ; Only two lights are supported by this shader, if there are more, the nearest two
; ; are chosen. Currently, this shader is only implemented for the D3D8 and D3D9 renderers.
;- #IRR_EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA
; ; Just like EMT_NORMAL_MAP_SOLID, but uses parallax mapping too, which
; ; looks a lot more realistic. This only works when the hardware supports at
; ; least vertex shader 1.1 and pixel shader 1.4.
; ; First texture is the color map, the second should be the normal map.
; ; The normal map texture should contain the height value in the
; ; alpha component. The IVideoDriver::makeNormalMapTexture() method writes
; ; this value automaticly when creating normal maps from a heightmap when using a 32 bit
; ; texture.
; ; The height scale of the material (affecting the bumpiness) is being controlled
; ; by the SMaterial::MaterialTypeParam member.
; ; If set to zero, the default value (0.02f) will be applied. Otherwise
; ; the value set in SMaterial::MaterialTypeParam is taken. This value depends on with which
; ; scale the texture is mapped on the material. Too high or low values of MaterialTypeParam
; ; can result in strange artifacts.
;- #IRR_EMT_PARALLAX_MAP_SOLID
; ; A material just like EMT_PARALLAX_MAP_SOLID, but it is transparent, using
; ; EMT_TRANSPARENT_ADD_COLOR as base material.
;- #IRR_EMT_PARALLAX_MAP_TRANSPARENT_ADD_COLOR
; ; A material just like EMT_PARALLAX_MAP_SOLID, but it is transparent, using
; ; EMT_TRANSPARENT_VERTEX_ALPHA as base material.
;- #IRR_EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA
; ; BlendFunc = source * sourceFactor + dest * destFactor ( E_BLEND_FUNC )
; ; Using only Textures[0]. generic Blender
;- #IRR_EMT_ONETEXTURE_BLEND
; ; This value is not used. It only forces this enumeration to compile in 32 bit.
;- #IRR_EMT_FORCE_32BIT = $7FFFFFFF
;}