Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
1.0.0:postfx [2023/02/23 14:21] – [DesignTime] admin1.0.0:postfx [2023/02/23 14:41] (current) – [Shaders] admin
Line 1: Line 1:
 ====== PostFX ====== ====== PostFX ======
  
-Even though Gorilla3D is compatible Firemonkey post effects, it is difficult for many users to build their own post effect.+Even though Gorilla3D is compatible with Firemonkey post effects, it is difficult for many users to build their own post effect.
  
 To solve this issue we provide the TGorillaRenderPassPostFX component. To solve this issue we provide the TGorillaRenderPassPostFX component.
  
-It is now possible for you to easily create your own effect and to design it in the IDE at design time.+It is now possible for you to easily create your own effect and to write a shader in the IDE at design time.
  
 {{:1.0.0:g3d-postfx.jpg?nolink|}} {{:1.0.0:g3d-postfx.jpg?nolink|}}
Line 17: Line 17:
   - Write GLSL shader code using "vec3 SurfaceShader(inout TLocals DATA){...}" as entry function   - Write GLSL shader code using "vec3 SurfaceShader(inout TLocals DATA){...}" as entry function
  
-Here is some nice television post effect for the surface shader:+Here is some nice television post-effect for the surface shader.  
 + 
 +Just copy & paste into **GorillaRenderPassPostFX1.SurfaceShader** property editor:
  
 <file glsl> <file glsl>
Line 92: Line 94:
 </file> </file>
  
-__WARNING:__ GLSL compiler does not allow comments in shader code. +Source[[https://www.shadertoy.com/view/XtK3W3]]
 ===== Runtime ===== ===== Runtime =====
  
Line 105: Line 106:
 LPostFX.SurfaceShader.Text :=  LPostFX.SurfaceShader.Text := 
   'vec3 SurfaceShader(inout TLocals DATA){'#13#10 +   'vec3 SurfaceShader(inout TLocals DATA){'#13#10 +
-  '  return vec3(tex2D(_RenderedTexture, DATA.TexCoord0.xy).r, 0.0, 0.0));'#13#10;+  '  return vec3(tex2D(_RenderedTexture, DATA.TexCoord0.xy).r, 0.0, 0.0));'#13#10 + 
 +  '}'#13#10;
 </file> </file>
  
 +
 +===== Shaders =====
 +
 +You can write shaders in GLSL syntax compatible with OpenGL 4.3 (on Windows) and OpenGLES 3.1+ (on Android).
 +
 +__WARNING:__ GLSL compiler does not allow comments in shader code. The framework currently does not filter comments.
 +
 +The **SurfaceShader** property of the PostFX instance allows to put a string with compatible shader code into.
 +
 +At least every shader needs a "SurfaceShader" function with the following header. Besides that you can add further functions to the shader.
 +
 +<file glsl>
 +vec3 SurfaceShader(inout TLocals DATA){
 +...
 +}
 +</file>
 +
 +The shader itself provides some variables for usage:
 +
 +^Shader Variable ^Type ^ Description ^
 +|_RenderedTexture|sampler2D|The main render pass result texture.|
 +|_MaskTexture|sampler2D|Optional texture for post effects. You can use this texture for additional shader computation.|
 +|_TimeInfo.x|float|Starting timestamp of the post effect shader|
 +|_TimeInfo.y|float|Current timestamp of the post effect shader|
 +|_TimeInfo.z|float|Previous timestamp of the post effect shader|
 +|_TimeInfo.w|float|Delta timestamp of the post effect shader|
 +|DATA.TexCoord0|vec2|Texture coordinate of the post effect plane.|
 +|DATA.WorldViewProjVertPos|vec4|World-View-Projected vertex position of the post effect plane.|
 +|DATA.Normal|vec3|Normal vector of the post effect plane.|
 +
 +==== Links ====
 +
 +You can find many free shaders in the web with less need of change.
 +  * https://www.shadertoy.com/
 +  * https://glslsandbox.com/
 +  * https://shaderpark.com/
 +  * ...