Rastar Posted June 12, 2015 Share Posted June 12, 2015 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? Quote Link to comment Share on other sites More sharing options...
Rastar Posted June 16, 2015 Author Share Posted June 16, 2015 Bump. Anybody? I've put a screenshot of my WIP in the gallery http://www.leadwerks.com/werkspace/page/viewitem?fileid=462724265 but without indirect specular lighting from (special) cubemaps this won't be the real deal ;-) Quote Link to comment Share on other sites More sharing options...
shadmar Posted June 17, 2015 Share Posted June 17, 2015 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 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rastar Posted June 18, 2015 Author Share Posted June 18, 2015 Hi shadmar, thanks for the suggestion - will try over the weekend! Quote Link to comment Share on other sites More sharing options...
shadmar Posted June 18, 2015 Share Posted June 18, 2015 If you just want to make an in-scene static cubemap you can do it like this : http://www.leadwerks.com/werkspace/topic/11224-skybox-rendering/#entry82736 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Recommended Posts
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.