Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Parallax shader


Recommended Posts

Here's a lua script to attach to stuff for the shader:

Script.diffuse = "" --path "Diffuse Map" "Texture File (*tex):tex|Texture"
Script.normal = "" --path "Normal Map" "Texture File (*tex):tex|Texture"
Script.specular = "" --path "Specular Map" "Texture File (*tex):tex|Texture"
Script.height = "" --path "Height Map" "Texture File (*tex):tex|Texture"

Script.diffuseColor = Vec4(0.4,0.4,0.5,1.0) -- color "Diffuse Hue"
Script.brightness = 2.0 -- float "Brightness"
Script.specIntensity = 3.0 -- float "Specular Intensity"
Script.parallaxSteps = 10 -- float "Parallax Steps"
Script.parallaxDepth = 0.03 -- float "Parallax Depth"
Script.parallaxRounding = 0.2 -- float "Parallax Rounding"
Script.texSize = 1.5 -- float "Texture Size"

function Script:Start()
    self.shader = Shader:Load("Parallax/parallax_economy.shader")
    --self.shader = Shader:Load("Parallax/parallax.shader")

    --surface = self.entity:GetSurface(0) -- for models
    surface = self.entity:GetFace(0) --for brushes
    mat = surface:GetMaterial()
    self.entity:SetMaterial(mat)
    mat:SetTexture(self.diffuse,0)
    mat:SetTexture(self.normal,1)
    mat:SetTexture(self.specular,2)
    mat:SetTexture(self.height,3)

    mat:SetShader(self.shader)
    self.shader:SetVec4("diffuse_hue", self.diffuseColor)
    self.shader:SetFloat("diffuse_brightness", self.brightness)
    self.shader:SetFloat("specular_intensity", self.specIntensity)
    self.shader:SetInt("parallax_steps", self.parallaxSteps)
    self.shader:SetFloat("parallax_depth", self.parallaxDepth)
    self.shader:SetFloat("parallax_rounding", self.parallaxRounding)
    self.shader:SetFloat("texture_size", self.texSize)
end

function Script:Release()
    self.shader:Release()
    mat:Release()
end

parallax lua.jpg

  • Like 1
Link to post
Share on other sites
6 hours ago, reepblue said:

Only downside attaching a script to a brush is that now the brush will not collapse with the scene. 

What do you mean? Collapse with the scene?

I hadn't tried this script on more than one entity at a time and it looks like you can't do more than one. Not sure why. Adjusting the settings on one entity adjusts the settings on others. I thought  each instance of the script in play would affect only the entity it was attached to.

It works better I guess just to leave the lua out of it.

  • Like 1
Link to post
Share on other sites

I don't know if it's the same, but once I had a problem with changing the color of a surface in several models loaded from the editor. If you change the color on one, they would all be changed. I remember that the solution was to load the model by script again, and that way it didn't get distant every time I dragged it to the editor. 

Link to post
Share on other sites
1 hour ago, 💎Yue💎 said:

I don't know if it's the same, but once I had a problem with changing the color of a surface in several models loaded from the editor. If you change the color on one, they would all be changed. I remember that the solution was to load the model by script again, and that way it didn't get distant every time I dragged it to the editor. 


Yeah that's the problem. But I seem to have gotten around it by loading the shader outside the Start() function.
 

I thought a script would be good, otherwise for every entity you use it on in a single scene you'd need to make a whole new shader if you wanted to adjust any of the settings.
 

Script.diffuse = "" --path "Diffuse Map" "Texture File (*tex):tex|Texture"
Script.normal = "" --path "Normal Map" "Texture File (*tex):tex|Texture"
Script.specular = "" --path "Specular Map" "Texture File (*tex):tex|Texture"
Script.height = "" --path "Height Map" "Texture File (*tex):tex|Texture"

Script.diffuseColor = Vec4(0.4,0.4,0.5,1.0) -- color "Diffuse Hue"
Script.brightness = 1.0 -- float "Brightness"
Script.specIntensity = 1.0 -- float "Specular Intensity"
Script.parallaxSteps = 10 -- float "Parallax Steps"
Script.parallaxDepth = 0.03 -- float "Parallax Depth"
Script.parallaxRounding = 0.2 -- float "Parallax Rounding"
Script.texSize = 1.0 -- float "Texture Size"
Script.shader = Shader:Load("Parallax/parallax_economy.shader")               -- here instead of in the Start()
--Script.shader = Shader:Load("Parallax/parallax.shader")                             -- here instead of in the Start()

function Script:Start()

    mat = Material:Create()
    mat:SetTexture(self.diffuse,0)
    mat:SetTexture(self.normal,1)
    mat:SetTexture(self.specular,2)
    mat:SetTexture(self.height,3)
    mat:SetShader(self.shader)

    self.shader:SetVec4("diffuse_hue", self.diffuseColor)
    self.shader:SetFloat("diffuse_brightness", self.brightness)
    self.shader:SetFloat("specular_intensity", self.specIntensity)
    self.shader:SetInt("parallax_steps", self.parallaxSteps)
    self.shader:SetFloat("parallax_depth", self.parallaxDepth)
    self.shader:SetFloat("parallax_rounding", self.parallaxRounding)
    self.shader:SetFloat("texture_size", self.texSize)
    self.entity:SetMaterial(mat)
end

function Script:Release()
    self.shader:Release()
    mat:Release()
end

  • Like 1
Link to post
Share on other sites
4 hours ago, havenphillip said:

What do you mean? Collapse with the scene?

Brushes get collapsed into the scene tree to improve performance. Once a brush has a script attached to it, it's left as a model. Josh can go into detail about what actually happens, but it's not wise to attach a script to a brush to change it's apperence. 

I would look into how I could read the material file and adjust the material accordingly. It would probably have to be in the MapHook function

I have been meaning to try your shader for the longest time but now I want to see if I can read custom values from a mat file. 

Link to post
Share on other sites
5 hours ago, 💎Yue💎 said:

 


So what does that mean? It's slower that way? I see some places in the community you're talking about the map hook but I haven't even touched C++ yet. I can't really make sense of it. I don't know what it would look like in Lua. If you know a better way in general to help me improve this then by all means explain it, fix it, optimize it, whatever. I still consider myself a noob and I really don't know a lot of things still.

 

  • Confused 1
Link to post
Share on other sites
7 hours ago, reepblue said:

I don't think there is anything you can do as a shader artist. The implementation of how to alter the shader to get different results is a job for the actual game programmer. 

Alright. If there's no blatant problems with it I'm good with it.

Link to post
Share on other sites

Sorry dude I wouldn't even know where to begin. You just try. Sometimes it happens for you. Sometimes it doesn't.

I was going to ask you, I'm trying to find a way to get collisions with materials. I saw a post you made about collision with materials for footsteps. Do you remember that? You had this code something like:

    local mat = Material:Load("Terrain Patch/terrain_patch.mat")
    local pivot = self.piv
    pickinfo = PickInfo()
    local p0 = self.entity:GetPosition(true)
    local p1 = Transform:Point(0,-0.2,0,self.entity,nil) ---3.84
    if self.entity.world:Pick(p0,p1, pickinfo, 0, true, Collision.LineOfSight ) then
        if pickinfo.surface~=nil then
        local pickedmaterial = pickinfo.surface:GetMaterial()
            if pickedmaterial~=nil then
                local height = pickedmaterial:GetTexture(0):GetHeight()
                if height>self.entity:GetPosition(true).y then
                    self.entity:Move(0,height*0.007,0)
                    System:Print("It works")
                end
            end
        end
    end

This is my problem, here:

 

Link to post
Share on other sites

It's ok if it doesn't work for VR. It may only be an AMD issue as the animated shaders don't render correctly ether in VR. I would not worry about it.

As for the footsteps, I got the filepath of the material and used it's subfolder to determine what material type it is. I know the new engine has a Material praram that makes life easier.

I should look into how to load custom material properties as I mentioned earlier.

Link to post
Share on other sites
  • 4 months later...

Was able to get self-shadowing on the parallax and cut the edges to give it a more 3D look. The shadows slowed it down, and the edge-cutting system isn't really developed at all. There may be better ways to do it. Right now it's mostly just something to look at and poke at. If you open the shader there's a bunch of variables at the top like the light direction(in the vertex shader), the shadow alpha, depth, etc. Still want to find a cheap way to soften the shadows and maybe find a way to round/smooth those sharp mesh edges, as well as get it faster, etc. Also I tried to break down the shader into sections to make it easier to mess with and to see which segment does what.

I didn't feel like I quite got the depth before as when I saw some videos of other parallax shaders they looked way better. I'm getting there, though. The picture is the previous parallax/current parallax:

 

 

pom before after.jpg

Parallax Rocks.zip

  • Like 6
Link to post
Share on other sites
1 hour ago, JoshMK said:

How did you make the edges extend beyond the geometry in the image on the right?

The trouble is getting the edges of the quad. But once you have that you can just shrink in a tiny bit and cut them off. My "alpha" is a black box that spans out from the center of the texcoords. Cut them too much and you start to see the gaps. The parallax effect is due to a depth coordinate, so it's actually sunk into the surface of the quad. So all I'm doing is cutting the repetitions of the texture beyond the quad. :

    quad_edge_sizing = -quad_edge_sizing;
    vec2 texcoord = abs(parallaxed_texcoords0.xy-0.85)*2.0/texture_size;
    float leftRight = clamp((quad_edge_sizing.x + texcoord.x - 1.0), 0.0, 1.0);
    float upDown = clamp((quad_edge_sizing.y + texcoord.y - 1.0), 0.0, 1.0);
    float alpha = clamp(leftRight + upDown, 0.0, 1.0);
    if (alpha > 0.0) discard;
 

  • Like 1
Link to post
Share on other sites
55 minutes ago, TWahl said:

I will have to let you try this with some of the materials that I am making, when I am finished with them that is.

Dude I sit and drool over the stuff you're making over there. I'll gladly try it with some of your stuff.

  • Like 2
Link to post
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.

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.

Facebook Twitter Youtube Github Steam
×
×
  • Create New...