-- script.lua x = "" pos = nil pos1 = nil defpos = nil lastdefpos = nil dclpos = nil lastdclpos = nil c7pos = nil lastc7pos = nil rpos = nil xpos = nil sr = "" sx = "" sw = "" sm = "" isDone = false doSearch = true AddNextStr = true IsFirst = true GBuffer = nil ScreenToLS = nil SceneColorTexture = nil SamplerPos = nil SamplerName = "" MulEnd = nil rposEnd = nil; LightAttenuationTexture = nil MinZ_MaxZRatio = nil ShadowTexture = nil textcordpos = nil textcordreg = "" FixSceneColorTexture = true FixShadowsHalo = true UniformPixelVector = nil VPreg = "" VPPos = nil LstIdx = 0; LightMapTextures = nil UniformPixelScalars = nil ScreenPositionScaleBias = nil Texture2D_2 = nil ScreenToWorld = nil DepthFilterSampleOffsets = nil GBufferToView = nil -- search for constants names it helps to determinate shader for i = 1, #SText do if pos == nil then pos = string.find(SText[i], "bReceiveDynamicShadows") end if pos1 == nil then pos1 = string.find(SText[i], "ViewProjectionMatrix") LstIdx = i + 1 end if LightAttenuationTexture == nil then LightAttenuationTexture = string.find(SText[i], "LightAttenuationTexture") end if LightMapTextures == nil then LightMapTextures = string.find(SText[i], "LightMapTextures") if LightMapTextures ~= nil then LightMapTextures = i end end if UniformPixelScalars == nil then UniformPixelScalars = string.find(SText[i], "UniformPixelScalars") end if GBufferToView == nil then GBufferToView = string.find(SText[i], "GBufferToView") if GBufferToView ~= nil then GBufferToView = i + 1 end end if GBuffer == nil then GBuffer = string.find(SText[i], "GBuffer_NormalTexture") if GBuffer ~= nil then GBuffer = i end end if ScreenToWorld == nil then ScreenToWorld = string.find(SText[i], "ScreenToWorld") end if DepthFilterSampleOffsets == nil then DepthFilterSampleOffsets = string.find(SText[i], "DepthFilterSampleOffsets") end if ScreenPositionScaleBias == nil then ScreenPositionScaleBias = string.find(SText[i], "ScreenPositionScaleBias") end if Texture2D_2 == nil then Texture2D_2 = string.find(SText[i], "Texture2D_") end if SceneColorTexture == nil then SceneColorTexture = string.find(SText[i], "SceneColorTexture") if SceneColorTexture ~= nil then SceneColorTexture = i end end if ScreenToLS == nil then ScreenToLS = string.find(SText[i], "ScreenToLight") end if ScreenToLS == nil then ScreenToLS = string.find(SText[i], "ScreenToShadowMatrix") end if UniformPixelVector == nil then UniformPixelVector = string.find(SText[i], "UniformPixelVector") end --isDone = true --x = x .. SText[i] .. string.char(13) if string.find(SText[i], "ps_3_0") ~= nil then break end end if isDone == false then if (GBufferToView ~= nil) and (GBuffer ~= nil) then for i = GBufferToView, #SText do AddNextStr = true if SamplerPos == nil then SamplerPos = string.find(SText[i], "GBuffer_NormalTexture") end if sm ~= "" then rpos, rposEnd = string.find(SText[i], sm) if rpos ~= nil then rpos, MulEnd = string.find(SText[i - 1], "mul ") if rpos == nil then rpos, MulEnd = string.find(SText[i - 1], "mul_pp ", 1, true) end if rpos ~= nil then --rpos = rpos + 4 xpos = string.find(SText[i - 1], ".", MulEnd, true) sr = string.sub(SText[i - 1], MulEnd, xpos - 1) sx = string.sub(SText[i - 1], xpos + 1, xpos + 1) xpos, rposEnd = string.find(SText[i - 1], ",", xpos + 1, true) xpos = string.find(SText[i - 1], ",", rposEnd + 1, true) sw = string.sub(SText[i - 1], rposEnd + 1, xpos - 1) --x = x .. SText[i] .. string.char(10) x = x .. " texldl r11, c200.z, s13" .. string.char(10) x = x .. " add r11.y, " .. sw .. ", -r11.y" .. string.char(10) x = x .. " mul r11.x, r11.x, r11.y" .. string.char(10) x = x .. " add " .. sr .. "." .. sx .. ", " .. sr .. "." .. sx .. ", -r11.x" .. string.char(10) --doSearch = false isDone = true --AddNextStr = false end end end if c7pos == nil then c7pos = string.find(SText[i], "GBufferToView") end if c7pos ~= nil then if sm == "" then c7pos = string.find(SText[i], "c", c7pos + 13) sm = string.sub(SText[i], c7pos, c7pos + 2) units = string.byte(sm, 3) - 48 dozens = string.byte(sm, 2) - 48 if((units < 0) or (units > 9)) or ((dozens < 0) or (dozens > 9)) then sm = "" else dozens = dozens * 10 + units + 1 sm = string.format("c%u", dozens) end end end if SamplerPos ~= nil then if SamplerName == "" then SamplerPos = string.find(SText[i], "s", SamplerPos + 21) if SamplerPos ~= nil then SamplerName = string.sub(SText[i], SamplerPos, SamplerPos + 1) end end if SamplerName ~= "" then lastdefpos = string.find(SText[i], "def") if lastdefpos ~= nil then defpos = i + 1 end if (lastdefpos == nil) and (defpos ~= nil) then if i == defpos then x = x .. " def c200, 0.0, 0.5, 0.0625, 0 " .. string.char(10) end lastdclpos = string.find(SText[i], "dcl_2") if lastdclpos == nil then lastdclpos = string.find(SText[i], "dcl_cube") end if lastdclpos ~= nil then dclpos = i + 1 end if (lastdclpos == nil) and (dclpos ~= nil) then if i == dclpos then x = x .. " dcl_2d s13" .. string.char(10) end end end end end if AddNextStr then x = x .. SText[i] .. string.char(10) end end end end if isDone == false then --and (MinZ_MaxZRatio ~= nil) if (SceneColorTexture ~= nil) then StartIdx = SceneColorTexture else StartIdx = LightMapTextures end if (((SceneColorTexture ~= nil) or (LightMapTextures ~= nil)) and (UniformPixelVector ~= nil) and (ScreenToLS == nil) and (ShadowTexture == nil)) or ((SceneColorTexture ~= nil) and (UniformPixelScalars ~= nil) and (ScreenPositionScaleBias ~= nil) and (Texture2D_2 ~= nil) and (UniformPixelVector == nil)) or ((SceneColorTexture ~= nil) and (DepthFilterSampleOffsets ~= nil) and (ScreenPositionScaleBias ~= nil)) and FixSceneColorTexture then -- and (ScreenToWorld ~= nil) for i = StartIdx + 1, #SText do AddNextStr = true --if doSearch then if SamplerPos == nil then if (SceneColorTexture ~= nil) then SamplerPos = string.find(SText[i], "SceneColorTexture") else SamplerPos = string.find(SText[i], "LightMapTextures") end end if SamplerPos ~= nil then if SamplerName == "" then SamplerPos = string.find(SText[i], "s", SamplerPos + 16) SamplerName = string.sub(SText[i], SamplerPos, SamplerPos + 1) end if SamplerName ~= "" then lastdefpos = string.find(SText[i], "def") if lastdefpos ~= nil then defpos = i + 1 end if (lastdefpos == nil) and (defpos ~= nil) then if i == defpos then x = x .. " def c200, 0.0, 0.5, 0.0625, 0 " .. string.char(10) end lastdclpos = string.find(SText[i], "dcl_2") if lastdclpos == nil then lastdclpos = string.find(SText[i], "dcl_cube") end if lastdclpos ~= nil then dclpos = i + 1 end if (lastdclpos == nil) and (dclpos ~= nil) then if i == dclpos then x = x .. " dcl_2d s13" .. string.char(10) end end end end end if FixSceneColorTexture then if textcordreg ~= "" then --isDone = true rpos, rposEnd = string.find(SText[i], textcordreg) if rpos ~= nil then if IsFirst then if (DepthFilterSampleOffsets ~= nil) and (ScreenPositionScaleBias ~= nil) then x = x .. " mov r16, " .. textcordreg .. string.char(10) else x = x .. " mov r16.xyw, " .. textcordreg .. string.char(10) end x = x .. " texldl r11, c200.z, s13" .. string.char(10) x = x .. " add r11.y, r16.w, -r11.y" .. string.char(10) x = x .. " mul r11.x, r11.x, r11.y" .. string.char(10) x = x .. " add r16.x, r16.x, r11.x" .. string.char(10) --doSearch = false isDone = true end IsFirst = false; str = string.sub(SText[i], 1, rpos - 1) str = str .. "r16" .. string.sub(SText[i], rposEnd + 1) SText[i] = str end end if textcordpos == nil then textcordpos, rposEnd = string.find(SText[i], "dcl_texcoord4 v") if (DepthFilterSampleOffsets ~= nil) and (ScreenPositionScaleBias ~= nil) and (textcordpos == nil) then textcordpos, rposEnd = string.find(SText[i], "dcl_texcoord5 v") end if textcordpos ~= nil then textcordpos = string.find(SText[i], "." ,rposEnd - 1, true) if (DepthFilterSampleOffsets ~= nil) and (ScreenPositionScaleBias ~= nil) and (textcordpos == nil) then textcordpos = string.len(SText[i]) + 1 end if textcordpos ~= nil then textcordreg = string.sub(SText[i], rposEnd - 1, textcordpos - 1) else x = "" break end end end end --end if AddNextStr then x = x .. SText[i] .. string.char(10) end end end if isDone then x = x .. string.char(10) .. "//usepres" end end if isDone == false then -- probably static/world shadows, inject code by a template if ((pos ~= nil) or (ShadowTexture and SceneColorTexture) or (SceneColorTexture and (UniformPixelScalars or UniformPixelVector) and Texture2D_2 and ScreenPositionScaleBias)) and (pos1 ~= nil) then --isDone = true for i = LstIdx + 1, #SText do AddNextStr = true if doSearch then if VPPos == nil then VPPos = string.find(SText[i], "ViewProjectionMatrix") if(VPPos ~= nil) then xpos = string.find(SText[i], "c", VPPos + 19, true) if(xpos ~= nil) then --VPPos = string.find(SText[i], " ", xpos, true) VPreg = string.sub(SText[i], xpos, xpos + 1) --x = x .." //" ..VPreg .. string.char(10) end end end lastdefpos = string.find(SText[i], "def") if lastdefpos ~= nil then defpos = i + 1 end if (lastdefpos == nil) and (defpos ~= nil) then if i == defpos then x = x .. " def c200, 0.0, 0.5, 0.0625, 0" .. string.char(10) end lastdclpos = string.find(SText[i], "dcl_2") if lastdclpos == nil then lastdclpos = string.find(SText[i], "dcl_cube") end if lastdclpos ~= nil then dclpos = i + 1 end if (lastdclpos == nil) and (dclpos ~= nil) and (VPreg ~= "") then if i == dclpos then x = x .. " dcl_2d s13" .. string.char(10) end c7pos = string.find(SText[i], VPreg .. ".", 1, true) if c7pos == nil then c7pos = string.find(SText[i], VPreg .. ",", 1, true) end if c7pos ~= nil then --x = x .." //" ..VPreg .. string.char(10) c7pos = i + 2; rpos = string.find(SText[i], "mad ") if rpos ~= nil then rpos = rpos + 4 xpos = string.find(SText[i], ".", rpos, true) sr = string.sub(SText[i], rpos, xpos - 1) sx = string.sub(SText[i], xpos + 1, xpos + 1) sw = string.sub(SText[i], xpos + 3, xpos + 3) x = x .. SText[i] .. string.char(10) x = x .. SText[i + 1] .. string.char(10) x = x .. SText[i + 2] .. string.char(10) SText[i + 1] = "" SText[i + 2] = "" x = x .. " texldl r11, c200.z, s13" .. string.char(10) x = x .. " add r11.y, " .. sr .. "." .. sw .. ", -r11.y" .. string.char(10) x = x .. " mul r11.x, r11.x, r11.y" .. string.char(10) x = x .. " add " .. sr .. "." .. sx .. ", " .. sr .. "." .. sx .. ", r11.x" .. string.char(10) doSearch = false isDone = true AddNextStr = false end end end end end if AddNextStr then x = x .. SText[i] .. string.char(10) end end end if isDone then x = x .. string.char(10) .. "//usepres" end end if isDone then return x else return "" end;