August 15, 2020, 03:01:03 AM

Author Topic: Is it possible to apply a shader without unloading textures?  (Read 625 times)

Offline Kippykip

  • Full Member
  • ***
  • Posts: 122
    • Kippykip Forums!
Is it possible to apply a shader without unloading textures?
« on: October 01, 2019, 01:28:04 PM »
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. :)
Code: [Select]
Local PSXShader:TShader = LoadShader("", "ps1.vert.glsl", default.frag.glsl)Then use either
Code: [Select]
ShadeMesh(Container.Model, PSXShader)
ShadeEntity(Container.Model, PSXShader)

Code: [Select]
varying vec4 vertColor;
void main() // all vertex shaders define a main() function
vec4 snapToPixel = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 vertex = snapToPixel; =;
vertex.x = floor(160*vertex.x)/160;
vertex.y = floor(120*vertex.y)/120;*=snapToPixel.w;
gl_Position = vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vertColor = gl_Color;

Code: [Select]

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:


SimplePortal 2.3.6 © 2008-2014, SimplePortal