• Real Time Reflections
    5 replies, posted
Hello folks. Recently I've become interested in doing real time reflections, and was wondering what were the common approaches to this. The goal is to create a square panel which acts identically to a mirror, or even better, a more complex shape. I've been doing quite some reading on [URL="https://developer.valvesoftware.com/wiki/Shader"]shaders[/URL] and specifically on the [URL="https://developer.valvesoftware.com/wiki/LightmappedReflective"]LightmappedReflective[/URL] shader on the Valve wiki, and how it's utilized in the [URL="https://developer.valvesoftware.com/wiki/Func_reflective_glass"]func_reflective_glass[/URL] brush entity. I was hoping some of you could either guide me or give me some of your insight. Assuming I can code in lua: What exactly is a brush entity? Can I spawn one with my own settings in game with the right code? Can I create a brush entity identical to func_reflective_glass completely in-game, or does it have to be built into the map? If so, how do I do that and what can I control about it? Can I apply shaders other than the VertexLitGeneric shader to entities? [B]Why or why not[/B], and if so, how? Expensive water has real time reflections. Is there a way to utilize this to my advantage somehow? I've already created a material creator tool in-game. It gives you the entire range of settings one would put into a VMT file and once you click on a prop, the material is created and applied. It currently seems to only work on the VertexLitGeneric shader and does not correctly update on any other shader, even when I try to apply it on [B]existing[/B] func_reflective_glass entities. If anyone has an idea why, I'd love to know. Finally, would there be a way of creating real time reflections purely in Lua? Thanks in advance!
1) Brush entity is a visible entity that uses a brush as its model, as opposed to a .mdl model. 2) If it can be "created by the map", it can be created with Lua. 3) You don't apply shaders to entities, Shaders are applier to each material. 4) I don't follow
[QUOTE=Robotboy655;50732256] [B]3) You don't apply shaders to entities, Shaders are applier to each material.[/B][/QUOTE] This is excellent news. Is there anything else I need to be looking at other than [URL="http://wiki.garrysmod.com/page/Global/CreateMaterial"]CreateMaterial [/URL]when applying shaders such as the LightmappedReflective to a newly created material?
Yep, CreateMaterial, but also [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetMaterial]Entity:SetMaterial[/url] (you probably already knew that though). Just make sure forceMaterial is true for applying different shaders
[QUOTE=MPan1;50734476]Yep, CreateMaterial, but also [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/Entity/SetMaterial"]Entity:SetMaterial[/URL] (you probably already knew that though). Just make sure forceMaterial is true for applying different shaders[/QUOTE] Is Entity:SetSubMaterial an equal substitute? e: It works for example with the Wireframe shader, or the UnlitGeneric shader, but does not for the LightMappedGeneric shader for example. I worry they can't be loaded onto models or something. At the end of the day, my code looks like this: [CODE]local function CreateAndSetMaterials(ent, MCData) -- MCData is a big table containing 'Submaterials', where every 'submaterial' is a table of its own containing a material's keyvalues which need to be set per material if !IsValid(ent) then return false end if ent:GetMaterials() then for sky, snm in pairs (ent:GetMaterials()) do -- Deletes all the submaterials to start from scratch ent:SetSubMaterial(tonumber(sky) - 1, nil) end end if MCData then for smkey, keyvalues in pairs (MCData.SubMaterials) do for a, b in pairs (keyvalues) do -- Avoids flags related errors, we also probably dont need them if a == "$flags" or a == "$flags2" or a == "$flags_defined" or a == "$flags_defined2" then keyvalues[a] = nil end end local NewShaderString = MCData.SubMaterials[smkey].ShaderString or "VertexLitGeneric" -- this is where I put in my new shader name (ShaderString is client info) local NewSubMaterialName = "MCSM_"..ent:EntIndex()..smkey..os.time() -- So we dont get overlaps in names local NewSubMaterial = CreateMaterial(NewSubMaterialName, NewShaderString, keyvalues) -- Actually create the material --Reset some values on our new material... we gotta do that otherwise we get some errors, basically repeat myself for k, v in pairs(keyvalues) do local typ = OrganizedMCSettings[k] if typ == "Vector" then NewSubMaterial:SetVector(k, keyvalues[k]) elseif typ == "number" then NewSubMaterial:SetFloat(k, keyvalues[k]) elseif typ == "VMatrix" then NewSubMaterial:SetMatrix(k, keyvalues[k]) elseif typ == "ITexture" then NewSubMaterial:SetTexture(k, keyvalues[k]) elseif typ == "string" then NewSubMaterial:SetString(k, keyvalues[k]) end end ent:SetSubMaterial(tonumber(smkey) - 1, "!"..NewSubMaterialName) -- Hopefully equal to ent:SetMaterial() NewSubMaterial:Recompute() -- Double tap it end end end[/CODE] [editline]18th July 2016[/editline] And it works for VertexLitGeneric shaders, Wireframe shaders, the UnlitGeneric shader, but does nothing on pretty much all other shaders, what should I do differently, in your opinion?
LightMappedGeneric is a brush only shader. VertexLitGeneric is model only shader. UnlitGeneric is GUI shader.
Sorry, you need to Log In to post a reply to this thread.