Jump to content

Cubemap generation - some questions


Rastar
 Share

Recommended Posts

After some time off I am picking up my PBR stuff for Leadwerks again. For the indirect specular lighitng I need special cubemaps that I would like to generate using the Leadwerks API. I would prefer to stay in Lua.

 

I am doing it currently like this

local cameraBuffer = Buffer:Create(self.resolution, self.resolution, 1, 0)
local cubemap = Texture:CubeMap(self.resolution, self.resolution, Texture.RGB)

cameraBuffer:Enable()
for i = 1,6 do
camera:SetRotation(self.cameraRotations[i])
cameraBuffer:SetColorTexture(cubemap, 0, i-1)
App.world:Render()
end
cameraBuffer:Disable()
Context:SetCurrent(App.context)

 

Now

  • Running this code gives me a "Asset map vaue is different" error, though the game continues normally. I don't know what this means?
  • What is the second parameter to Buffer:SetColorTexture()? The mipmap level?
  • I'm assuming that a cubemap is created by specifying the width and height of a single face (rather than width*6), is this correct?
  • As I see it, there currently is no way to save a texture to disk (or is there?). Would it be possible to add this to the (Lua) API?

Link to comment
Share on other sites

I would probably do it something like this (but it always renders black)

 

function Script:Start()

   --get workd,context etc..
   self.context=Context:GetCurrent()
   self.world=World:GetCurrent()
   self.resolution=1024

   --fetch a camara
   if self.camera==nil then
       for i=0,self.world:CountEntities()-1 do  --CountEntities is not a supported command
		    if self.world:GetEntity(i):GetClass()==Object.CameraClass then
			  self.camera=self.world:GetEntity(i)  --GetEntity is not a supported command
			  tolua.cast(self.camera,"Camera")
			  System:Print(self.world:GetEntity(i):GetClassName())
			  break
			 end
       end
   end

   --cube directions
   self.cameraRotations = {
       Vec3(0,0,0),
       Vec3(0,180,0),
       Vec3(-90,-90,0),
       Vec3(90,-90,0),
       Vec3(0,-90,0),
       Vec3(0,90,0)
   }

   --make cam buffer
   self.cameraBuffer = Buffer:Create(self.resolution, self.resolution, 1, 0)
   self.cameraBuffer:GetColorTexture():SetFilter(Texture.Pixel)

   --make cube buffer using cubemap texture
   self.cubebuffer =  Buffer:Create(self.resolution, self.resolution, 1, 0)
   self.cubemap = Texture:CubeMap(self.resolution, self.resolution)
   self.cubebuffer:SetColorTexture(self.cubemap)



   --ok warap the cubemap around something
   model=Model:Box(10,100,10)
   material=Material:Create()
   shader=Shader:Load("Shaders/Editor/SkyBox2.shader")


   material:SetShader(shader)
   model:SetMaterial(material)
end



function Script:UpdateWorld()
   -- render workd into a buffer and then copy buffer texture to a cubemap buffer
   for i = 1,6 do
       self.camera:SetRotation(self.cameraRotations[i])
       self.cameraBuffer:Enable()
       self.world:Render()
       self.cameraBuffer:Disable()
       self.cubebuffer:SetColorTexture(self.cameraBuffer:GetColorTexture(), 0, i-1) --write cambuffer to cubebuffer each face
   end
   Context:SetCurrent(self.context)

   material:SetTexture(self.cubebuffer:GetColorTexture())
   shader:Enable() -- enable skybox shader2
   self.cubebuffer:GetColorTexture():Bind(0) --assign cubemap texture from buffer into texture0
end

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...