Skip to content

Custom shaders during a shadow pass.#7613

Merged
ofTheo merged 1 commit intoopenframeworks:masterfrom
NickHardeman:shadows-custom-shader
Aug 25, 2023
Merged

Custom shaders during a shadow pass.#7613
ofTheo merged 1 commit intoopenframeworks:masterfrom
NickHardeman:shadows-custom-shader

Conversation

@NickHardeman
Copy link
Copy Markdown
Contributor

This allows using custom shaders during a shadow pass. The materials do not support custom shadow passes yet. Maybe that can be addressed in the next minor release. I tested using the shadow and material examples but could probably use a bit more.

Shadow shader functions have been added, so you can setup a shader using a function within the shadow class
shadow.setupShadowDepthShader(ofShader& ashader, const std::string aShaderMain);

The shader function for sending to the frag shader accepts a world position

vec3 worldPosition = (modelMatrix * vec4(position.xyz, 1.0)).xyz;
sendShadowDepthWorldPosition(worldPosition);

An example vert shader based on the MaterialPBRAdvanced Example

#if defined(SHADOW_DEPTH_PASS)
uniform mat4 modelMatrix;
in vec4 position;
uniform float iElapsedTime;
#else
OUT vec3 v_localPos;
#endif

void main (void){
	vec4 npos = position;
	npos.xyz += 3.0 * vec3( cos(iElapsedTime+position.y*1.25), 0.0, 0.0);
#if defined(SHADOW_DEPTH_PASS)
	vec3 worldPosition = (modelMatrix * vec4(npos.xyz, 1.0)).xyz;
	sendShadowDepthWorldPosition(worldPosition);
#else
	v_localPos = position.xyz;
	sendVaryings(npos);
	gl_Position = modelViewProjectionMatrix * npos;
#endif
	
}

Example usage:

if( light.shouldRenderShadowDepthPass() ) {
	int numShadowPasses = light.getNumShadowDepthPasses();
	light.beginShadowDepthPass();
	mDepthShader.begin();
	mDepthShader.setUniform1f("iElapsedTime", ofGetElapsedTimef());
	renderScene(true);
	mDepthShader.end();
	light.endShadowDepthPass();
}

@NickHardeman
Copy link
Copy Markdown
Contributor Author

Addresses issue #7555

@ofTheo
Copy link
Copy Markdown
Member

ofTheo commented Aug 25, 2023

the broken arm check is fixed now in apothecary will re-run in a sec to confirm

@ofTheo ofTheo merged commit 1837cd0 into openframeworks:master Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants