Are soft shadows possible with point light using cubemap ...
文章推薦指數: 80 %
Or is there an alternative? Thanks a lot in advance for your help! opengl glsl shader shadow shadow-mapping.
2022DeveloperSurveyisopen!Takesurvey.
Home
Public
Questions
Tags
Users
Companies
Collectives
ExploreCollectives
Teams
StackOverflowforTeams
–Startcollaboratingandsharingorganizationalknowledge.
CreateafreeTeam
WhyTeams?
Teams
CreatefreeTeam
Collectives™onStackOverflow
Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost.
Learnmore
Teams
Q&Aforwork
Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch.
Learnmore
Aresoftshadowspossiblewithpointlightusingcubemap(OpenGL/GLSL)?
AskQuestion
Asked
7years,7monthsago
Modified
7years,7monthsago
Viewed
2ktimes
3
Icodeda3Dapplicationmanagingspotlightshadowmapping.TodothisIuseclassicalshadowmappingtechnique(IfilladepthtextureinthefirstrenderpassandinthesecondrenderpassIcomparethedistancefromlighttothefirstoccluderandthedistancefromthelighttothevertexpositiontoknowifmyfragmentisinshadowornot).
Here'sascreenshot(spotlight/2Ddepthtextureshadowmapping):
InthisexampleIusePCFshadowmappingtechniqueusingthefunction'textureProjOffset'.Here'sapieceofcodefrommyfragmentshader:
Samplerused:
sampler2DShadowShadow2DSampler[MAX_LIGHTS_COUNT];
ForHARDshadows:
shadowFactor=textureProj(Shadow2DSampler[idx],ShadowCoords[idx]);
ForPCFSOFTshadows:
for(intidy=offset;idy>=-offset;idy--)
for(intidx=-offset;idx<=offset;idx++)
shadowFactor+=textureProjOffset(
Shadow2DSampler[idz],ShadowCoords[idz],ivec2(idx,idy));
Ihavealsomanagedthebasiccubemapshadowmappingtomanageomnidirectionalshadowmappingcurrentlyappliedforpointlights.TodothisinthefirstrenderpassIuseageometryshadertodispatchboththeprojectionandviewmatrixprovidedbythe6shadowfrustrums(allinONEpass!It'sdifferentofthetechniqueconcistingtofill6separatetextureswiththistime6renderstates).
Here'sascreenshot(spotlight/Cubedepthtextureshadowmapping):
Asyoucansee,it'sonlyHARDshadowmapping.TorecoverthedepthvalueencodedintothecubemapIhavetousethistimethefunction'texture'(textureProjdoesnotexistsfor'samplerCube'and'samplerCubeShadow').NextIhavetocomputethedistancebetweenthelightpositionandthevertexpositioninworldspaceandthenconvertitintoclipspacebecausethedepthvaluecontainedintothetextureisalreadyinclipspace.
Here'sapieceofcodefromthefragmentshadertoseetheprocess:
Samplerused:
samplerCubeShadowShadowCubeSampler[MAX_LIGHTS_COUNT];
ForHARDshadows:
floatConvertDistToClipSpace(vec3lightDir_ws)
{
vec3AbsVec=abs(lightDir_ws);
floatLocalZcomp=max(AbsVec.x,max(AbsVec.y,AbsVec.z));
floatNormZComp=(NearFar.y+NearFar.x)/(NearFar.y-NearFar.x)
-(2.0f*NearFar.y*NearFar.x)/(LocalZcomp*NearFar.y-NearFar.x);
return((NormZComp+1)*0.5f);
}
floatGetBiased_Cube_Hard_ShadowFactor(vec3vertexPosition_ws,intidx)
{
vec3lightToVertexDir_ws=vertexPosition_ws-LightPos_ws.xyz;
floatLightToVertexClipDist=ConvertDistToClipSpace(lightToVertexDir_ws);
floatLightToOccluderClipDist=texture(
ShadowCubeSampler[idx],vec4(lightToVertexDir_ws,LightToVertexClipDist));
if(LightToOccluderClipDist
延伸文章資訊
- 1Shadow Mapping - LearnOpenGL
comparrison of shadows in a scene with and without in OpenGL. You can see that with shadows it be...
- 2Tutorial 42: Soft Shadows - RasterTek
To create soft shadows we first need to modify the shadow shader. Instead of using the shader to ...
- 3What are some modern shadowing techniques for soft ... - Reddit
I've been working with some OpenGL recently (version 3.3) and I am curious as to what techniques ...
- 4Chapter 17. Efficient Soft-Edged Shadows Using Pixel Shader ...
Soft shadows present an even greater challenge to developers, ... a depth texture and a "compare"...
- 5Rendering soft shadows with OpenGL based on planar ...
In order to approximate soft-shadow effect, a number of points on the light source are sampled. F...