Shader Info

Previous topic - Next topic

Kyo

Hi,

I test this example of shader (C64colorshader):

Code (glbasic) Select

// --------------------------------- //
// Project: C64izer
// Start: Tuesday, March 25, 2008
// IDE Version: 5.212


LOADBMP "test.png"
X_LOADSHADER(0, "", "C64izer.frag")


DRAWRECT 0,0,64,64,RGB(0,255,0)
DRAWRECT 0,0,32,32,RGB(0,0,255)
DRAWRECT 32,32,32,32,RGB(255,255,255)
PRINT "C64", 8,8
GRABSPRITE 0,0,0,64,64

// C64izeOld()

WHILE TRUE
ROTOZOOMSPRITE 0, 140,100, GETTIMERALL()/20, SIN(GETTIMERALL()/37)+1

C64ize()
SHOWSCREEN
WEND


FUNCTION C64ize:
// Grab the 320x240 image from screen
GRABSPRITE 1000, 0,0, 320,240

// Make smooth downscaling for better quality
SMOOTHSHADING TRUE

// Set the C64 color shader
X_SETSHADER 0

// draw the sprite 160x240 with C64 colors
STRETCHSPRITE 1000, 0,0,160,240
// unlink the shader - we're done
X_SETSHADER -1

// grab the image 160x240
GRABSPRITE 1000, 0,0,160,240

// make hard pixels for final output
SMOOTHSHADING FALSE
// stretch by factors 4x2 -> C64 has 2 neighbored pixels of same color
STRETCHSPRITE 1000,0,0,640,480
ENDFUNCTION


But if i delete all shader command the result it's the same, it's the STRETCHSPRITE command which has the effect C64 style!

I test with other .frag but the result don't change.

I would like to get the 2D effects (on sprites) as:
- Black / White (greyscale)
- Distortion
etc.

It's possible? and how?

kanonet

If you dont post your shader code, we cant tell you whats wrong with them. BTW you can not just copy a shader from somewhere else and expect it to work, you need to code it correctly, which means you need to learn the OpenGL shader language GLSL.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Kyo

Quote from: kanonet on 2014-Oct-29
If you dont post your shader code, we cant tell you whats wrong with them. BTW you can not just copy a shader from somewhere else and expect it to work, you need to code it correctly, which means you need to learn the OpenGL shader language GLSL.

I use the sample test on the site: http://www.glbasic.com/showroom.php?site=games&game=C64colorshader

But if I lock the commands:

Code (glbasic) Select

// --------------------------------- //
// Project: C64izer
// Start: Tuesday, March 25, 2008
// IDE Version: 5.212


LOADBMP "test.png"
//X_LOADSHADER(0, "", "C64izer.frag")


DRAWRECT 0,0,64,64,RGB(0,255,0)
DRAWRECT 0,0,32,32,RGB(0,0,255)
DRAWRECT 32,32,32,32,RGB(255,255,255)
PRINT "C64", 8,8
GRABSPRITE 0,0,0,64,64

// C64izeOld()

WHILE TRUE
ROTOZOOMSPRITE 0, 140,100, GETTIMERALL()/20, SIN(GETTIMERALL()/37)+1

C64ize()
SHOWSCREEN
WEND


FUNCTION C64ize:
// Grab the 320x240 image from screen
GRABSPRITE 1000, 0,0, 320,240

// Make smooth downscaling for better quality
SMOOTHSHADING TRUE

// Set the C64 color shader
// X_SETSHADER 0

// draw the sprite 160x240 with C64 colors
STRETCHSPRITE 1000, 0,0,160,240
// unlink the shader - we're done
// X_SETSHADER -1

// grab the image 160x240
GRABSPRITE 1000, 0,0,160,240

// make hard pixels for final output
SMOOTHSHADING FALSE
// stretch by factors 4x2 -> C64 has 2 neighbored pixels of same color
STRETCHSPRITE 1000,0,0,640,480
ENDFUNCTION




so I dont understand what makes the shader!

I also tried to use this shader for Black / White (greyscale):
Code (glbasic) Select

precision lowp float;
varying vec2 v_texCoord;
uniform sampler2D u_texture;

void main()

{

    vec4 normalColor = texture2D(u_texture, v_texCoord);
    float gray = 0.299*normalColor.r + 0.587*normalColor.g + 0.114*normalColor.b;
    gl_FragColor = vec4(gray, gray, gray, normalColor.a);

}


but the result does not change!

Hemlos

This is just ANY bump.

I would like to see a screenshot of the problem please.
Ive been working with shaders again recently, and would like to help you.

In my experience with this sample from the download section, it is no longer working as expected.
It used to show a cool background, and now it doesnt, it only shows a rotating square with c64 written on it.

Furthmore, shaders work.
Moreover, they dont get controlled by shader standards.
You must prepare each input as a one dimensional input.
In other words you cant send a vector, but you can code your glbasic code to split it up and send each dimension one at a time.
Also you can send time into the shaders, with GETTIMERALL()*0.001

I have a thread somewhere on this forum with more about shaders, ive been looking for it and thats how i found this thread lol.

Bing ChatGpt is pretty smart :O