Texture coordinates

Everything related to 3D programming
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Texture coordinates

Post by Polo »

How do you add multiple texture coordinates sets to a mesh, in order to use light maps for instance?
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Texture coordinates

Post by Comtois »

you can call MeshVertexTextureCoordinate(u, v) multiple times between AddMeshVertex(x, y, z) calls to add multiple texture coordinates to a vertex.

Never tested, you will tell us if it work :)
Please correct my english
http://purebasic.developpez.com/
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Texture coordinates

Post by Polo »

How do I then set a texture to use a specific set of texture coordinates then?
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Texture coordinates

Post by Comtois »

i think you will need a vertex shader

http://www.ogre3d.org/forums/viewtopic.php?f=4&t=23179
If the adjacent faces use the same material, but disagree on the texture coordinates (or normals, or anything else for that matter), then they have to use different vertices. In a shader you can use different UVs to access the same sampler but you'd have to have some way of knowing which to use, and that in itself would burn more space on the vertex and would also require per-vertex branch instructions. On balance, it's much better to duplicate vertices.
http://www.ogre3d.org/forums/viewtopic.php?f=5&t=69057
Please correct my english
http://purebasic.developpez.com/
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Texture coordinates

Post by Polo »

If the adjacent faces use the same material, but disagree on the texture coordinates (or normals, or anything else for that matter), then they have to use different vertices. In a shader you can use different UVs to access the same sampler but you'd have to have some way of knowing which to use, and that in itself would burn more space on the vertex and would also require per-vertex branch instructions. On balance, it's much better to duplicate vertices.
I just hope this advice doesn't come from an Ogre3d developer... It's such a basic task, cannot this be implemented in the engine without having to spend hours making a shader works? :?
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Texture coordinates

Post by Comtois »

this advice come from sinbad 'OGRE Founder' .

It was in 2006, you should do some research to see if there is anything new since.
Please correct my english
http://purebasic.developpez.com/
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Texture coordinates

Post by Polo »

Comtois wrote:this advice come from sinbad 'OGRE Founder' .
I hope he's changed his mind, that's the worst advice I've ever read!
No built in per pixel lightning and no built in lightmap support, I'm wondering how Ogre users manage to get lightning working.
DarkDragon
Addict
Addict
Posts: 2228
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Texture coordinates

Post by DarkDragon »

Comtois wrote:i think you will need a vertex shader
No, definately not. It says
In a shader you can use different UVs to access the same sampler [...]
but Polo wants different textures (samplers) with different texture coordinates. The AddMaterialLayer textures are different samplers. He should still try it the way you told him, as it should work then. The first layer gets the first texture coordinate specified. The second one the second ... .

Btw built in per fragment lighting should be already done: MaterialShadingMode(#Material, #PB_Material_Phong). Phong is a slightly modified Gouraud (with specular) based on fragments instead of vertices. <= sorry, mixed shading with illumination
Last edited by DarkDragon on Fri Sep 28, 2012 5:15 am, edited 1 time in total.
bye,
Daniel
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Texture coordinates

Post by PMV »

In a material-script, you can define which texture should
use which texture-coordinate-set. To define multiple
texture-coordinate-sets use a 3d-editor that can handle
that. I think blender can do that job, but i haven't tried
that. I had no need for different texture-coordinates and
i'm not a graphic-designer.

http://www.ogre3d.org/docs/manual/manual_16.html#shading wrote:phong

Vertex normals are interpolated across the face, and these are used to determine colour at each pixel. Gives a more natural lighting effect but is more expensive and works better at high levels of tessellation. Not supported on all hardware.
for more information about shadows in ogre3d i would recommend the manual:
http://www.ogre3d.org/docs/manual/manua ... ml#Shadows

MFG PMV
DarkDragon
Addict
Addict
Posts: 2228
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Texture coordinates

Post by DarkDragon »

PMV wrote:
http://www.ogre3d.org/docs/manual/manual_16.html#shading wrote:phong

Vertex normals are interpolated across the face, and these are used to determine colour at each pixel. Gives a more natural lighting effect but is more expensive and works better at high levels of tessellation. Not supported on all hardware.
for more information about shadows in ogre3d i would recommend the manual:
http://www.ogre3d.org/docs/manual/manua ... ml#Shadows
Oh yes, you're right. There was this difference between shading and illumination. But why are you then talking about shadows? They're part of global illumination not local illumination.

Nevertheless, writing one shader for per pixel lighting shouldn't hurt anyone, as shaders are more or less reusable.
bye,
Daniel
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Texture coordinates

Post by Comtois »

A quick test using MeshManual.pb example, added MeshVertexTextureCoordinate(u, v) for the base of pyramid.
And i use this materialScript

Code: Select all

material MeshManual
{
	technique
	{
		pass
		{
			texture_unit
			{
				texture Clouds.jpg
				tex_coord_set 0
			}
			texture_unit
			{
				texture Dirt.jpg
				tex_coord_set 1
			}
		}
	}
} 

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Manual Mesh
;
;    (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 1

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

Define.f x, y, z, nx, ny, nz, u, v
Define.l Co
Define.w t1, t2, t3

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    ; Create a pyramid, manually.. See the DataSection, for more precisions
    ;
    
    Restore Pyramid
    
    CreateMesh(0)
    
    ;Base
    AddSubMesh()
    For i = 0 To 3
      Read.f x : Read.f y : Read.f z
      Read.l Co
      Read.f u : Read.f v
      AddMeshVertex(x, y, z)
      MeshVertexNormal(0, 0, 0)
      MeshVertexColor(Co)
      MeshVertexTextureCoordinate(u, v)
      MeshVertexTextureCoordinate(u, v)
    Next
    
    For i = 0 To 1
      Read.w t1 : Read.w t2 : Read.w t3
      AddMeshFace(t1, t2, t3)
    Next
    
    ;Side
    For k=0 To 3
      
      AddSubMesh()
      For i = 0 To 2
        Read.f x : Read.f y : Read.f z
        Read.l Co
        Read.f u : Read.f v
        AddMeshVertex(x, y, z)
        MeshVertexNormal(0, 0, 0) 
        MeshVertexColor(Co)
        MeshVertexTextureCoordinate(u, v)
      Next i
      Read.w t1 : Read.w t2 : Read.w t3
      AddMeshFace(t1, t2, t3)
      
    Next
    
    FinishMesh()
    NormalizeMesh(0) 
    
    UpdateMeshBoundingBox(0)
    
    GetScriptMaterial(0, "MeshManual")
 
    CreateEntity(0, MeshID(0), MaterialID(0))
    ScaleEntity(0, 400, 200, 400)
    
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0, 0, 0, 1000)
    
    CreateLight(0, RGB(255,255,255), 300, 600, -100)
    AmbientColor(RGB(80, 80, 80))
    
    Repeat
      Screen3DEvents()
      
      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, 1, 0, 0, #PB_Relative)
      
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      RenderWorld()
      Screen3DStats()      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

DataSection
  Pyramid:
  ;Base
  Data.f -0.5,-0.5,0.5  ; position
  Data.l $FF            ; color
  Data.f 0,0            ; UVCoordinate
  
  Data.f 0.5,-0.5,0.5   ; position
  Data.l $FF            ; color 
  Data.f 0,1            ; UVCoordinate
  
  Data.f 0.5,-0.5,-0.5  ; position
  Data.l $FF            ; color
  Data.f 1,1            ; UVCoordinate
  
  Data.f -0.5,-0.5,-0.5 ; position
  Data.l $FF            ; color
  Data.f 1,0            ; UVCoordinate
  
  Data.w 2,1,0          ; Face 
  Data.w 0,3,2          ; Face 
  
  ;-Front
  Data.f 0.5,-0.5,0.5   ; position
  Data.l $FFFFFF        ; color
  Data.f 1,0            ; UVCoordinate
  
  Data.f 0.0,0.5,0.0
  Data.l $FFFFFF
  Data.f 0.5,0.5
  
  Data.f -0.5,-0.5,0.5
  Data.l $FFFFFF
  Data.f 0,0
 
  Data.w 0,1,2         ; Face
  
  ;-Back
  Data.f -0.5,-0.5,-0.5
  Data.l $FFFFFF
  Data.f 0,1
  
  Data.f 0.0,0.5,0.0
  Data.l $FFFFFF
  Data.f 0.5,0.5
  
  Data.f 0.5,-0.5,-0.5
  Data.l $FFFFFF
  Data.f 1,1
  
  Data.w 0,1,2
  
  ;-Left
  Data.f -0.5,-0.5,0.5
  Data.l $FFFFFF
  Data.f 0,0
  
  Data.f 0.0,0.5,0.0
  Data.l $FFFFFF
  Data.f 0.5,0.5
  
  Data.f -0.5,-0.5,-0.5
  Data.l $FFFFFF
  Data.f 0,1
  
  Data.w 0,1,2
  
  ;-Right
  Data.f 0.5,-0.5,-0.5
  Data.l $FFFFFF
  Data.f 1,1
  
  Data.f 0.0,0.5,0.0
  Data.l $FFFFFF
  Data.f 0.5,0.5
  
  Data.f 0.5,-0.5,0.5
  Data.l $FFFFFF
  Data.f 1,0
  
  Data.w 0,1,2
  
EndDataSection
Please correct my english
http://purebasic.developpez.com/
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Texture coordinates

Post by Polo »

Thanks for your answers - any chance this could be possible using a command instead of a material file?
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Texture coordinates

Post by Fred »

To do advanced stuffs, scripts are probably mandatory as we can't map all the script features with PB commands, it would be too much. Using scripts allows to leverage most of OGRE without hassle.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: Texture coordinates

Post by Polo »

Fred wrote:To do advanced stuffs, scripts are probably mandatory as we can't map all the script features with PB commands, it would be too much. Using scripts allows to leverage most of OGRE without hassle.
True, though using multiple texture coordinates is not that advanced stuff ;)
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Texture coordinates

Post by J. Baker »

Polo wrote:
Fred wrote:To do advanced stuffs, scripts are probably mandatory as we can't map all the script features with PB commands, it would be too much. Using scripts allows to leverage most of OGRE without hassle.
True, though using multiple texture coordinates is not that advanced stuff ;)
You add multiple textures to a single mesh in your 3D editor, such as Wings3D or whatever you may use. I did this a few years ago with PB. So PB/OGRE does support this, even years ago. You just need to learn how to create multiple textures in your 3D app. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
Post Reply