Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Samples: LightShafts - port from Cg to OgreUnifiedShader #1637

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Samples/Media/materials/programs/GLSL/LightShafts.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ---------------------------------------------------------------------------------------
// Light shafts shaders with shadows and noise support
// Inpirated on the ATI paper https://developer.amd.com/wordpress/media/2012/10/Mitchell_LightShafts.pdf
// Ogre3D implementation by Xavier Verguín González (xavyiy [at] gmail [dot] com) [Xavyiy]
// ---------------------------------------------------------------------------------------

#include <OgreUnifiedShader.h>

// UNIFORM
uniform vec4 uAttenuation;
uniform vec3 uLightPosition;
uniform SAMPLER2D(uDepthMap, 0);
uniform SAMPLER2D(uCookieMap, 1);
uniform SAMPLER2D(uNoiseMap, 2);
uniform float Time;

MAIN_PARAMETERS
IN(vec3 vPosition, TEXCOORD0)
IN(vec4 oUV , TEXCOORD1)
MAIN_DECLARATION
{
vec4 iUV = oUV / oUV.w;

float Depth = texture2D(uDepthMap, iUV.xy).r;

#if !defined(OGRE_HLSL) && !defined(OGRE_REVERSED_Z)
iUV.z = iUV.z * 0.5 + 0.5;
#endif

if (Depth < iUV.z)
{
gl_FragColor = vec4(0,0,0,1);
}
else
{
vec4 Cookie = texture2D(uCookieMap, iUV.xy);
vec2 Noise = vec2(texture2D(uNoiseMap, iUV.xy - Time).r,
texture2D(uNoiseMap, iUV.xy + Time).g);

float noise = Noise.x * Noise.y;
float length_ = length(uLightPosition - vPosition);
float atten = 1.0 / (uAttenuation.y + uAttenuation.z*length_ + 20.0*uAttenuation.w*length_*length_);

gl_FragColor = vec4(Cookie.rgb * atten * noise , 1);
}
}
23 changes: 23 additions & 0 deletions Samples/Media/materials/programs/GLSL/LightShafts.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ---------------------------------------------------------------------------------------
// Light shafts shaders with shadows and noise support
// Inpirated on the ATI paper https://developer.amd.com/wordpress/media/2012/10/Mitchell_LightShafts.pdf
// Ogre3D implementation by Xavier Verguín González (xavyiy [at] gmail [dot] com) [Xavyiy]
// ---------------------------------------------------------------------------------------

#include <OgreUnifiedShader.h>

// UNIFORM
uniform mat4 uWorldView;
uniform mat4 uWorldViewProj;
uniform mat4 uTexWorldViewProj;

MAIN_PARAMETERS
IN(vec4 vertex , POSITION)
OUT(vec3 vPosition, TEXCOORD0)
OUT(vec4 oUV , TEXCOORD1)
MAIN_DECLARATION
{
gl_Position = mul(uWorldViewProj, vertex);
vPosition = mul(uWorldView, vertex).xyz;
oUV = mul(uTexWorldViewProj, vertex);
}
63 changes: 0 additions & 63 deletions Samples/Media/materials/programs/HLSL_Cg/LightShafts.hlsl

This file was deleted.

63 changes: 33 additions & 30 deletions Samples/Media/materials/scripts/LigthShafts.material
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,38 @@

// --------------------- Light shafts material ------------------------

vertex_program LightShafts_VP cg
vertex_program LightShafts_VP_GLSL glsl
{
source LightShafts.hlsl
entry_point main_vp
profiles vs_2_0 arbvp1
source LightShafts.vert
}

vertex_program LightShafts_VP_HLSL hlsl
{
source LightShafts.vert
target vs_2_0
}

fragment_program LightShafts_FP_GLSL glsl
{
source LightShafts.frag
default_params
{
param_named uDepthMap int 0
param_named uCookieMap int 1
param_named uNoiseMap int 2
}
}

fragment_program LightShafts_FP_HLSL hlsl
{
source LightShafts.frag
target ps_2_0
}

vertex_program LightShafts_VP unified
{
delegate LightShafts_VP_GLSL
delegate LightShafts_VP_HLSL
default_params
{
param_named_auto uWorldView worldview_matrix
Expand All @@ -20,11 +46,10 @@ vertex_program LightShafts_VP cg
}
}

fragment_program LightShafts_FP cg
fragment_program LightShafts_FP unified
{
source LightShafts.hlsl
entry_point main_fp
profiles ps_2_0 arbfp1
delegate LightShafts_FP_GLSL
delegate LightShafts_FP_HLSL
}

material LightShafts
Expand Down Expand Up @@ -73,26 +98,4 @@ material LightShafts
}
}
}
}

// --------------------- Depth material ------------------------

vertex_program LightShaftsDepth_VP cg
{
source LightShafts.hlsl
entry_point main_vp_depth
profiles vs_2_0 arbvp1

default_params
{
param_named_auto uWorldView worldview_matrix
param_named_auto uWorldViewProj worldviewproj_matrix
}
}

fragment_program LightShaftsDepth_FP cg
{
source LightShafts.hlsl
entry_point main_fp_depth
profiles ps_2_0 arbfp1
}
2 changes: 0 additions & 2 deletions Samples/Simple/include/LightShafts.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class _OgreSampleClassExport Sample_LightShafts : public SdkSample
"N - Change light cookie";
}

StringVector getRequiredPlugins() { return {"Cg Program Manager"}; }

bool frameStarted(const FrameEvent& e)
{
// Update light position
Expand Down