Is it possible to apply a shader without unloading textures?

Started by Kippykip, October 01, 2019, 13:28:04

Previous topic - Next topic

Kippykip

Hey everyone! I was wondering if it was possible to apply a shader to a mesh/model without unloading the textures. I haven't really played with shaders much in OpenB3D other than a greyscale filter on a RenderToTexture mesh that's in front of the camera.

For example I ported a PS1 shaky vertex GLSL shader from a Unity demo project, and used ShadeMesh whenever I used LoadAnimMesh it'll either appear just plain white, or glitch into random colours as it seems to collide a bit with Max2D functions. Similar things happen if I use the PixelLight shaders included with the examples.
If someone knows how to use shaders on meshes properly in OpenB3D it would be awesome if you could explain the process. :)
Local PSXShader:TShader = LoadShader("", "ps1.vert.glsl", default.frag.glsl)
Then use either
ShadeMesh(Container.Model, PSXShader)
ShadeEntity(Container.Model, PSXShader)


ps1.vert.glsl
varying vec4 vertColor;
void main() // all vertex shaders define a main() function
{
vec4 snapToPixel = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 vertex = snapToPixel;
vertex.xyz = snapToPixel.xyz/snapToPixel.w;
vertex.x = floor(160*vertex.x)/160;
vertex.y = floor(120*vertex.y)/120;
vertex.xyz*=snapToPixel.w;
gl_Position = vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vertColor = gl_Color;
}


default.frag.glsl
// https://github.com/chudooder/entanglement/blob/master/shaders

varying vec4 vertColor;
uniform sampler2D texture0;

void main() {
    gl_FragColor = texture2D(texture0, gl_TexCoord[0].st)*vertColor;
}


Here's a video showing what's happening:
[yt_search]https://www.youtube.com/watch?v=Yp1IL1TDnQ0[/yt_search]